How-to

Add LLM Embeddings to a Knowledge Base on a Budget

Last updated 2026-11-25. Facts are checked against the live registry.

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.05625 USD per 1M input tokens.

Prerequisites

  • Python 3.8+ and pip
  • openai package (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

  1. 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** to 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.05 USD per 1M input tokens (embeddings only consume input tokens)
  • Rate limits: 30 requests/min for unverified accounts, 3,000 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 to API key missing, malformed, or inactive. Verify FIKRA_API_KEY is set correctly.
  • 400 Bad Request to Model name not supported or request payload malformed. Ensure you use a model from the pricing list.
  • 429 Too Many Requests to Exceeded the rate limit (30/100 req/min). Add a short sleep or batch calls.
  • 503 Service Unavailable to Upstream is busy. Retry with exponential back‑off.

Live prices -> · Agent account -> · SDKs ->