Integrating Fikra API with AnythingLLM
Prerequisites
- A Fikra API account with a valid API key (
fk_live_...). - Access to the Fikra dashboard to manage keys and token credits.
- AnythingLLM installed and running locally or in your environment.
- Basic familiarity with environment variables and JSON configuration.
Configuration Overview
AnythingLLM supports custom OpenAI-compatible endpoints. Since Fikra API exposes an OpenAI-style chat-completions interface, you can configure AnythingLLM to use Fikra as a custom LLM provider.
Step 1: Set Environment Variables
Export your Fikra API key as an environment variable. This ensures the key is not hardcoded in configuration files.
export FIKRA_API_KEY="fk_live_your_key_here"
Step 2: Configure AnythingLLM
In AnythingLLM, navigate to Settings > LLM Providers and select Custom OpenAI (or equivalent custom endpoint option).
Enter the following values:
- Base URL:
https://api.fikraapi.co.ke/v1 - API Key: Your Fikra API key (
fk_live_...) - Model:
fikra-flash
Note: Check the Fikra model registry in your dashboard for the latest available aliases.
fikra-flashis used here as a default example.
Python Example
Below is a minimal Python example using the openai Python SDK, which is compatible with Fikra’s OpenAI-style interface. This can be used to verify connectivity before configuring AnythingLLM.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.fikraapi.co.ke/v1",
api_key=os.environ["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 API supports streaming via Server-Sent Events (SSE) when stream: true is set. In AnythingLLM, enable streaming in the LLM provider settings if available. For custom integrations, use the stream parameter in your request.
Python Streaming Example
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.fikraapi.co.ke/v1",
api_key=os.environ["FIKRA_API_KEY"]
)
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
| HTTP Status | Meaning | Action |
|---|---|---|
400 |
Bad Request | Check your request payload for invalid parameters, missing fields, or malformed JSON. |
401 |
Unauthorized | Verify your Authorization: Bearer fk_live_... header. Ensure the API key is valid and not expired. |
402 |
Payment Required | Your token-credit wallet may be empty. Top up via the Fikra dashboard using Paystack (M-Pesa or cards accepted). |
429 |
Too Many Requests | You have exceeded the rate limit (30 RPM for unverified accounts, 100 RPM for trusted accounts). Implement exponential backoff. |
503 |
Service Unavailable | Fikra API may be temporarily unavailable. Retry with backoff. Check the Fikra dashboard for status updates. |
Production Checklist
- [ ] Store
FIKRA_API_KEYin a secure environment variable or secrets manager. - [ ] Use
https://api.fikraapi.co.ke/v1as the base URL. - [ ] Select an appropriate Fikra model alias (e.g.,
fikra-flash) based on your use case. - [ ] Implement retry logic with exponential backoff for
429and503errors. - [ ] Monitor token-credit usage in the Fikra dashboard to avoid
402errors. - [ ] Test streaming behavior if your application requires real-time responses.
- [ ] Verify rate limits (30 RPM unverified, 100 RPM trusted) and adjust concurrency accordingly.
- [ ] Log and alert on non-2xx responses for operational visibility.
Disclaimer: Fikra API is an OpenAI-compatible interface. Always refer to the official Fikra documentation and dashboard for the latest model availability, pricing, and rate limits.
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.