# Migrate from OpenRouter

> Move OpenRouter Chat Completions requests to AnyRouter. Provider preferences carry over unchanged.


# Migrate from OpenRouter

Change the base URL and key. Model ids keep the `provider/model` form, and request-level `provider` preferences (`only`, `ignore`, `order`, `sort`, `max_price`, `allow_fallbacks`) work unchanged. Your `HTTP-Referer` and `X-Title` headers can stay; AnyRouter reads both for dashboard attribution.

## What changes

| Setting | Before | After |
|---|---|---|
| Base URL | `https://openrouter.ai/api/v1` | `https://anyrouter.dev/api/v1` |
| API key | OpenRouter key | AnyRouter key (`sk-ar-...`) from the [dashboard](https://anyrouter.dev/dashboard/keys) |
| Model | `provider/model` | Same, but confirm each id is in [Models](/api-reference/models); some differ |

```typescript
import OpenAI from "openai"

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

const completion = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4-6",
  messages: [{ role: "user", content: "Summarize this support thread." }],
})
```

## Provider preferences

```json
{
  "provider": {
    "only": ["OpenAI", "Groq"],
    "order": ["Groq", "OpenAI"],
    "sort": "latency",
    "max_price": { "prompt": "1.00", "completion": "4.00" },
    "allow_fallbacks": true
  }
}
```

- `max_price` is in dollars per 1M tokens and is a hard filter: if every route is filtered out, the request fails.
- Fallbacks are on by default. Set `"allow_fallbacks": false` when you need a fixed upstream, for example in an eval run.

All fields: [Provider Routing](/guides/provider-routing).

## OAuth PKCE

The OpenRouter OAuth PKCE flow works too. Swap `openrouter.ai` for `anyrouter.dev` in the `/auth` URL and the `/api/v1/auth/keys` exchange. See [OAuth PKCE](/guides/oauth-pkce).

## Verify

```bash
curl https://anyrouter.dev/api/v1/chat/completions \
  -H "Authorization: Bearer sk-ar-your-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "anthropic/claude-sonnet-4-6", "messages": [{"role": "user", "content": "Say hello."}]}'
```

## Troubleshooting

| Symptom | Fix |
|---|---|
| Model id returns 404 | List [Models](/api-reference/models) and use the matching AnyRouter id. |
| Request fails with a price cap set | `max_price` is a hard filter. Raise the cap; no route fits under it. |


## Related

- [Smart Routing](/docs/features/routing.md)
- [Provider Routing](/docs/guides/provider-routing.md)
- [Models API](/docs/api-reference/models.md)
- [AnyRouter vs OpenRouter](/docs/guides/anyrouter-vs-openrouter.md)
- [OAuth PKCE](/docs/guides/oauth-pkce.md)
