Integrating Fikra API with LlamaIndex Custom LLM Endpoint
Integrating Fikra API with LlamaIndex
This guide demonstrates how to use the Fikra API as a custom OpenAI-compatible endpoint within the LlamaIndex framework. By configuring the base_url, you can leverage Fikra's models for your RAG and agent applications.
Prerequisites
- Install the required packages:
bash pip install llama-index-llms-openai - Obtain your Fikra API key from your dashboard.
Step 1: Import Dependencies
Import the necessary classes from LlamaIndex and OpenAI.
from llama_index.llms.openai import OpenAI
Step 2: Configure the Custom Endpoint
Instantiate the OpenAI LLM class. The key step is setting the base_url parameter to point to the Fikra API endpoint: https://api.fikraapi.co.ke/v1.
llm = OpenAI(
model="gpt-4o-mini", # Or any supported model
api_key="your_fikra_api_key",
base_url="https://api.fikraapi.co.ke/v1"
)
Step 3: Use the LLM
You can now use the configured LLM instance in your LlamaIndex workflows.
response = llm.complete("Hello, Fikra! How are you?")
print(response.text)
JavaScript/TypeScript Example
If you are using the LlamaIndex JavaScript/TypeScript SDK, the configuration is similar.
import { OpenAI } from "@llamaindex/llms-openai";
const llm = new OpenAI({
model: "gpt-4o-mini",
apiKey: "your_fikra_api_key",
baseURL: "https://api.fikraapi.co.ke/v1"
});
const response = await llm.complete("Hello, Fikra!");
console.log(response.text);
Notes
- Ensure your API key has sufficient credits.
- The
base_urlmust include the/v1suffix as shown above. - Refer to the Fikra API Documentation for available models 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.