Contents
Make your first request
NightRouter gives you one API key for many models. It speaks the OpenAI API and the Anthropic Messages API, so tools that let you set a custom base URL can usually be pointed at it by changing the base URL and the key.
Create a key under Dashboard → API keys, then use it in place of sk-nr-your-key in the examples below.
Generate your setup
Pick your tool and model, then copy the exact settings. Only models that support the API your tool uses are listed.
12 models with Anthropic Messages API
Add to ~/.zshrc, then run claude.
export ANTHROPIC_BASE_URL='https://api.nightrouter.ai' export ANTHROPIC_AUTH_TOKEN='sk-nr-your-key' export ANTHROPIC_MODEL='claude-fable-5'
Authentication
Send your key as a Bearer token in the Authorization header. Anthropic-style clients may send it in the x-api-key header instead.
| API | Base URL | Header |
|---|---|---|
| OpenAI-compatible | https://api.nightrouter.ai/v1 | Authorization: Bearer <key> |
| Anthropic Messages | https://api.nightrouter.ai | Authorization: Bearer <key> or x-api-key: <key> |
Send a request
A minimal call to the chat completions endpoint. Put your own key in place of the placeholder.
curl https://api.nightrouter.ai/v1/chat/completions \ -H "Authorization: Bearer sk-nr-your-key" -H "Content-Type: application/json" \ -d '{"model":"claude-fable-5","messages":[{"role":"user","content":"Hello"}]}'
Models & pricing
Use a model id from the model library. Prices are listed per 1M tokens or per request, and your usage is recorded in the logs of your dashboard.
Claude Code
Claude Code reads its endpoint and key from environment variables. Add these lines to your shell profile, then run claude.
export ANTHROPIC_BASE_URL='https://api.nightrouter.ai' export ANTHROPIC_AUTH_TOKEN='sk-nr-your-key' export ANTHROPIC_MODEL='claude-fable-5'
Codex CLI
Codex CLI talks to the Responses API. Add this provider to its config file and export your key as NIGHTROUTER_API_KEY.
model = "your-model-id" model_provider = "nightrouter" [model_providers.nightrouter] name = "NightRouter" base_url = "https://api.nightrouter.ai/v1" env_key = "NIGHTROUTER_API_KEY" wire_api = "responses" # export NIGHTROUTER_API_KEY="sk-nr-your-key"
No model that supports the Responses API is listed right now, so this example uses the placeholder your-model-id. Replace it with a model id once one is available.
Coding agents
In tools such as Cline, Roo Code or Cursor, choose the OpenAI-compatible provider option, set the base URL to https://api.nightrouter.ai/v1 and paste your key.
Cline / Roo Code
Open the provider settings and fill in these fields.
API Provider OpenAI Compatible Base URL https://api.nightrouter.ai/v1 API Key sk-nr-your-key Model ID claude-fable-5
Cursor
Open Settings → Models and fill in these fields.
OpenAI API Key sk-nr-your-key Override OpenAI Base URL https://api.nightrouter.ai/v1 Add custom model claude-fable-5
The same base URL and key may also work in other tools that let you set a custom OpenAI-compatible base URL, for example Kilo Code, Continue and Zed.
SDKs
Point the official SDKs at NightRouter by changing the base URL and the key.
OpenAI SDK (Python)
Install the openai package, then run this.
from openai import OpenAI client = OpenAI(base_url="https://api.nightrouter.ai/v1", api_key="sk-nr-your-key") r = client.chat.completions.create(model="claude-fable-5", messages=[{"role": "user", "content": "Hello"}]) print(r.choices[0].message.content)
Anthropic SDK (TypeScript)
Install @anthropic-ai/sdk, then run this.
import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ baseURL: "https://api.nightrouter.ai", apiKey: "sk-nr-your-key" }); const msg = await client.messages.create({ model: "claude-fable-5", max_tokens: 1024, messages: [{ role: "user", content: "Hello" }] });
Chat clients
Chat apps that let you set a custom OpenAI-compatible base URL, for example Cherry Studio, LobeChat, Open WebUI, LibreChat or TypingMind, can be pointed at NightRouter: add a custom provider with the base URL https://api.nightrouter.ai/v1 and your key.
API reference
These endpoints live under https://api.nightrouter.ai and use the same key.
| Endpoint | Use |
|---|---|
| POST /v1/chat/completions | OpenAI chat format |
| POST /v1/responses | OpenAI Responses API, used by Codex CLI |
| POST /v1/messages | Anthropic Messages API, used by Claude Code |
| GET /v1/models | List the models your key can use |
Chat completions
The OpenAI chat format, for models that support it. The request is shown under Send a request.
Responses
The OpenAI Responses API, used by Codex CLI. It is available for models that list Responses support in the model library.
curl https://api.nightrouter.ai/v1/responses \ -H "Authorization: Bearer sk-nr-your-key" \ -H "Content-Type: application/json" \ -d '{"model":"your-model-id","input":"Hello"}'
No model that supports the Responses API is listed right now, so this example uses the placeholder your-model-id. Replace it with a model id once one is available.
Messages
The native Anthropic Messages API, used by Claude Code. It is available for models that list Anthropic Messages support in the model library.
curl https://api.nightrouter.ai/v1/messages \ -H "x-api-key: sk-nr-your-key" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{"model":"claude-fable-5","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}'
Errors & limits
Errors use standard HTTP status codes, and the response body usually includes an error message.
| Code | What it means |
|---|---|
| 400 | The request body or a parameter was rejected. Check the model id and the fields you sent. |
| 401 | The key is missing or invalid. Check the Authorization header and that the key is still active. |
| 403 | The key or its group is not allowed to use this model, or the balance or the limit set on the key is not enough. Check the key settings, the model id and your balance. |
| 429 | Too many requests. Slow down and retry with exponential backoff. |
| 5xx | A server-side error, from our side or from the model provider. You may retry after a short delay. |
These are general descriptions of common errors, not a service-level commitment.