Overview
Fikra API is an OpenAI-compatible AI inference API that lets you run chat and embedding models behind one OpenAI-style endpoint. For retrieval augmented generation (RAG), you can send documents to the embeddings endpoint and get vector embeddings back in OpenAI format. Because the API is OpenAI-compatible, it works with anything that accepts an OpenAI-compatible base URL.
Prerequisites
- A Fikra API key, stored in the environment variable
FIKRA_API_KEY - Python with the
openaiSDK installed - Documents as plain text or a list of text strings
Step-by-step
- Install the OpenAI SDK
bash
pip install openai
- Create the client
The base URL is https://api.fikraapi.co.ke/v1.
```python from openai import OpenAI
client = OpenAI( base_url="https://api.fikraapi.co.ke/v1", api_key=os.environ["FIKRA_API_KEY"], ) ```
- Embed your documents
Choose a model from the Fikra API model list. For example, you can use fikra-auto.
```python documents = [ "Fikra API supports OpenAI-style chat completions.", "Embeddings are returned in OpenAI format.", ]
response = client.embeddings.create( model="fikra-auto", input=documents, )
for i, data in enumerate(response.data): print(i, len(data.embedding)) ```
- Store and use the vectors
Store the returned embedding vectors in your vector database, then use them for retrieval in your RAG pipeline.
Verify it works
A successful call returns an OpenAI-style embeddings object with a data list. Each item in that list contains an embedding array and an index matching the order of your input documents. If you see one embedding per input document, the request worked.
Costs
Fikra API uses a token-credit wallet. You can top up with M-Pesa, cards via Paystack, or x402 USDC on Base for agents. Model pricing ranges from $0.09 to $6.00 per 1M input tokens and $0.15 to $12.00 per 1M output tokens depending on the model you choose. For exact embedding pricing and the full model list, check the pricing page.
Common errors
- 401 Unauthorized — The API key is missing, invalid, or inactive. Check that
FIKRA_API_KEYis set and that your key has not been revoked. - 400 Bad Request — The requested model is not supported or the request payload is invalid. Confirm the model name matches one in the model list.
- 429 Too Many Requests — You have hit the rate limit: 30 requests per minute for unverified accounts and 100 requests per minute for trusted accounts. Reduce request frequency or apply for trusted status.
- 503 Service Unavailable — The upstream service is busy. Retry the request with backoff.