By Fikra DevRel • 4 min read

Paying for AI Inference with M-Pesa: A Developer's Guide to Fikra API

Paying for AI Inference with M-Pesa: A Developer's Guide to Fikra API

Paying for AI Inference with M-Pesa: A Developer's Guide to Fikra API

For African developers, accessing global AI models like GPT-4 or DALL-E has historically been a logistical nightmare. The primary barrier? Payment. Most AI providers require international credit cards, which are scarce, expensive, or simply unavailable for many developers in the region.

Fikra API solves this by acting as a bridge. It accepts M-Pesa natively for purchasing OpenAI API credits while providing OpenAI-compatible endpoints. This means you can pay with your local mobile money wallet and use your existing OpenAI SDK code without a single line of rewrite.

Why Fikra API?

  1. Native M-Pesa Support: Buy credits directly via M-Pesa STK Push. No credit card required.
  2. Zero Code Rewrites: Fikra’s endpoints are fully compatible with the official OpenAI SDK. If your code works with api.openai.com, it works with api.fikraapi.co.ke.
  3. Low Latency for Africa: Optimized routing ensures faster response times for developers in East and Southern Africa.
  4. Transparent Pricing: Pay only for what you use, with no hidden fees or subscription traps.

Getting Started

Step 1: Create an Account

  1. Visit fikraapi.co.ke.
  2. Sign up with your email and phone number.
  3. Verify your account via SMS.

Step 2: Purchase Credits with M-Pesa

  1. Log in to your Fikra dashboard.
  2. Navigate to Billing > Add Credits.
  3. Select M-Pesa as your payment method.
  4. Enter your M-Pesa phone number.
  5. You will receive an STK Push prompt on your phone. Enter your M-Pesa PIN to confirm.
  6. Your credits will be instantly reflected in your dashboard.

Step 3: Get Your API Key

  1. Go to Settings > API Keys.
  2. Generate a new API key.
  3. Copy this key. You will use it in your code.

Code Example: Using Fikra API with OpenAI SDK

The beauty of Fikra API is that you don’t need to change your logic. You only change the base URL and API key.

Python Example

from openai import OpenAI

# Initialize the client with Fikra's base URL and your Fikra API key
client = OpenAI(
    api_key="your_fikra_api_key",
    base_url="https://api.fikraapi.co.ke/v1"
)

# Use the same OpenAI methods
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum computing in simple terms."}
    ]
)

print(response.choices[0].message.content)

Node.js Example

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'your_fikra_api_key',
  baseURL: 'https://api.fikraapi.co.ke/v1'
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Explain quantum computing in simple terms.' }
    ],
  });

  console.log(completion.choices[0].message.content);
}

main();

Supported Models

Fikra API currently supports a wide range of OpenAI models, including:

  • gpt-4o and gpt-4o-mini
  • gpt-3.5-turbo
  • dall-e-3 (Image Generation)
  • whisper-1 (Speech-to-Text)

Check the Fikra Model Catalog for the latest availability and pricing.

Best Practices

  1. Monitor Usage: Use the Fikra dashboard to track your credit consumption. Set up alerts to avoid running out of credits mid-project.
  2. Cache Responses: For repetitive queries, implement caching on your end to save credits.
  3. Use Smaller Models: For simple tasks, use gpt-4o-mini instead of gpt-4o to reduce costs.
  4. Secure Your API Key: Never expose your Fikra API key in client-side code. Use environment variables or a backend proxy.

Troubleshooting

  • M-Pesa Payment Failed: Ensure your M-Pesa account has sufficient balance and that your phone number is correctly registered with Safaricom.
  • 401 Unauthorized: Double-check that you are using your Fikra API key (not your OpenAI key) and that the base_url is set to https://api.fikraapi.co.ke/v1.
  • 402 Payment Required: Your credits are insufficient. Top up via M-Pesa in the dashboard.

Conclusion

Fikra API removes the payment barrier for African developers, allowing you to build with the world’s best AI models using the payment method you already trust: M-Pesa. With zero code rewrites, you can start building AI-powered applications today.

Ready to start?

  1. Sign Up
  2. Buy Credits with M-Pesa
  3. Build with OpenAI-compatible endpoints

Fikra API is hosted at fikraapi.co.ke. Base URL: https://api.fikraapi.co.ke/v1


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