CanalAPI
Getting started

Introduction

CanalAPI is a unified gateway over 600+ LLM, image, and audio models. Use any OpenAI-compatible client — point base_url at https://api.canalapi.com/v1, pass your key, and ship.

Ready in 60 seconds
Grab a key from the console, run the snippet below, done.
Get API key
→ Chat completions
GPT-4o, Claude 4, Gemini 2.5 — same shape
→ Embeddings
OpenAI & BGE vectors, 8K+ context
→ Auto-routing
Automatic failover across channels
→ Streaming
SSE, token-by-token, OpenAI-compatible

Quickstart

You need two things: an API key (from the console) and a model slug. Here's the simplest possible request:

cURL
# Any OpenAI-compatible client works — just swap the base URL
curl https://api.canalapi.com/v1/chat/completions \
  -H "Authorization: Bearer $CANAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-4-sonnet",
    "messages": [{"role":"user","content":"Hello"}]
  }'

Response

application/json
{
  "id": "chatcmpl_8K2m3",
  "object": "chat.completion",
  "created": 1745078400,
  "model": "claude-4-sonnet",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "Hi there!" },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 8, "completion_tokens": 3, "total_tokens": 11 }
}

Authentication

Pass your key via the Authorization: Bearer ... header. Keys are scoped — create separate keys per environment (dev / staging / prod) from the console.

i
Tip: Set CANAL_KEY in your environment, then any OpenAI SDK picks it up automatically via OPENAI_API_KEY — just point baseURL and you're compatible.

Chat completionsPOST/v1/chat/completions

Create a chat completion. Compatible with OpenAI's chat/completions — same parameters, same response shape.

Request body

FieldTypeDescription
modelrequiredstringModel slug, e.g. claude-4-sonnet, gpt-4o. See full model list.
messagesrequiredarrayConversation as an array of { role, content } objects. Roles: system, user, assistant.
streamoptionalbooleanIf true, returns tokens as SSE. Default false.
temperatureoptionalnumber0–2. Higher = more random. Default 1.
max_tokensoptionalintegerCap on completion tokens. Model-dependent default.
toolsoptionalarrayTool definitions for function calling.

Streaming example

Python · SSE
stream = client.chat.completions.create(
  model="claude-4-sonnet",
  messages=[{"role": "user", "content": "Write a haiku."}],
  stream=True,
)
for chunk in stream:
  print(chunk.choices[0].delta.content or "", end="")

Errors & retries

CanalAPI uses conventional HTTP status codes. On 5xx upstream failures we auto-retry across healthy channels — you only see an error after the routing pool is exhausted.

CodeMeaningWhat to do
400bad_requestCheck request body — likely a bad model or malformed messages.
401unauthenticatedMissing / revoked key. Create a new one in the console.
402insufficient_balanceTop up your balance, then retry.
429rate_limitedBack off per Retry-After header.
502/503upstream_errorAlready retried — raise a support ticket if persistent.
Idempotency: Pass an Idempotency-Key header (UUID) on non-idempotent requests. We dedupe within 24h.

SDKs

Official SDKs wrap retries, streaming, and error normalization. Under the hood they're thin wrappers over the HTTP API.

Python
pip install canalapi
TypeScript
npm i @canalapi/sdk
Go
go get canalapi/canal-go
Ready to build?
Grab your first API key and make a request in under 2 minutes.
Get API key
IntroductionChat completions