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

SettingBeforeAfter
Base URLhttps://api.anthropic.comhttps://anyrouter.dev/api
API keyANTHROPIC_API_KEYAnyRouter key (sk-ar-...) from the dashboard, sent as x-api-key
anthropic-version2023-06-01Same. Required.
Modelclaude-sonnet-4-5anthropic/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

SymptomFix
404 on every requestSet baseURL to https://anyrouter.dev/api, not /api/v1.
401 UnauthorizedSend 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