Build a Chatbot with Fikra API in 10 Minutes (OpenAI-Compatible, M-Pesa Payments)
If you're an African developer trying to build AI apps, you've probably hit this wall: Stripe doesn't work in Kenya. You can't use global AI APIs like OpenAI or Anthropic because they require credit cards and payment rails that don't exist here.
I built Fikra API to fix this. It's a fully OpenAI-compatible AI inference gateway that works with M-Pesa, has a $1 minimum (2M tokens), and requires no credit card. You get 87% cheaper pricing than OpenAI.
In this tutorial, you'll build a working chatbot in Python using Fikra API. No code rewrites needed.
What You'll Build
A conversational chatbot that remembers previous messages in the conversation. By the end, you'll have:
- A working Python chatbot
- Understanding of OpenAI-compatible API calls
- Your Fikra API key (with 2M free tokens)
Prerequisites
- Python 3.8+ installed
- Basic Python knowledge
- Fikra API key (get one at fikraapi.co.ke)
Step 1: Install the OpenAI SDK
Fikra API is 100% OpenAI-compatible, so you use the same SDK:
pip install openai
Step 2: Set Up Your API Key
Create a file called chatbot.py:
import openai
import os
# Set your API key
os.environ["FIKRA_API_KEY"] = "fk_live_YOUR_KEY_HERE"
# Initialize Fikra client (change base_url only)
client = openai.OpenAI(
base_url="https://api.fikraapi.co.ke/v1",
api_key=os.getenv("FIKRA_API_KEY")
)
Security Tip: Use environment variables instead:
export FIKRA_API_KEY="fk_live_YOUR_KEY_HERE"
Step 3: Make Your First Chat Completion
Add this to chatbot.py:
response = client.chat.completions.create(
model="fikra-fast-8b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! What can you do?"}
]
)
print(response.choices.message.content)
Run it:
python chatbot.py
Expected Output:
Hello! I'm a helpful AI assistant. I can help you with:
Answering questions
Writing code
Explaining concepts
And much more!
Step 4: Make It Interactive (Conversation Memory)
Now let's add conversation memory so the bot remembers previous messages:
conversation = [
{"role": "system", "content": "You are a helpful assistant."}
]
while True:
user_input = input("You: ")
if user_input.lower() == "quit":
break
conversation.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="fikra-fast-8b",
messages=conversation
)
assistant_reply = response.choices.message.content
conversation.append({"role": "assistant", "content": assistant_reply})
print(f"Assistant: {assistant_reply}")
Example Conversation:
You: What's the capital of Kenya?
Assistant: The capital of Kenya is Nairobi.
You: What's special about Nairobi?
Assistant: Nairobi is Kenya's largest city and serves as the country's economic hub. It's known for Nairobi National Park (the only wildlife park within a city capital), vibrant culture, and as a major business center in East Africa.
You: quit
Step 5: Add Streaming (Real-Time Responses)
For faster, more natural responses, use streaming:
response = client.chat.completions.create(
model="fikra-fast-8b",
messages=[
{"role": "user", "content": "Write a poem about Kenya."}
],
stream=True
)
for chunk in response:
if chunk.choices.delta.content:
print(chunk.choices.delta.content, end="", flush=True)
Output:
In the heart of East Africa lies Kenya,
Where sun-kissed plains and mountains sway...
Tokens appear as they're generated, not waiting for the full response.
Why Fikra API? (The Pain Point)
| Problem with Global APIs | Fikra Solution |
|---|---|
| Stripe doesn't support Kenya/East Africa | Native M-Pesa top-ups from your phone |
| $20+ monthly minimums | $1 minimum spend (2,000,000 tokens) |
| Credit card required | No credit card needed |
| High costs ($15/1M tokens) | 87% cheaper ($2/1M tokens) |
| Slow global routing | Local Kenya infrastructure |
The math: 2M tokens per dollar = 20,000 chatbot messages per $1.
Available Models
| Model String ID | Context Window | Best For |
|---|---|---|
fikra-fast-8b |
8,192 tokens | Real-time chat, basic routing |
fikra-pro-20b |
32,768 tokens | Production workflows, agentic tasks |
fikra-pro-120b |
128,000 tokens | Complex coding, deep analysis |
Troubleshooting
| Error | Fix |
|---|---|
401 Unauthorized |
Check API key starts with fk_live_
|
402 Payment Required |
Top up via M-Pesa at fikraapi.co.ke |
429 Too Many Requests |
Hit 30 RPM limit (unverified account). Wait 1 minute |
model not found |
Use exact strings: fikra-fast-8b, fikra-pro-20b
|
Next Steps
Now you can build:
- Customer Support Bot: Add business context to system role
- Code Assistant: Set system role to "You are a Python expert"
-
Content Generator: Use
temperature=0.9for creative writing - RAG System: Add document retrieval before sending to AI
Get Your Free API Key
Ready to build? Sign up at fikraapi.co.ke and get 2M free tokens when you create an account this week.
- Documentation: docs.fikraapi.co.ke
- Email: support@fikraapi.co.ke
- Phone: +254 702 794 345
Stop fighting payment rails. Start building AI. M-Pesa native, OpenAI-compatible, 87% cheaper.
Built in Nairobi, Kenya.
Read on medium: https://medium.com/@benjmiano/build-a-chatbot-with-fikra-api-in-10-minutes-openai-compatible-m-pesa-payments-dc2f80e0739c

Top comments (1)
What would you build if you had 2M free tokens?