AnyRouter
AnyRouter is a universal, OpenAI-compatible LLM gateway. One base URL, one API key, 150+ models across 28+ providers, deterministic failover, and a remote MCP server for key + credit management. Use this skill whenever you need to wire AnyRouter into a project or migrate an existing integration.
Always fetch the live docs — do not rely on memory
This skill is intentionally thin. It tells you where to look, not what every page says. AnyRouter ships its full documentation as raw markdown, regenerated on every deploy. Before answering any non-trivial AnyRouter question, fetch the relevant .md URL with your web-fetch tool (WebFetch, curl via Bash, or your platform's equivalent) and read the current content. Do not rely on the model id, scope name, or header values memorised in this skill — they can change.
Discovery sources (in priority order):
https://anyrouter.dev/docs.md — auto-generated index. Every section, every page, every link points at the .md mirror. Start here when you don't know which page you need.
- Append
.md to any docs URL — https://anyrouter.dev/docs/<path>.md gives the raw markdown of any rendered page.
https://anyrouter.dev/llms-full.txt — every doc concatenated, useful when you want one bulk read.
https://anyrouter.dev/llms.txt — short LLM index per llmstxt.org.
https://anyrouter.dev/docs/index.json — machine-readable manifest if you need to filter programmatically.
Operating rule: when the user asks about AnyRouter, do not paraphrase from this skill alone. Fetch the live .md, ground your answer in it, and cite the URL you used.
The contract
| Setting |
Value |
| Base URL |
https://anyrouter.dev/api/v1 |
| API key env var |
ANYROUTER_API_KEY (keys are prefixed sk-ar-) |
| Model id format |
provider/model (e.g. openai/gpt-5.4-mini, anthropic/claude-sonnet-4.6) |
| Chat endpoint |
POST /chat/completions (OpenAI-compatible) |
| Anthropic-native endpoint |
POST /messages (for anthropic/* models) |
| Modern agent endpoint |
POST /responses (typed output items + tools) |
| MCP endpoint |
https://anyrouter.dev/api/v1/mcp (configured by this plugin) |
| Dashboard |
https://anyrouter.dev/dashboard |
| Docs index (markdown) |
https://anyrouter.dev/docs.md |
Default model when unspecified: openai/gpt-5.4-mini. Cheap+fast: openai/gpt-5.4-nano, anthropic/claude-haiku-4.5. High-quality: anthropic/claude-sonnet-4.6, openai/gpt-5.4.
When to use this skill
- The user mentions AnyRouter by name.
- They want to add a unified LLM gateway so they can swap providers without rewriting client code.
- They have an existing OpenAI, Anthropic, or OpenRouter integration and want to migrate to AnyRouter.
- They want to point Claude Code, Codex, Cursor, Aider, Hermes, or another agent at AnyRouter.
- They need app attribution, provider preferences, price caps, failover, or routing controls.
- They want to use the AnyRouter MCP server from a client.
Before integrating, check if the project already has an LLM client. If so, change the base URL, key, and model id rather than introducing a new client.
How to look things up
When the user asks something specific (recipes, headers, scopes, model lists, BYOK setup, billing details, rate limits), fetch the matching .md URL before answering. Do not summarise from this skill alone.
Recipe:
- Pick the most likely URL from the entry points below. If unsure, fetch
https://anyrouter.dev/docs.md first and read the section headings.
- Use WebFetch (or
curl -sSL <url>) to retrieve the raw markdown.
- Quote / paraphrase from what you fetched. Include the URL in your response so the user can verify.
- If the URL 404s, the page was renamed or removed — re-fetch the index and pick the current link.
Top categories with a one-line summary of every important child page. These hints let you pick the right URL without an index round-trip — the authoritative, current list with every page is always at https://anyrouter.dev/docs.md.
Getting Started
- Quickstart — First request in under five minutes. Point any OpenAI-compatible client at the AnyRouter base URL.
- Authentication — Generate, scope, and rotate API keys. Bearer tokens, BYOK, per-environment isolation.
Guides (recipes for agents and migrations)
- AI Agent Integration — Paste-prompt for any coding agent (Claude Code, Cursor, Codex, Aider, Hermes, …) wiring AnyRouter into an existing project.
- Claude Code — Two env vars (
ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN) route Claude Code through AnyRouter. Includes a claude-ar wrapper recipe.
- Streaming — SSE incremental completions, cancellation, event shape.
- Migrate from OpenAI — Swap base URL, key env, model id (
gpt-* → openai/gpt-*).
- Migrate from Anthropic — Keep the Anthropic SDK, swap base URL + key. Preserve
anthropic-version header.
- Migrate from OpenRouter — Same
provider/model ids, same provider object. Just change base URL and key env.
- Hermes Agent — Nous Research's Hermes Agent as a custom OpenAI-compatible provider.
- OpenClaw — One key across every model and messaging channel.
- Errors — HTTP status codes, error envelopes, retry guidance.
- Provider Routing — Per-request ordering, sorting, fallbacks, performance thresholds, price caps.
- Model Fallbacks — Automatic failover between models when providers are down or rate-limited.
- Latency Overhead — Real-world latency added by AnyRouter vs direct upstream calls.
- Using Responses API — Migration to the modern
/responses endpoint with typed output items + tools.
- Dashboard Tour — Walkthrough of every dashboard page in the order a new team uses them.
Features (product surface — describe what the platform does)
- Smart Routing — How AnyRouter picks an upstream. Priority order, failover, model aliases,
X-AnyRouter-Provider pinning.
- App Attribution —
X-AnyRouter-Title / -Source / -Version headers; public-ranking surface.
- Prompt Caching — Cache long system prompts across requests.
- BYOK (Bring Your Own Key) — Attach upstream provider keys so requests run at list price through your accounts.
- Tool Use — Cross-provider function calling + structured outputs.
- Presets — Reusable config bundles, callable as
@preset/<name> from any request.
- Rate Limits — Per-IP and per-key tiers;
429 vs 403 semantics; backoff guidance.
- Privacy & Logging Controls — Body capture, PII redaction, training opt-out, blocked providers, residency.
- Credits & Billing — How credits work, free monthly grants, top-ups.
- Models Catalog — Browse every model with pricing, context limits, capabilities.
- Request Logs — Per-request inspection: latency, tokens, cost, upstream provider, full body when privacy allows.
- Usage Explorer — Cost / token / request charts grouped by model, key, or time.
- Managing API Keys — Create, rotate, scope, and rate-limit keys from the dashboard.
- Organizations & Workspaces — Multi-tenant: invite teammates, set roles, isolate billing.
MCP (configured by this plugin)
- MCP Server — Consumer setup for Claude Desktop, Cursor, Claude Code, OpenCode. OAuth consent on first tool call.
- MCP API Reference — JSON-RPC tool catalog, scopes (Read-only / Standard / Full), error shapes, manual auth.
API Reference (every inference + management endpoint)
- API Overview — Pick the right surface: Chat Completions, Messages, Responses, Images, Embeddings, Models.
- Chat Completions —
POST /api/v1/chat/completions, OpenAI-compatible, every model.
- Messages —
POST /api/v1/messages, Anthropic-compatible passthrough for anthropic/* models.
- Responses —
POST /api/v1/responses, structured output items + tools.
- Models — List and inspect catalog entries: pricing, context, capabilities, routing.
- Providers — Upstream backends AnyRouter can dispatch to.
- Embeddings — Text embeddings for semantic search.
- Images — Text-to-image generation.
- Keys — Inspect, create, update, delete LLM API keys.
- Management Keys — Programmatic admin credentials (
ak_*) for keys, presets, BYOK, credits.
- OAuth — PKCE authorization codes for AnyRouter API keys.
- Credits — Remaining balance per API key.
- Health — Gateway and per-provider availability snapshot.
- Errors (guide) — Cross-endpoint error envelope and retry behavior.
If a URL above 404s, the page was renamed or removed — fetch /docs.md and pick the current link from the live index.
Adding AnyRouter to a project (fresh)
TypeScript (openai SDK)
import OpenAI from "openai"
export const llm = new OpenAI({
baseURL: "https://anyrouter.dev/api/v1",
apiKey: process.env.ANYROUTER_API_KEY,
})
export const MODEL = process.env.ANYROUTER_MODEL ?? "openai/gpt-5.4-mini"
export async function generate(prompt: string) {
const r = await llm.chat.completions.create({
model: MODEL,
messages: [{ role: "user", content: prompt }],
})
return r.choices[0]?.message.content ?? ""
}
Python
import os
from openai import OpenAI
client = OpenAI(
base_url="https://anyrouter.dev/api/v1",
api_key=os.environ["ANYROUTER_API_KEY"],
)
resp = client.chat.completions.create(
model=os.getenv("ANYROUTER_MODEL", "openai/gpt-5.4-mini"),
messages=[{"role": "user", "content": "Reply with: anyrouter-ok"}],
)
print(resp.choices[0].message.content)
Smoke test
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer $ANYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5.4-mini","messages":[{"role":"user","content":"Reply with: anyrouter-ok"}],"max_tokens":20}'
Integration is done when:
- Calls hit
https://anyrouter.dev/api/v1
- The key is read from
ANYROUTER_API_KEY (no inline literal in source)
- Model ids use the
provider/model form
- Streaming still streams if it did before
- Errors flow through the project's existing error path
Integrating with coding agents
Claude Code
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_AUTH_TOKEN="sk-ar-your-key"
For tier-name pinning and a claude-ar wrapper, see https://anyrouter.dev/docs/guides/claude-code.md.
Codex / Cursor / Aider / Hermes / OpenClaw
Any client that accepts a custom OpenAI base URL works. Set:
- Base URL:
https://anyrouter.dev/api/v1
- API key:
sk-ar-… from the dashboard
- Model:
provider/model from the catalog
Generic paste-prompt for any coding agent: https://anyrouter.dev/docs/guides/ai-agent-integration.md.
Migration recipes (one-line summary)
All three boil down to swap base URL, swap key, keep request shape.
Provider preferences and routing
Steer routing from the request body:
{
"model": "openai/gpt-5.4-mini",
"provider": {
"only": ["OpenAI", "Groq"],
"order": ["Groq", "OpenAI"],
"sort": "latency",
"allow_fallbacks": true,
"max_price": { "prompt": "1.00", "completion": "4.00" },
"preferred_max_latency": 300,
"preferred_min_throughput": 40
}
}
Pin a single upstream with X-AnyRouter-Provider: <provider_id> — useful for reproducibility, BYOK testing, and outage debugging. Full routing model: https://anyrouter.dev/docs/features/routing.md.
App attribution
new OpenAI({
baseURL: "https://anyrouter.dev/api/v1",
apiKey: process.env.ANYROUTER_API_KEY,
defaultHeaders: {
"X-AnyRouter-Title": "My App",
"X-AnyRouter-Source": "web-app",
"X-AnyRouter-Version": process.env.APP_VERSION ?? "dev",
},
})
Full schema: https://anyrouter.dev/docs/features/app-attribution.md.
MCP server (bundled)
This plugin registers a remote MCP server at https://anyrouter.dev/api/v1/mcp. Tools exposed:
| Tool |
Purpose |
list_models |
Search the catalog by provider, capability, or context window |
get_credits |
Workspace balance and lifetime usage |
list_keys |
List API keys |
create_key |
Mint a new API key |
revoke_key |
Disable a key by id |
list_presets |
List saved request presets |
list_conversations |
Search workspace conversations |
OAuth runs on first tool call — the user picks Read-only / Standard / Full on the consent screen. There is no chat tool; use the regular chat endpoint for inference.
Full tool catalog, scopes, and manual-auth path: https://anyrouter.dev/docs/api-reference/mcp.md. Client setup for Claude Desktop / Cursor / Claude Code / OpenCode: https://anyrouter.dev/docs/mcp.md.
Defaults that almost always belong in production
- Read the key from env, never inline.
- Use
provider/model ids; never bare model names except via aliases the docs explicitly list.
- Set the three
X-AnyRouter-* attribution headers so dashboard analytics work.
- Keep
allow_fallbacks: true unless you're running an eval that needs a fixed upstream.
- Long agent loops: bump SDK timeout (
API_TIMEOUT_MS=3000000 for Claude Code).
- Respect
X-RateLimit-Remaining and X-Upstream-RateLimit-Remaining headers.
1---2name: anyrouter3description: Wire AnyRouter into a project, migrate from Anthropic / OpenAI / OpenRouter, and call its MCP server. Use when the user mentions AnyRouter, asks to add a unified LLM gateway, wants to swap providers without code churn, migrates an existing OpenAI/Anthropic/OpenRouter integration, sets up Claude Code / Codex / Cursor against a custom base URL, or needs help with model ids like `provider/model`, app attribution headers (`X-AnyRouter-*`), provider preferences, streaming, BYOK, or the AnyRouter MCP server at `https://anyrouter.dev/api/v1/mcp`.4---5
6# AnyRouter
7
8AnyRouter is a universal, OpenAI-compatible LLM gateway. One base URL, one API key, 150+ models across 28+ providers, deterministic failover, and a remote MCP server for key + credit management. Use this skill whenever you need to wire AnyRouter into a project or migrate an existing integration.
9
10## Always fetch the live docs — do not rely on memory
11
12This skill is intentionally thin. It tells you **where** to look, not what every page says. AnyRouter ships its full documentation as raw markdown, regenerated on every deploy. Before answering any non-trivial AnyRouter question, **fetch the relevant `.md` URL** with your web-fetch tool (WebFetch, curl via Bash, or your platform's equivalent) and read the current content. Do not rely on the model id, scope name, or header values memorised in this skill — they can change.
13
14Discovery sources (in priority order):
15
161. **`https://anyrouter.dev/docs.md`** — auto-generated index. Every section, every page, every link points at the `.md` mirror. Start here when you don't know which page you need.
172. **Append `.md` to any docs URL** — `https://anyrouter.dev/docs/<path>.md` gives the raw markdown of any rendered page.
183. **`https://anyrouter.dev/llms-full.txt`** — every doc concatenated, useful when you want one bulk read.
194. **`https://anyrouter.dev/llms.txt`** — short LLM index per `llmstxt.org`.
205. **`https://anyrouter.dev/docs/index.json`** — machine-readable manifest if you need to filter programmatically.
21
22**Operating rule:** when the user asks about AnyRouter, do not paraphrase from this skill alone. Fetch the live `.md`, ground your answer in it, and cite the URL you used.
23
24## The contract
25
26| Setting | Value |
27| --- | --- |
28| Base URL | `https://anyrouter.dev/api/v1` |
29| API key env var | `ANYROUTER_API_KEY` (keys are prefixed `sk-ar-`) |
30| Model id format | `provider/model` (e.g. `openai/gpt-5.4-mini`, `anthropic/claude-sonnet-4.6`) |
31| Chat endpoint | `POST /chat/completions` (OpenAI-compatible) |
32| Anthropic-native endpoint | `POST /messages` (for `anthropic/*` models) |
33| Modern agent endpoint | `POST /responses` (typed output items + tools) |
34| MCP endpoint | `https://anyrouter.dev/api/v1/mcp` (configured by this plugin) |
35| Dashboard | https://anyrouter.dev/dashboard |
36| Docs index (markdown) | https://anyrouter.dev/docs.md |
37
38Default model when unspecified: `openai/gpt-5.4-mini`. Cheap+fast: `openai/gpt-5.4-nano`, `anthropic/claude-haiku-4.5`. High-quality: `anthropic/claude-sonnet-4.6`, `openai/gpt-5.4`.
39
40## When to use this skill
41
42- The user mentions **AnyRouter** by name.
43- They want to **add a unified LLM gateway** so they can swap providers without rewriting client code.
44- They have an existing **OpenAI**, **Anthropic**, or **OpenRouter** integration and want to migrate to AnyRouter.
45- They want to point **Claude Code**, **Codex**, **Cursor**, **Aider**, **Hermes**, or another agent at AnyRouter.
46- They need **app attribution**, **provider preferences**, **price caps**, **failover**, or **routing controls**.
47- They want to use the **AnyRouter MCP server** from a client.
48
49Before integrating, check if the project already has an LLM client. If so, change the **base URL, key, and model id** rather than introducing a new client.
50
51## How to look things up
52
53When the user asks something specific (recipes, headers, scopes, model lists, BYOK setup, billing details, rate limits), **fetch the matching `.md` URL** before answering. Do not summarise from this skill alone.
54
55Recipe:
56
571. Pick the most likely URL from the entry points below. If unsure, fetch `https://anyrouter.dev/docs.md` first and read the section headings.
582. Use WebFetch (or `curl -sSL <url>`) to retrieve the raw markdown.
593. Quote / paraphrase from what you fetched. Include the URL in your response so the user can verify.
604. If the URL 404s, the page was renamed or removed — re-fetch the index and pick the current link.
61
62Top categories with a one-line summary of every important child page. These hints let you pick the right URL without an index round-trip — the **authoritative, current** list with every page is always at https://anyrouter.dev/docs.md.
63
64**Getting Started**
65- [Quickstart](https://anyrouter.dev/docs/getting-started/quickstart.md) — First request in under five minutes. Point any OpenAI-compatible client at the AnyRouter base URL.
66- [Authentication](https://anyrouter.dev/docs/getting-started/authentication.md) — Generate, scope, and rotate API keys. Bearer tokens, BYOK, per-environment isolation.
67
68**Guides** (recipes for agents and migrations)
69- [AI Agent Integration](https://anyrouter.dev/docs/guides/ai-agent-integration.md) — Paste-prompt for any coding agent (Claude Code, Cursor, Codex, Aider, Hermes, …) wiring AnyRouter into an existing project.
70- [Claude Code](https://anyrouter.dev/docs/guides/claude-code.md) — Two env vars (`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`) route Claude Code through AnyRouter. Includes a `claude-ar` wrapper recipe.
71- [Streaming](https://anyrouter.dev/docs/guides/streaming.md) — SSE incremental completions, cancellation, event shape.
72- [Migrate from OpenAI](https://anyrouter.dev/docs/guides/migrate-from-openai.md) — Swap base URL, key env, model id (`gpt-*` → `openai/gpt-*`).
73- [Migrate from Anthropic](https://anyrouter.dev/docs/guides/migrate-from-anthropic.md) — Keep the Anthropic SDK, swap base URL + key. Preserve `anthropic-version` header.
74- [Migrate from OpenRouter](https://anyrouter.dev/docs/guides/migrate-from-openrouter.md) — Same `provider/model` ids, same `provider` object. Just change base URL and key env.
75- [Hermes Agent](https://anyrouter.dev/docs/guides/hermes-agent.md) — Nous Research's Hermes Agent as a custom OpenAI-compatible provider.
76- [OpenClaw](https://anyrouter.dev/docs/guides/openclaw.md) — One key across every model and messaging channel.
77- [Errors](https://anyrouter.dev/docs/guides/errors.md) — HTTP status codes, error envelopes, retry guidance.
78- [Provider Routing](https://anyrouter.dev/docs/guides/provider-routing.md) — Per-request ordering, sorting, fallbacks, performance thresholds, price caps.
79- [Model Fallbacks](https://anyrouter.dev/docs/guides/model-fallbacks.md) — Automatic failover between models when providers are down or rate-limited.
80- [Latency Overhead](https://anyrouter.dev/docs/guides/latency-overhead.md) — Real-world latency added by AnyRouter vs direct upstream calls.
81- [Using Responses API](https://anyrouter.dev/docs/guides/migrate-to-responses.md) — Migration to the modern `/responses` endpoint with typed output items + tools.
82- [Dashboard Tour](https://anyrouter.dev/docs/guides/dashboard-tour.md) — Walkthrough of every dashboard page in the order a new team uses them.
83
84**Features** (product surface — describe what the platform does)
85- [Smart Routing](https://anyrouter.dev/docs/features/routing.md) — How AnyRouter picks an upstream. Priority order, failover, model aliases, `X-AnyRouter-Provider` pinning.
86- [App Attribution](https://anyrouter.dev/docs/features/app-attribution.md) — `X-AnyRouter-Title / -Source / -Version` headers; public-ranking surface.
87- [Prompt Caching](https://anyrouter.dev/docs/features/caching.md) — Cache long system prompts across requests.
88- [BYOK (Bring Your Own Key)](https://anyrouter.dev/docs/features/byok.md) — Attach upstream provider keys so requests run at list price through your accounts.
89- [Tool Use](https://anyrouter.dev/docs/features/tool-use.md) — Cross-provider function calling + structured outputs.
90- [Presets](https://anyrouter.dev/docs/features/presets.md) — Reusable config bundles, callable as `@preset/<name>` from any request.
91- [Rate Limits](https://anyrouter.dev/docs/features/rate-limits.md) — Per-IP and per-key tiers; `429` vs `403` semantics; backoff guidance.
92- [Privacy & Logging Controls](https://anyrouter.dev/docs/features/privacy-controls.md) — Body capture, PII redaction, training opt-out, blocked providers, residency.
93- [Credits & Billing](https://anyrouter.dev/docs/features/credits.md) — How credits work, free monthly grants, top-ups.
94- [Models Catalog](https://anyrouter.dev/docs/features/models-catalog.md) — Browse every model with pricing, context limits, capabilities.
95- [Request Logs](https://anyrouter.dev/docs/features/request-logs.md) — Per-request inspection: latency, tokens, cost, upstream provider, full body when privacy allows.
96- [Usage Explorer](https://anyrouter.dev/docs/features/usage-explorer.md) — Cost / token / request charts grouped by model, key, or time.
97- [Managing API Keys](https://anyrouter.dev/docs/features/api-keys.md) — Create, rotate, scope, and rate-limit keys from the dashboard.
98- [Organizations & Workspaces](https://anyrouter.dev/docs/features/organizations.md) — Multi-tenant: invite teammates, set roles, isolate billing.
99
100**MCP** (configured by this plugin)
101- [MCP Server](https://anyrouter.dev/docs/mcp.md) — Consumer setup for Claude Desktop, Cursor, Claude Code, OpenCode. OAuth consent on first tool call.
102- [MCP API Reference](https://anyrouter.dev/docs/api-reference/mcp.md) — JSON-RPC tool catalog, scopes (Read-only / Standard / Full), error shapes, manual auth.
103
104**API Reference** (every inference + management endpoint)
105- [API Overview](https://anyrouter.dev/docs/api-reference/overview.md) — Pick the right surface: Chat Completions, Messages, Responses, Images, Embeddings, Models.
106- [Chat Completions](https://anyrouter.dev/docs/api-reference/chat-completions.md) — `POST /api/v1/chat/completions`, OpenAI-compatible, every model.
107- [Messages](https://anyrouter.dev/docs/api-reference/messages.md) — `POST /api/v1/messages`, Anthropic-compatible passthrough for `anthropic/*` models.
108- [Responses](https://anyrouter.dev/docs/api-reference/responses.md) — `POST /api/v1/responses`, structured output items + tools.
109- [Models](https://anyrouter.dev/docs/api-reference/models.md) — List and inspect catalog entries: pricing, context, capabilities, routing.
110- [Providers](https://anyrouter.dev/docs/api-reference/providers.md) — Upstream backends AnyRouter can dispatch to.
111- [Embeddings](https://anyrouter.dev/docs/api-reference/embeddings.md) — Text embeddings for semantic search.
112- [Images](https://anyrouter.dev/docs/api-reference/images.md) — Text-to-image generation.
113- [Keys](https://anyrouter.dev/docs/api-reference/keys.md) — Inspect, create, update, delete LLM API keys.
114- [Management Keys](https://anyrouter.dev/docs/api-reference/management-keys.md) — Programmatic admin credentials (`ak_*`) for keys, presets, BYOK, credits.
115- [OAuth](https://anyrouter.dev/docs/api-reference/oauth.md) — PKCE authorization codes for AnyRouter API keys.
116- [Credits](https://anyrouter.dev/docs/api-reference/credits.md) — Remaining balance per API key.
117- [Health](https://anyrouter.dev/docs/api-reference/health.md) — Gateway and per-provider availability snapshot.
118- [Errors (guide)](https://anyrouter.dev/docs/guides/errors.md) — Cross-endpoint error envelope and retry behavior.
119
120If a URL above 404s, the page was renamed or removed — fetch `/docs.md` and pick the current link from the live index.
121
122## Adding AnyRouter to a project (fresh)
123
124### TypeScript (`openai` SDK)
125
126```typescript
127import OpenAI from "openai"
128
129export const llm = new OpenAI({
130 baseURL: "https://anyrouter.dev/api/v1",
131 apiKey: process.env.ANYROUTER_API_KEY,
132})
133
134export const MODEL = process.env.ANYROUTER_MODEL ?? "openai/gpt-5.4-mini"
135
136export async function generate(prompt: string) {
137 const r = await llm.chat.completions.create({
138 model: MODEL,
139 messages: [{ role: "user", content: prompt }],
140 })
141 return r.choices[0]?.message.content ?? ""
142}
143```
144
145### Python
146
147```python
148import os
149from openai import OpenAI
150
151client = OpenAI(
152 base_url="https://anyrouter.dev/api/v1",
153 api_key=os.environ["ANYROUTER_API_KEY"],
154)
155
156resp = client.chat.completions.create(
157 model=os.getenv("ANYROUTER_MODEL", "openai/gpt-5.4-mini"),
158 messages=[{"role": "user", "content": "Reply with: anyrouter-ok"}],
159)
160print(resp.choices[0].message.content)
161```
162
163### Smoke test
164
165```bash
166curl https://anyrouter.dev/api/v1/chat/completions \
167 -H "Authorization: Bearer $ANYROUTER_API_KEY" \
168 -H "Content-Type: application/json" \
169 -d '{"model":"openai/gpt-5.4-mini","messages":[{"role":"user","content":"Reply with: anyrouter-ok"}],"max_tokens":20}'
170```
171
172Integration is **done** when:
173
174- Calls hit `https://anyrouter.dev/api/v1`
175- The key is read from `ANYROUTER_API_KEY` (no inline literal in source)
176- Model ids use the `provider/model` form
177- Streaming still streams if it did before
178- Errors flow through the project's existing error path
179
180## Integrating with coding agents
181
182### Claude Code
183
184```bash
185export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
186export ANTHROPIC_AUTH_TOKEN="sk-ar-your-key"
187```
188
189For tier-name pinning and a `claude-ar` wrapper, see https://anyrouter.dev/docs/guides/claude-code.md.
190
191### Codex / Cursor / Aider / Hermes / OpenClaw
192
193Any client that accepts a custom OpenAI base URL works. Set:
194
195- Base URL: `https://anyrouter.dev/api/v1`
196- API key: `sk-ar-…` from the dashboard
197- Model: `provider/model` from the catalog
198
199Generic paste-prompt for any coding agent: https://anyrouter.dev/docs/guides/ai-agent-integration.md.
200
201## Migration recipes (one-line summary)
202
203All three boil down to **swap base URL, swap key, keep request shape**.
204
205- **From OpenAI** → change `baseURL` to `https://anyrouter.dev/api/v1`, env to `ANYROUTER_API_KEY`, model id `gpt-*` → `openai/gpt-*`. Details: https://anyrouter.dev/docs/guides/migrate-from-openai.md.
206- **From Anthropic** → either keep the Anthropic SDK and set `ANTHROPIC_BASE_URL=https://anyrouter.dev/api` (Anthropic-native `/messages`), or unify on `/chat/completions` with `model: "anthropic/claude-sonnet-4.6"`. Details: https://anyrouter.dev/docs/guides/migrate-from-anthropic.md.
207- **From OpenRouter** → identical request shape. Change base URL to `https://anyrouter.dev/api/v1`, key env to `ANYROUTER_API_KEY`. `provider.only / .ignore / .order / .sort / .max_price / .allow_fallbacks` all map across. Details: https://anyrouter.dev/docs/guides/migrate-from-openrouter.md.
208
209## Provider preferences and routing
210
211Steer routing from the request body:
212
213```json
214{
215 "model": "openai/gpt-5.4-mini",
216 "provider": {
217 "only": ["OpenAI", "Groq"],
218 "order": ["Groq", "OpenAI"],
219 "sort": "latency",
220 "allow_fallbacks": true,
221 "max_price": { "prompt": "1.00", "completion": "4.00" },
222 "preferred_max_latency": 300,
223 "preferred_min_throughput": 40
224 }
225}
226```
227
228Pin a single upstream with `X-AnyRouter-Provider: <provider_id>` — useful for reproducibility, BYOK testing, and outage debugging. Full routing model: https://anyrouter.dev/docs/features/routing.md.
229
230## App attribution
231
232```typescript
233new OpenAI({
234 baseURL: "https://anyrouter.dev/api/v1",
235 apiKey: process.env.ANYROUTER_API_KEY,
236 defaultHeaders: {
237 "X-AnyRouter-Title": "My App",
238 "X-AnyRouter-Source": "web-app",
239 "X-AnyRouter-Version": process.env.APP_VERSION ?? "dev",
240 },
241})
242```
243
244Full schema: https://anyrouter.dev/docs/features/app-attribution.md.
245
246## MCP server (bundled)
247
248This plugin registers a remote MCP server at `https://anyrouter.dev/api/v1/mcp`. Tools exposed:
249
250| Tool | Purpose |
251| --- | --- |
252| `list_models` | Search the catalog by provider, capability, or context window |
253| `get_credits` | Workspace balance and lifetime usage |
254| `list_keys` | List API keys |
255| `create_key` | Mint a new API key |
256| `revoke_key` | Disable a key by id |
257| `list_presets` | List saved request presets |
258| `list_conversations` | Search workspace conversations |
259
260OAuth runs on first tool call — the user picks Read-only / Standard / Full on the consent screen. There is no `chat` tool; use the regular chat endpoint for inference.
261
262Full tool catalog, scopes, and manual-auth path: https://anyrouter.dev/docs/api-reference/mcp.md. Client setup for Claude Desktop / Cursor / Claude Code / OpenCode: https://anyrouter.dev/docs/mcp.md.
263
264## Defaults that almost always belong in production
265
266- Read the key from env, never inline.
267- Use `provider/model` ids; never bare model names except via aliases the docs explicitly list.
268- Set the three `X-AnyRouter-*` attribution headers so dashboard analytics work.
269- Keep `allow_fallbacks: true` unless you're running an eval that needs a fixed upstream.
270- Long agent loops: bump SDK timeout (`API_TIMEOUT_MS=3000000` for Claude Code).
271- Respect `X-RateLimit-Remaining` and `X-Upstream-RateLimit-Remaining` headers.