Overview
Add inexpensive vector embeddings to your knowledge base using the Fikra API. The service is OpenAI‑compatible, so you can use the standard openai Python SDK with a custom base URL. You pay per‑token in USD, and the cheapest model (deepseek-v4-flash-0731) costs $0.09 USD for input tokens.
Prerequisites
- Python 3.8+ and
pip openaipackage (pip install openai)- A Fikra API key stored in the environment variable
FIKRA_API_KEY - A list of text chunks you want to embed (e.g., documents, FAQ entries)
Step-by-step
- Set up the SDK ```python import os, openai
openai.api_key = os.getenv("FIKRA_API_KEY")
openai.base_url = "https://api.fikraapi.co.ke/v1"
2. **Prepare your texts**python
texts = [
"What is the return policy?",
"How do I reset my password?",
"Pricing details for premium plans",
]
3. **Request embeddings**python
response = openai.embeddings.create(
model="deepseek-v4-flash-0731",
input=texts,
)
embeddings = [e.embedding for e in response.data]
``
4. **Store vectors** – insert eachembedding` into your vector store (e.g., Pinecone, Qdrant, or a simple SQLite + FAISS index). The exact storage code depends on your chosen backend, but the output format is a list of floats ready for indexing.
Verify it works
# Print the dimension of the first vector to confirm a successful call
print(len(embeddings[0]))
If you see a non‑zero length (typically 768‑1536 depending on the model), the embeddings are ready for use.
Costs
- Model:
deepseek-v4-flash-0731 - Pricing: $0.09 USD per 1 M input tokens (embeddings only consume input tokens)
- Rate limits: 30 requests/min for unverified accounts, 100 requests/min for trusted accounts.
- You are billed in USD (or KES) via the token‑credit wallet; top‑ups are available through M‑Pesa, card, or USDC on Base.
Common errors
- 401 Unauthorized – API key missing, malformed, or inactive. Verify
FIKRA_API_KEYis set correctly. - 400 Bad Request – Model name not supported or request payload malformed. Ensure you use a model from the pricing list.
- 429 Too Many Requests – Exceeded the rate limit (30/100 req/min). Add a short sleep or batch calls.
- 503 Service Unavailable – Upstream is busy. Retry with exponential back‑off.