Overview
Fikra API is an OpenAI-compatible AI inference API for developers and growing AI teams. Its chat completions endpoint accepts OpenAI-style requests and responses with streaming support, so you can stream token chunks into a web app as server-sent events (SSE).
Prerequisites
- A Fikra API key set as the
FIKRA_API_KEYenvironment variable - The OpenAI Python SDK
- A web app that can read an SSE stream (for example,
EventSourcein the browser)
Step-by-step
- Create an OpenAI-style client pointed at the Fikra API base URL.
- Call the chat completions endpoint with
stream=Trueand a model from your account. - Forward each chunk to the browser over SSE.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["FIKRA_API_KEY"],
base_url="https://api.fikraapi.co.ke/v1",
)
stream = client.chat.completions.create(
model="deepseek-v4-flash-0731",
messages=[{"role": "user", "content": "Write a short Python snippet."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
if delta.content:
# Send each piece to the web app as an SSE event
print(delta.content, end="", flush=True)
In production, the loop above sits in a server route that writes each delta.content value as an SSE data: event. The browser subscribes to that route and appends events to the chat UI as they arrive.
Verify it works
Run the script and confirm tokens appear progressively rather than all at once. Then connect your web app to the SSE route and confirm the UI updates incrementally with each chunk.
Costs
Pricing is per 1M tokens, billed in USD from your token-credit wallet:
deepseek-v4-flash-0731: $0.09 input, $0.15 outputdeepseek-v4.1-flash: $0.25 input, $0.80 outputdeepseek-v4.1-flash-1017: $0.30 input, $0.85 outputfikra-auto: $0.40 input, $0.40 outputfikra-auto-pro: $6.00 input, $12.00 outputfikra-code-35b: $1.00 input, $1.00 output
Common errors
- 401: Bad or inactive API key. Check the key and confirm it is scoped and active.
- 400: Unsupported model. Use a model name from your available models list.
- 429: Rate limit reached. Limits are 30 requests/min for unverified keys and 100 requests/min for trusted keys; retry after a short delay.
- 503: Upstream is busy. Retry the request with backoff.