By Fikra DevRel • 4 min read

Fikra API Payment Methods and Token-Credit Wallet

Fikra API Payment Methods and Token-Credit Wallet

Payment Methods and Billing

Fikra API uses a token-credit wallet system for billing. The platform has Paystack billing integration and publicly states that M-Pesa and card payments are accepted.

Note on Flutterwave: Flutterwave is not listed as a verified payment method for Fikra API. If you intend to use Flutterwave for payments, you must confirm its availability directly with Fikra before implementation. Do not assume compatibility based on general market availability.

What is a Token-Credit Wallet?

A token-credit wallet is a prepaid balance system where developers purchase credits (tokens) that are deducted from their account as they make API requests. This model separates payment processing from API usage, allowing for predictable cost management.

Account and Top-Up Flow

  1. Access Dashboard: Log in to the Fikra dashboard at https://fikraapi.co.ke.
  2. Generate API Key: Create a new API key (format: fk_live_...) for your application.
  3. Top Up Wallet: Navigate to the billing section to add funds using supported methods (M-Pesa or cards via Paystack integration).
  4. Verify Balance: Ensure your token-credit balance is sufficient before making API calls.

Monitoring Balance and Handling HTTP 402

Developers should implement logic to monitor their token-credit balance. If the balance is insufficient to cover the cost of a request, the API will return an HTTP 402 (Payment Required) status code.

Best Practices: - Check the response status code after each API call. - If a 402 error is received, pause API requests and prompt the user to top up their wallet. - Avoid retrying requests immediately after a 402 error without verifying the balance has been replenished.

Security Advice

  • Never expose Fikra API keys in browser code. API keys should be stored securely on your backend server.
  • Use environment variables (e.g., FIKRA_API_KEY) to manage credentials in your development and production environments.
  • Rotate API keys regularly and revoke any keys that may have been compromised.

Code Example: Handling 402 Errors

import os
import requests

FIKRA_API_KEY = os.getenv("FIKRA_API_KEY")
BASE_URL = "https://api.fikraapi.co.ke/v1"

def make_chat_request():
    headers = {
        "Authorization": f"Bearer {FIKRA_API_KEY}",
        "Content-Type": "application/json"
    }
    payload = {
        "model": "fikra-flash",
        "messages": [{"role": "user", "content": "Hello"}]
    }

    response = requests.post(f"{BASE_URL}/chat/completions", headers=headers, json=payload)

    if response.status_code == 402:
        print("Insufficient token-credit balance. Please top up your wallet.")
        return None
    elif response.status_code == 200:
        return response.json()
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

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