Quick Start

Get up and running with the AllRoutes AI gateway in under 5 minutes.

Overview

AllRoutes is a unified AI API gateway that gives you access to 100+ models across 9 providers (OpenAI, Anthropic, Google, and more) through a single API key. It uses an OpenAI-compatible request and response format, so you can switch providers by changing one line of code -- no SDK rewrite, no schema migration, no vendor lock-in.

This guide gets you from zero to your first API call in under 5 minutes.

Heads up: the native allroutes / @allroutes/sdk / allroutes-go packages are not yet published. Until they ship, point the official OpenAI client at https://api.allroutes.ai/v1 with your AllRoutes API key — the wire format is identical, so every example below works today.

1. Get Your API Key

Sign up at allroutes.ai and create an API key from the dashboard. Keys come in three flavors, each with a distinct prefix:

PrefixTypeUse Case
allroutes_sk_SecretServer-side applications and scripts
allroutes_pk_PublicBrowser/mobile apps with origin restrictions
allroutes_mgmt_ManagementAdmin scripts that create or revoke other keys

For this quickstart you want a secret key. Store it in an environment variable:

export ALLROUTES_API_KEY="allroutes_sk_..."

2. Use the OpenAI Client (SDKs Coming Soon)

Native allroutes, @allroutes/sdk, and allroutes-go packages are on the roadmap but not yet published. In the meantime, use the official OpenAI client with the base URL pointed at AllRoutes — the request/response shape is identical:

# Python (3.8+)
pip install openai

# Node.js / TypeScript (Node 18+, Bun, or Deno)
npm install openai

For Go, use any OpenAI-compatible client (for example github.com/sashabaranov/go-openai) and override its BaseURL to https://api.allroutes.ai/v1.

3. Make Your First Request

Python (OpenAI client → AllRoutes)

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ALLROUTES_API_KEY"],
    base_url="https://api.allroutes.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Explain quantum computing in one paragraph."}],
)

print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.total_tokens}")

Node.js / TypeScript (OpenAI client → AllRoutes)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ALLROUTES_API_KEY,
  baseURL: "https://api.allroutes.ai/v1",
});

const completion = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Explain quantum computing in one paragraph." }],
});

console.log(completion.choices[0].message.content);
console.log(`Tokens used: ${completion.usage.total_tokens}`);

Go (OpenAI-compatible client → AllRoutes)

import (
    "context"
    "fmt"
    "os"

    openai "github.com/sashabaranov/go-openai"
)

cfg := openai.DefaultConfig(os.Getenv("ALLROUTES_API_KEY"))
cfg.BaseURL = "https://api.allroutes.ai/v1"
client := openai.NewClientWithConfig(cfg)

resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
    Model: "gpt-4o",
    Messages: []openai.ChatCompletionMessage{
        {Role: openai.ChatMessageRoleUser, Content: "Explain quantum computing in one paragraph."},
    },
})
if err != nil {
    panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)

cURL

curl https://api.allroutes.ai/v1/chat/completions \
  -H "Authorization: Bearer $ALLROUTES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "user", "content": "Explain quantum computing in one paragraph."}
    ]
  }'

4. Switch Providers Instantly

Change the model field to use any supported provider -- no other code changes required:

# OpenAI
response = client.chat.completions.create(model="gpt-4o", messages=msgs)

# Anthropic
response = client.chat.completions.create(model="claude-sonnet-4-20250514", messages=msgs)

# Google
response = client.chat.completions.create(model="gemini-2.0-flash", messages=msgs)

AllRoutes-specific routing extensions (model fallback chains, routing strategies, preset references) are exposed via the standard OpenAI request body using the extra_body escape hatch -- see Smart Routing.

5. Enable Streaming

Receive tokens as they are generated for real-time UIs:

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a short story about a robot."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

The streaming protocol is standard SSE with data: [DONE] termination -- see Streaming for the full chunk format and stream_options.include_usage.

6. Check Your Usage

Every response includes token counts. Watch the X-AllRoutes-Cost and X-AllRoutes-Cache response headers to track per-request spend and cache hit rate, or check your balance in the dashboard.

Authentication Recap

All requests require a Bearer token in the Authorization header:

Authorization: Bearer allroutes_sk_...

The base endpoint is https://api.allroutes.ai/v1. See Authentication for scopes, rate limits, and per-key budget controls.

Common Errors

StatusMeaningFix
401Invalid or missing API keyCheck the Authorization header and key prefix
402Insufficient credits or budget exhaustedTop up credits or increase the per-key budget
429Rate limit exceededSlow down, or request a higher RPM tier
404Unknown modelCall /v1/models to list valid identifiers

The SDKs auto-retry on 429 and 5xx with exponential backoff. For deeper guidance, see Error Handling.

See Also