Overview
Fikra API is an OpenAI-compatible inference API that lets you run chat models behind one endpoint and bill your own users for the AI features you ship. You send OpenAI-style chat-completions requests to https://api.fikraapi.co.ke/v1, metered in tokens, and pay Fikra in USD or KES from a token-credit wallet. Because pricing is per 1M tokens with a published per-model rate, you can turn each request's token usage into a per-user charge in your own product.
This page covers the server-side path only: your API key stays on your backend, never in client code.
Prerequisites
- A Fikra API key, created and scoped in your account. Keys are scoped, revocable, and never shared between users.
- The key exported as
FIKRA_API_KEYin your server environment. - Python with the OpenAI SDK installed (
pip install openai). - A base URL of
https://api.fikraapi.co.ke/v1.
Step-by-step
-
Store the key server-side. Set
FIKRA_API_KEYin your backend environment (or secret manager). Do not ship it to browsers or mobile clients; your SaaS backend calls Fikra on the user's behalf. -
Create the client. Point the OpenAI SDK at Fikra's base URL:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.fikraapi.co.ke/v1",
api_key=os.environ["FIKRA_API_KEY"],
)
-
Pick a model per feature tier. For high-volume, low-margin features, start with
deepseek-v4-flash-0731(the cheapest listed model). For heavier features, step up todeepseek-v4.1-flashorfikra-auto. This choice is the main lever on your per-user gross margin. -
Call chat completions.
response = client.chat.completions.create(
model="deepseek-v4-flash-0731",
messages=[
{"role": "system", "content": "You are a helpful assistant inside a SaaS product."},
{"role": "user", "content": "Summarise this customer's ticket."},
],
)
print(response.choices[0].message.content)
print(response.usage)
Streaming is supported if your UI needs it; the request and response shapes stay OpenAI-style.
-
Meter the usage object. Read the token counts from
response.usageon every call, multiply by the model's input/output rate, and record the amount against the calling user or plan. Charge your users in USD or KES in whatever billing system you already run. -
Respect the request rates. Limits are 30 requests/min for unverified accounts and 100 requests/min for trusted accounts. Queue or throttle per-tenant calls in your backend so one user's burst does not exhaust the budget for everyone.
-
Fund the wallet. Fikra usage is drawn from a token-credit wallet topped up by M-Pesa or card via Paystack. Agents can also top up with x402 USDC on Base.
Verify it works
Send one short request with the snippet above and confirm:
response.choices[0].message.contentis non-empty text.response.usagereports non-zero prompt and completion tokens , that is the number your billing logic will consume.- The key in use is the one you scoped for this service, and it is absent from your client bundle and your logs.
If the key was copied with whitespace or belongs to a deactivated account, the call fails with 401; see Common errors.
Costs
All rates are USD per 1M tokens:
| Model | Input | Output |
|---|---|---|
| deepseek-v4-flash-0731 | 0.09 | 0.15 |
| deepseek-v4.1-flash | 0.25 | 0.80 |
| deepseek-v4.1-flash-1017 | 0.30 | 0.85 |
| fikra-auto | 0.40 | 0.40 |
| fikra-auto-pro | 6.00 | 12.00 |
| fikra-code-35b | 1.00 | 1.00 |
Pricing starts at 0.09 USD per 1M input tokens and 0.15 USD per 1M output tokens. Your charge to an end user is your decision: divide the metered token cost by your markup to get the per-user price, then reconcile against your wallet balance. For anything not listed here, check the pricing page.
Common errors
- 401 Unauthorized , the key is missing, malformed, or inactive. Check
FIKRA_API_KEYon the server and confirm the key is still active in your account. - 400 Bad Request , usually an unsupported model name. Use an exact model identifier from the Costs table.
- 429 Too Many Requests , you exceeded 30 requests/min (unverified) or 100 requests/min (trusted). Add per-tenant throttling or queueing and retry after a short delay.
- 503 Service Unavailable , the upstream model is busy. Retry with exponential backoff; do not surface the raw error to your end user.