Skip to content

OpenAI-Compatible API

AkaRouter provides an OpenAI-compatible API. If your SDK supports a custom baseURL, you usually only need to replace the Base URL and API key.

https://api.akarouter.com/v1

Do not use the console URL, documentation URL, payment URL, or a full endpoint path as the API Base URL.

import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AKAROUTER_API_KEY,
baseURL: "https://api.akarouter.com/v1"
});
const completion = await client.chat.completions.create({
model: process.env.AKAROUTER_MODEL,
messages: [{ role: "user", content: "Give me one concise onboarding tip." }]
});
console.log(completion.choices[0]?.message?.content);

Read AKAROUTER_API_KEY and AKAROUTER_MODEL from server-side environment variables. Do not hard-code them in source code.

import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AKAROUTER_API_KEY"],
base_url="https://api.akarouter.com/v1",
)
completion = client.chat.completions.create(
model=os.environ["AKAROUTER_MODEL"],
messages=[{"role": "user", "content": "Give me one concise onboarding tip."}],
)
print(completion.choices[0].message.content)
Terminal window
curl https://api.akarouter.com/v1/chat/completions \
-H "Authorization: Bearer $AKAROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$AKAROUTER_MODEL"'",
"messages": [{ "role": "user", "content": "ping" }]
}'
  • Read AKAROUTER_API_KEY on the server side. Do not expose it in the browser.
  • Use the model names shown on the Model Status page in the console.
  • Retry timeouts briefly, but do not retry forever.
  • Use exponential backoff for 429, 502, 503, and 504 responses.
  • For 401, 402, and 403 responses, check your key, balance, and account access before retrying.

A successful chat completion response includes choices. With the OpenAI SDK, the content is usually available here:

completion.choices[0]?.message?.content

If the response is not 200, follow the status-code guidance in Common Errors.