On this page
Quickstart
Send your first request to router.africa in a few minutes, using the SDK you already have.
Get an API key
Create a key in the dashboard under API keys. Keys start with sk-ra- and are shown once, so copy yours now and store it as an environment variable.
export ROUTER_AFRICA_API_KEY="sk-ra-..."$env:ROUTER_AFRICA_API_KEY = "sk-ra-..."Install an SDK
Pick your package manager. The same package works with router.africa; there is no separate router.africa SDK.
npm install openaipnpm add openaiyarn add openaibun add openaipip install openaiSend your first request
Choose how you call the API. Every tab sends the same request to https://api.router.africa/v1.
curl https://api.router.africa/v1/chat/completions \
-H "Authorization: Bearer $ROUTER_AFRICA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Habari! Say hello in Swahili."}]
}'from openai import OpenAI
client = OpenAI(
base_url="https://api.router.africa/v1",
api_key="sk-ra-...", # use an environment variable in real code
)
completion = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Habari! Say hello in Swahili."}],
)
print(completion.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.router.africa/v1",
apiKey: process.env.ROUTER_AFRICA_API_KEY,
});
const completion = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Habari! Say hello in Swahili." }],
});
console.log(completion.choices[0].message.content);curl https://api.router.africa/v1/messages \
-H "Authorization: Bearer $ROUTER_AFRICA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Habari! Say hello in Swahili."}]
}'import anthropic
client = anthropic.Anthropic(
base_url="https://api.router.africa",
api_key="sk-ra-...", # sent as x-api-key
)
message = client.messages.create(
model="anthropic/claude-sonnet-4",
max_tokens=256,
messages=[{"role": "user", "content": "Habari! Say hello in Swahili."}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.router.africa",
apiKey: process.env.ROUTER_AFRICA_API_KEY, // sent as x-api-key
});
const message = await client.messages.create({
model: "anthropic/claude-sonnet-4",
max_tokens: 256,
messages: [{ role: "user", content: "Habari! Say hello in Swahili." }],
});
console.log(message.content[0].text);curl https://api.router.africa/v1/chat/completions \
-H "Authorization: Bearer $ROUTER_AFRICA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Habari! Say hello in Swahili."}]
}'import os
import requests
response = requests.post(
"https://api.router.africa/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['ROUTER_AFRICA_API_KEY']}"},
json={
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "Habari! Say hello in Swahili."}],
},
timeout=60,
)
print(response.json()["choices"][0]["message"]["content"])const response = await fetch("https://api.router.africa/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ROUTER_AFRICA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Habari! Say hello in Swahili." }],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);A successful response includes the model’s reply and a usage object with the tokens used. The response header x-request-id identifies the request in your logs and in any support message.
Stream the response
Add "stream": true to receive tokens as they are generated. See Streaming for the details, including streaming with the Anthropic SDK. Ask for a final usage chunk with stream_options.include_usage.
curl https://api.router.africa/v1/chat/completions \
-H "Authorization: Bearer $ROUTER_AFRICA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"stream": true,
"stream_options": { "include_usage": true },
"messages": [
{ "role": "system", "content": "You are a helpful assistant for a Nairobi delivery startup." },
{ "role": "user", "content": "Write a two-line status message for a delayed parcel." }
]
}'
# The response is a stream of server-sent events:
data: {"id":"gen-8f2c","choices":[{"delta":{"role":"assistant","content":"Your"}}]}
data: {"id":"gen-8f2c","choices":[{"delta":{"content":" parcel is on its way"}}]}
data: {"id":"gen-8f2c","choices":[{"delta":{"content":", running a little late."}}]}
data: {"id":"gen-8f2c","choices":[],"usage":{"prompt_tokens":38,"completion_tokens":21,"total_tokens":59}}
data: [DONE]What a request costs
Requests are paid for with credits. Before a request runs, router.africa holds the credits it may need at the published rate; when it finishes, you are charged for the tokens actually used and the rest of the hold is released. You can see your balance and every request in the dashboard.
Next steps
- Authentication: how keys work and how to keep them safe.
- Messages: use the Anthropic SDK.
- Responses: use the OpenAI Responses API.
- Look up a request: check what one request cost.
- Credits and billing: what a request costs.
- Errors and Rate limits: what to do when a request fails.
- Compatibility notes: where router.africa differs from OpenAI and Anthropic.