Overview
This guide shows developers how to expose a simple OpenAI‑compatible endpoint that forwards requests to Fikra API. The proxy can be used by a mobile‑money business to run chat models without dealing with credit‑card gates.
Prerequisites
- Python 3.8+
openaiPython SDK- A lightweight web framework (e.g., FastAPI)
- Environment variable
FIKRA_API_KEYcontaining your Fikra API key - Internet access to
https://api.fikraapi.co.ke/v1
Step‑by‑step
- Install dependencies
bash pip install openai fastapi uvicorn - Create a proxy server (example using FastAPI). The server receives OpenAI‑style chat requests at
/v1/chat/completionsand forwards them to Fikra API. ```python import os from fastapi import FastAPI, Request, HTTPException import openai
app = FastAPI()
# Configure OpenAI SDK to talk to Fikra API openai.api_key = os.getenv("FIKRA_API_KEY") openai.base_url = "https://api.fikraapi.co.ke/v1"
@app.post("/v1/chat/completions")
async def proxy_chat(request: Request):
payload = await request.json()
try:
response = openai.ChatCompletion.create(
model="deepseek-v4-flash-0731", # any model from the fact block
**payload
)
return response
except openai.error.OpenAIError as e:
# Re‑raise as HTTP error so the client sees the same status code
raise HTTPException(status_code=e.http_status, detail=str(e))
3. **Run the server**bash
uvicorn your_module:app --host 0.0.0.0 --port 8000
``
The proxy is now reachable athttp://
Verify it works
Send a test request to the proxy (replace <host> as needed):
curl -X POST http://<host>:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Hello"}],"max_tokens":50}'
You should receive a JSON response identical to a direct Fikra API chat completion.
Costs
Usage is billed per token. The default rates are $0.09 USD per 1M input tokens and $0.15 USD per 1M output tokens. Specific models have their own rates (e.g., deepseek-v4-flash-0731 uses the default rates, fikra-auto-pro costs $6 USD input / $12 USD output per 1M tokens). See the pricing section of the API docs for the full list.
Common errors
- 401 Unauthorized – API key missing, malformed, or inactive.
- 400 Bad Request – Request format invalid or model not supported.
- 429 Too Many Requests – Exceeded rate limits (30 req/min unverified, 100 req/min trusted).
- 503 Service Unavailable – Upstream busy; retry with exponential backoff.