Integrating Fikra API with Langflow
Prerequisites
- A Fikra API account with a valid API key (
fk_live_...). - Langflow installed and running.
- Access to the Fikra dashboard to manage API keys and token credits.
Environment Variable Setup
Langflow supports OpenAI-compatible endpoints. To use Fikra API, configure the following environment variables in your Langflow environment or .env file:
FIKRA_API_KEY=fk_live_your_key_here
FIKRA_BASE_URL=https://api.fikraapi.co.ke/v1
In Langflow, when adding an LLM component, select the OpenAI provider type. Then, override the default base URL and API key with the Fikra-specific values above. This allows Langflow to route requests to Fikra’s OpenAI-compatible chat-completions interface.
Python Example
Below is a minimal Python example using the openai Python SDK, which is compatible with Fikra’s API. This pattern mirrors how Langflow internally communicates with OpenAI-compatible endpoints.
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
Fikra supports streaming via Server-Sent Events (SSE) when stream: true is set. In Langflow, enable streaming in the LLM component settings if available. For direct SDK usage:
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 request body or invalid model alias. Verify that
modelis one of the public Fikra aliases (e.g.,fikra-flash). - 401 Unauthorized: Missing or invalid
Authorization: Bearer fk_live_...header. Check yourFIKRA_API_KEY. - 402 Payment Required: Insufficient token credits in your Fikra 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 Fikra API outage. Retry with backoff and monitor the Fikra dashboard for status updates.
Production Checklist
- [ ] Store
FIKRA_API_KEYin a secure environment variable or secrets manager. - [ ] Use
fikra-flashfor low-latency tasks; check the model registry for other aliases. - [ ] Implement retry logic with exponential backoff for 429 and 503 errors.
- [ ] Monitor token credit usage in the Fikra dashboard.
- [ ] Test streaming behavior in staging before production deployment.
- [ ] Validate that Langflow’s OpenAI-compatible configuration points to
https://api.fikraapi.co.ke/v1.
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.