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 from openai import OpenAI
client = OpenAI(base_url="https://api.fikraapi.co.ke/v1", api_key="fk_...")
response = client.chat.completions.create( model="deepseek-v4-1-flash-economy-free", messages=[{"role": "user", "content": "Hello"}], ) print(response.choices[0].message.content)
3. **Run the server**
```bash
uvicorn your_module:app --host 0.0.0.0 --port 8000
```
The proxy is now reachable at `http://<host>:8000/v1/chat/completions`.
## Verify it works
Send a test request to the proxy (replace `<host>` as needed):
```bash
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.05625 USD per 1M input tokens and $0.1 USD per 1M output tokens. Specific models have their own rates (e.g., deepseek-v4-flash-0731 uses the default rates, deepseek-v4.1-flash-1017 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 to API key missing, malformed, or inactive.
- 400 Bad Request to Request format invalid or model not supported.
- 429 Too Many Requests to Exceeded rate limits (30 req/min unverified, 100 req/min trusted).
- 503 Service Unavailable to Upstream busy; retry with exponential backoff.