Migrate from Anthropic
Point Anthropic Messages clients at AnyRouter by changing the base URL and key. Keep the anthropic-version header.
Repoint an Anthropic Messages client at AnyRouter. Request bodies keep the native Anthropic shape.
The SDK appends /v1/messages, so the base URL must stop at /api, not /api/v1. Otherwise you get a 404 on /api/v1/v1/messages.
What changes
| Setting | Before | After |
|---|---|---|
| Base URL | https://api.anthropic.com | https://anyrouter.dev/api |
| API key | ANTHROPIC_API_KEY | AnyRouter key (sk-ar-...) from the dashboard, sent as x-api-key |
anthropic-version | 2023-06-01 | Same. Required. |
| Model | claude-sonnet-4-5 | anthropic/claude-sonnet-4-6 or any anthropic/* id (claude-haiku becomes anthropic/claude-haiku-4-5) |
typescript
import Anthropic from "@anthropic-ai/sdk"
const client = new Anthropic({
baseURL: "https://anyrouter.dev/api",
apiKey: process.env.ANYROUTER_API_KEY,
})
const message = await client.messages.create({
model: "anthropic/claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Review this incident summary." }],
})Verify
bash
curl https://anyrouter.dev/api/v1/messages \
-H "x-api-key: sk-ar-your-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model": "anthropic/claude-haiku-4-5", "max_tokens": 512,
"messages": [{"role": "user", "content": "Say hello."}]}'For cross-provider routing, use Chat Completions or Responses instead.
Troubleshooting
| Symptom | Fix |
|---|---|
| 404 on every request | Set baseURL to https://anyrouter.dev/api, not /api/v1. |
| 401 Unauthorized | Send the sk-ar- key as x-api-key and include anthropic-version. |
AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer