Integrating vLLM with Fikra API
Prerequisites
- A Fikra API key (
fk_live_...) generated from the Fikra dashboard. - Python 3.8+ or Node.js 18+.
- The
openaiPython package oropenaiNode.js package installed. - Access to the Fikra API base URL:
https://api.fikraapi.co.ke/v1.
Environment Variable Setup
Set your Fikra API key as an environment variable to avoid hardcoding credentials:
export FIKRA_API_KEY="fk_live_your_key_here"
Python Example
Fikra API is OpenAI-compatible. You can use the standard openai Python SDK by pointing it to the Fikra base URL.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.fikraapi.co.ke/v1",
api_key=os.getenv("FIKRA_API_KEY")
)
response = client.chat.completions.create(
model="fikra-flash",
messages=[
{"role": "user", "content": "Hello, Fikra!"}
]
)
print(response.choices[0].message.content)
Streaming Guidance
To enable streaming, set stream: true in the request. The API responds with Server-Sent Events (SSE).
stream = client.chat.completions.create(
model="fikra-flash",
messages=[
{"role": "user", "content": "Explain quantum computing simply."}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Common Errors
- 400 Bad Request: Malformed JSON, missing required fields, or invalid model alias. Check the model registry for available aliases.
- 401 Unauthorized: Missing or invalid
Authorization: Bearer fk_live_...header. - 402 Payment Required: Insufficient token credits in your Fikra wallet. Top up via Paystack billing integration.
- 429 Too Many Requests: Rate limit exceeded. Unverified accounts are limited to 30 RPM; trusted accounts to 100 RPM.
- 503 Service Unavailable: Temporary server issue. Implement retry logic with exponential backoff.
Production Checklist
- [ ] Use environment variables for API keys; never hardcode them.
- [ ] Implement retry logic with exponential backoff for 429 and 503 errors.
- [ ] Monitor token usage via the Fikra dashboard to manage wallet balance.
- [ ] Validate model aliases against the current model registry before deployment.
- [ ] Test streaming behavior under load to ensure SSE handling is robust.
- [ ] Log request IDs for debugging and support purposes.
James Miano
CTO & ML Engineer at Lacesse Ventures. James specializes in low-overhead LLM quantization processes, custom ternary weights architectures, and localized server optimization.
Stop paying for overpriced round-trip latency
Why route queries over Western servers when you can use low-overhead hardware located in Nairobi? Save 87% on your monthly inference spend. No minimum credit limits. M-Pesa ready.