Platform

SDKs

HTTP client examples for calling Africa API from JavaScript, TypeScript, and Python.

The examples below use HTTP requests directly. Keep these calls in a small shared client to reuse authentication and error handling.

MCP Server for AI Tools

For an AI assistant, the africa-api-mcp server exposes read-only API tools. See the MCP server guide for client configuration and runtime requirements.

Client Patterns

const BASE_URL = "https://api.africa-api.com";

async function africaRequest<T>(path: string): Promise<T> {
  const response = await fetch(`${BASE_URL}${path}`, {
    headers: {
      Authorization: `Bearer ${process.env.AFRICA_API_KEY ?? ""}`,
    },
  });

  if (!response.ok) {
    throw new Error(`Africa API request failed: ${response.status}`);
  }

  return response.json() as Promise<T>;
}

export function listIndicators(category?: string) {
  const suffix = category ? `?category=${encodeURIComponent(category)}` : "";
  return africaRequest<{ data: Array<{ key: string; name: string }> }>(
    `/v1/indicators${suffix}`,
  );
}

export function listData(countryCode: string, metricKey: string) {
  return africaRequest(`/v1/data?country_code=${countryCode}&metric_key=${metricKey}&latest=true`);
}
import requests

BASE_URL = "https://api.africa-api.com"


def africa_request(path: str, api_key: str) -> dict:
    response = requests.get(
        f"{BASE_URL}{path}",
        headers={"Authorization": f"Bearer {api_key}"},
        timeout=10,
    )
    response.raise_for_status()
    return response.json()


def list_indicators(api_key: str, category: str | None = None) -> dict:
    suffix = f"?category={category}" if category else ""
    return africa_request(f"/v1/indicators{suffix}", api_key)


def list_data(api_key: str, country_code: str, metric_key: str) -> dict:
    return africa_request(
        f"/v1/data?country_code={country_code}&metric_key={metric_key}&latest=true",
        api_key,
    )

OpenAPI Schema

If you prefer generated clients:

https://api.africa-api.com/openapi.json

Pin generated clients to the /v1 routes you actually use.

On this page