Overview
Create a customer‑support chatbot using Fikra API’s OpenAI‑compatible chat endpoint. The bot runs on a pay‑per‑token model (USD or KES) and can be monetised through support subscriptions, helping it cover its own cost.
Prerequisites
- Python 3.8+
openaiPython package (pip install openai)- Fikra API key stored in environment variable
FIKRA_API_KEY - Internet connectivity
Step-by-step
- Install the SDK
bash pip install openai - Configure the client ```python import os, openai
openai.api_key = os.getenv('FIKRA_API_KEY')
openai.base_url = 'https://api.fikraapi.co.ke/v1'
3. **Send a chat request**python
response = openai.ChatCompletion.create(
model='fikra-auto',
messages=[
{'role': 'system', 'content': 'You are a helpful support assistant.'},
{'role': 'user', 'content': 'How do I reset my password?'}
],
stream=False
)
print(response.choices[0].message.content)
```
4. Hook the response into your support channel (e.g., webhook, chat widget).
5. Monitor usage via the Fikra dashboard to ensure revenue exceeds token cost.
Verify it works
Running the script above should return a concise answer like “To reset your password, click ‘Forgot password’ on the login page…”. A successful HTTP 200 response confirms the endpoint is reachable and the API key is valid.
Costs
- Model:
fikra-auto - Input: $0.40 USD per 1 M tokens
- Output: $0.40 USD per 1 M tokens
- Rate limits: 30 requests/min for unverified keys, 100 requests/min for trusted keys. Track token usage to compare against any subscription revenue.
Common errors
- 401 Unauthorized – API key missing, inactive, or scoped incorrectly.
- 400 Bad Request – Invalid payload or unsupported model name.
- 429 Too Many Requests – Exceeded the request‑rate limit; back‑off and retry.
- 503 Service Unavailable – Upstream busy; retry with exponential back‑off.