Skip to content

Quickstart

Make your first AnyRouter request in under five minutes by pointing any OpenAI-compatible client at one base URL.

AnyRouter is a universal AI model router — one OpenAI-compatible gateway that reaches 180+ models across 17+ providers. This page gets you from zero to your first response in under five minutes.

Three things stay the same no matter how you call AnyRouter:

SettingValue
Base URLhttps://anyrouter.dev/api/v1
API keyyour sk-ar-v1-… inference key
Model idprovider/model, e.g. z-ai/glm-4.7-flash

Make your first request

Create an API key

Sign in to the dashboard and create a new key — no card required. AnyRouter inference keys are prefixed with sk-ar-v1- so you can tell them apart from upstream provider keys.

A new account starts at $0 balance with no included credits. Before your first paid-model call, either top up or subscribe to Go ($2/mo, includes $4/mo credits) — or donate a provider key to unlock Go for free. See Credits & Billing for all the ways to get started.

Set your key as an environment variable

export ANYROUTER_API_KEY="sk-ar-v1-your-key"

Send a chat completion

The most direct call is a plain HTTP request to /api/v1/chat/completions — no SDK required, so it works from any language that can make an HTTP call.

curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer $ANYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "z-ai/glm-4.7-flash",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Keys are scoped per organization. Create a separate key for every environment (dev, staging, prod) so you can rotate them independently.

To stream tokens as they arrive, add "stream": true to the request body — the response becomes a stream of server-sent events.

Call it from your stack

The same request works from any OpenAI-compatible client. Pick whichever fits your project.

AnyRouter is a drop-in replacement for the OpenAI API. Point base_url at AnyRouter, pass your key, and use a provider/model id — no other code changes.

from openai import OpenAI

client = OpenAI(
    base_url="https://anyrouter.dev/api/v1",
    api_key="sk-ar-v1-your-key",
)

response = client.chat.completions.create(
    model="z-ai/glm-4.7-flash",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: "sk-ar-v1-your-key",
})

const response = await client.chat.completions.create({
  model: "z-ai/glm-4.7-flash",
  messages: [{ role: "user", content: "Hello!" }],
})
console.log(response.choices[0].message.content)

Install @anyr/sdk and call chat.completions.create. The client reads ANYROUTER_API_KEY when you omit the key, and targets https://anyrouter.dev/api/v1 by default. Attribution headers are sent automatically so usage shows up in rankings and analytics.

npm install @anyr/sdk
export ANYROUTER_API_KEY="sk-ar-v1-your-key"
import { AnyRouter } from "@anyr/sdk"

// Reads the key from ANYROUTER_API_KEY when omitted.
const client = new AnyRouter()

const completion = await client.chat.completions.create({
  model: "z-ai/glm-4.7-flash",
  messages: [{ role: "user", content: "Hello!" }],
})

console.log(completion.choices[0].message.content)

See the SDK guide and Chat Completions API reference for the full request and response shape.

Any OpenAI-compatible framework — the Vercel AI SDK, LangChain, LlamaIndex — works the same way: set the base URL, supply your key, and reference models by their provider/model id.

import { createOpenAI } from "@ai-sdk/openai"

const anyrouter = createOpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: process.env.ANYROUTER_API_KEY,
})

const model = anyrouter("anthropic/claude-sonnet-4.6")

Or launch a coding agent

Install the native CLI (Linux, macOS, Windows — no Node required), sign in once, and spawn Claude Code / Codex / OpenCode / Grok / Pi through the gateway:

curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr auth login
anyr claude --install --ok
anyr usage

Full reference: AnyRouter CLI. For a Herdr fleet loop with Grok Bot, see Grok Bot, Herdr, and Anyr CLI.

Choose a model

Model ids follow the provider/model convention. Browse the full list on the models page or fetch it via the API:

curl https://anyrouter.dev/api/v1/models \
  -H "Authorization: Bearer sk-ar-v1-your-key"

A few popular choices:

Model idProviderNotes
z-ai/glm-4.7-flashZ-AIFast, low-cost — good first request
anthropic/claude-sonnet-4.6Anthropic1M context, strong coding
anthropic/claude-haiku-4.5AnthropicFast and cheap
google/gemini-3.1-proGoogleMultimodal, long context

How AnyRouter routes a request

Every request flows through three stages — key auth, model selection, and upstream dispatch — with automatic fallback if the first provider is unavailable:

flowchart LR
    Client([Your app]) -->|sk-ar-v1-...| A[AnyRouter API]
    A --> B{Route}
    B -->|primary| P[Provider A]
    B -->|fallback| Q[Provider B]
    P -->|response| Client
    Q -->|response| Client

Related