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?
- Native M-Pesa Support: Buy credits directly via M-Pesa STK Push. No credit card required.
- Zero Code Rewrites: Fikra’s endpoints are fully compatible with the official OpenAI SDK. If your code works with
api.openai.com, it works withapi.fikraapi.co.ke. - Low Latency for Africa: Optimized routing ensures faster response times for developers in East and Southern Africa.
- Transparent Pricing: Pay only for what you use, with no hidden fees or subscription traps.
Getting Started
Step 1: Create an Account
- Visit fikraapi.co.ke.
- Sign up with your email and phone number.
- Verify your account via SMS.
Step 2: Purchase Credits with M-Pesa
- Log in to your Fikra dashboard.
- Navigate to Billing > Add Credits.
- Select M-Pesa as your payment method.
- Enter your M-Pesa phone number.
- You will receive an STK Push prompt on your phone. Enter your M-Pesa PIN to confirm.
- Your credits will be instantly reflected in your dashboard.
Step 3: Get Your API Key
- Go to Settings > API Keys.
- Generate a new API key.
- 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-4oandgpt-4o-minigpt-3.5-turbodall-e-3(Image Generation)whisper-1(Speech-to-Text)
Check the Fikra Model Catalog for the latest availability and pricing.
Best Practices
- Monitor Usage: Use the Fikra dashboard to track your credit consumption. Set up alerts to avoid running out of credits mid-project.
- Cache Responses: For repetitive queries, implement caching on your end to save credits.
- Use Smaller Models: For simple tasks, use
gpt-4o-miniinstead ofgpt-4oto reduce costs. - 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_urlis set tohttps://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?
Fikra API is hosted at fikraapi.co.ke. Base URL: https://api.fikraapi.co.ke/v1
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.