Overview
Fikra API is an OpenAI-compatible AI inference API for developers and growing AI teams who need production inference. To wire an AI agent to send WhatsApp replies, you call Fikra API’s chat completions endpoint from your backend, receive the reply text, then pass it to your WhatsApp sending integration.
Because the API is OpenAI-compatible, any existing OpenAI SDK client can be pointed at Fikra API’s base URL without changing your request or response format.
Prerequisites
- A Fikra API key. Store it in the
FIKRA_API_KEYenvironment variable. - Python 3 with the
openaiSDK installed (pip install openai). - A WhatsApp sending service or bot integration that accepts a text message and sends it to a chat.
Step-by-step
- Configure the OpenAI SDK client with the Fikra base URL.
- Create a function that takes an incoming WhatsApp message, calls the Fikra chat completions endpoint, and returns the generated reply.
- Send the returned reply through your WhatsApp integration.
Example:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["FIKRA_API_KEY"],
base_url="https://api.fikraapi.co.ke/v1",
)
def generate_reply(incoming_text: str) -> str:
response = client.chat.completions.create(
model="deepseek-v4-flash-0731",
messages=[
{"role": "system", "content": "You are a WhatsApp assistant that replies concisely."},
{"role": "user", "content": incoming_text},
],
)
return response.choices[0].message.content.strip()
# Pass the reply to your WhatsApp integration, e.g.:
# whatsapp_send(incoming_chat_id, generate_reply(incoming_text))
Streaming is supported, so you can use any OpenAI-style streaming parameter if your WhatsApp agent needs token-by-token output.
Verify it works
Run a quick test locally:
print(generate_reply("Hello, are you open today?"))
You should see a generated reply printed. Then connect the function to your WhatsApp integration and send a real message to confirm the full flow works.
Costs
The example uses deepseek-v4-flash-0731: $0.09 per 1M input tokens and $0.15 per 1M output tokens. Fikra API runs on a token-credit wallet; top up with M-Pesa or card via Paystack, or use x402 USDC on Base for agent usage. For a full list of models and rates, check the pricing page.
Common errors
- 401 to Bad or inactive API key. Confirm the key exists, is active, and is set correctly in the
FIKRA_API_KEYenvironment variable. - 400 to Unsupported model. Use one of the models available on Fikra API.
- 429 to Rate limit exceeded. Unverified accounts get 30 requests/min; trusted accounts get 100 requests/min. Slow down or request a higher trust level.
- 503 to Upstream service busy. Retry the request with backoff.