Text Generation Inference (TGI) Alternative: Integrating with Fikra API
Overview
Text Generation Inference (TGI) is an external inference framework. Fikra API does not host TGI or claim compatibility with TGI-specific protocols. However, Fikra API provides an OpenAI-style chat-completions interface. You can use standard OpenAI-compatible SDKs or raw HTTP clients to interact with Fikra API, effectively replacing a local TGI deployment with a managed API endpoint.
Prerequisites
- A Fikra API account with a valid API key (
fk_live_...). - Python 3.8+ or Node.js 16+.
- The
openaiPython package oropenaiNode.js package (or any HTTP client).
Environment Variable Setup
Store your API key in an environment variable to avoid hardcoding secrets.
export FIKRA_API_KEY="fk_live_your_key_here"
Python Example
The following example uses the openai Python package configured to point to the Fikra API base URL.
import os
from openai import OpenAI
# Initialize client with Fikra API base URL
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": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, Fikra!"}
]
)
print(response.choices[0].message.content)
Streaming Guidance
Fikra API supports streaming via Server-Sent Events (SSE) when stream: true is set. The response will be a stream of chunks.
stream = client.chat.completions.create(
model="fikra-flash",
messages=[
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
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
Authorizationheader. Ensure the Bearer token is correctly formatted. - 402 Payment Required: Insufficient token credits in your wallet. Top up via the Fikra dashboard.
- 429 Too Many Requests: Rate limit exceeded. Unverified accounts are limited to 30 RPM; trusted accounts to 100 RPM. Implement exponential backoff.
- 503 Service Unavailable: Temporary server issue. Retry with backoff.
Production Checklist
- API Key Management: Use environment variables or a secrets manager. Never commit keys to version control.
- Rate Limiting: Implement client-side throttling to stay within 30 RPM (unverified) or 100 RPM (trusted) limits.
- Error Handling: Handle 429 and 503 errors with retry logic and exponential backoff.
- Monitoring: Log request latency and error rates. Monitor token credit usage via the Fikra dashboard.
- Model Selection: Use
fikra-flashfor low-latency tasks. Check the model registry for other aliases likefikra-pro-20bif higher quality is needed. - Security: Use HTTPS for all requests. Validate input to prevent prompt injection if applicable to your use case.
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.