By Fikra DevRel • 4 min read

Integrating Fikra API with Vercel AI SDK

Integrating Fikra API with Vercel AI SDK

Integrating Fikra API with Vercel AI SDK

This guide demonstrates how to configure the Vercel AI SDK to use Fikra API as a custom OpenAI-compatible endpoint. Fikra API is hosted at fikraapi.co.ke with the base URL api.fikraapi.co.ke/v1.

Prerequisites

  1. Install the Vercel AI SDK: bash npm install ai @ai-sdk/openai
  2. Obtain your Fikra API key from your Fikra dashboard.

Step 1: Configure the OpenAI Provider

To use Fikra API, you need to instantiate the OpenAI provider with a custom baseURL pointing to Fikra's endpoint.

import { createOpenAI } from '@ai-sdk/openai';

const fikra = createOpenAI({
  baseURL: 'https://api.fikraapi.co.ke/v1',
  apiKey: process.env.FIKRA_API_KEY,
});

Step 2: Use the Provider in Your Application

You can now use the fikra provider to generate text, stream responses, or perform other AI tasks.

Example: Generate Text

import { generateText } from 'ai';

const { text } = await generateText({
  model: fikra('gpt-4o-mini'), // Use any supported model
  prompt: 'Hello, Fikra API!',
});

console.log(text);

Example: Stream Text

import { streamText } from 'ai';

const { stream } = streamText({
  model: fikra('gpt-4o-mini'),
  prompt: 'Tell me a short story.',
});

for await (const chunk of stream) {
  process.stdout.write(chunk);
}

Step 3: Environment Variables

Ensure your FIKRA_API_KEY is set in your environment variables. For local development, use a .env file:

FIKRA_API_KEY=your_fikra_api_key_here

Notes

  • Fikra API is fully compatible with the OpenAI API format.
  • Replace gpt-4o-mini with any model supported by Fikra API.
  • For production, ensure your API key is securely managed and not exposed in client-side code.

JM
// The Founder

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.

usagestatusdashboard