Migrate from OpenRouter
Move OpenRouter Chat Completions calls to AnonRouter. Set your base URL and API key, choose a model, and review routing and request differences.
You can keep the OpenAI Python or TypeScript SDK for Chat Completions. Point it at AnonRouter, use an AnonRouter inference key, and confirm that your model ID and request options are supported. Migrate one call before switching production traffic.
1. Set up your key and model
- Create an inference API key with OpenAI-compatible access enabled and
store it in the server-side environment variable
ANONROUTER_API_KEY. - Pick a callable chat model from the model catalog
and set
ANONROUTER_MODELto its exact API ID. Model names can overlap across services, but availability and capabilities vary by provider route. - Set the SDK base URL to
https://api.anonrouter.ai/v1. Remove any old provider-specific default headers and routing options for the first test.
You can look up callable text model IDs without sending a key:
curl -fsS https://control.anonrouter.ai/v1/catalog/models |
jq -r '.models[] | select(.callable == true and .primaryModality == "text") | .id'Compatibility mode accepts a static bearer key. The compatibility broker handles key identity and request content together in memory. Use the private ticket flow when you need those kept separate. The ticket flow requires a separate authorization request.
2. Send a chat completion
Run the examples on a trusted server with the OpenAI SDK installed and both environment variables set. The examples can use your balance. Automatic retries are disabled because a disconnect can occur after a paid generation.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.anonrouter.ai/v1",
api_key=os.environ["ANONROUTER_API_KEY"],
max_retries=0,
)
completion = client.chat.completions.create(
model=os.environ["ANONROUTER_MODEL"],
max_completion_tokens=256,
messages=[{"role": "user", "content": "Hello"}],
)
print(completion.choices[0].message.content)With the same authenticated client, use client.models.list() for model
discovery. Read each entry’s provider_routes when choosing a specific
provider. Top-level capabilities describe the primary route.
3. Review request and routing differences
| If your app uses | What to check on AnonRouter |
|---|---|
| Automatic model selection | Use /auto and review your routing policy. Use an exact model ID when you need predictable model selection. |
| Provider filters, sorting, or fallbacks | Rebuild the provider object using AnonRouter’s supported keys, values, and provider slugs. Unknown keys in that object are rejected. See provider routing. |
| Cross-model fallbacks | Keep the primary ID in model. Compatibility mode accepts up to four exact fallback IDs in models. See model fallbacks. |
provider.data_collection | Review each route’s privacy label and choose a provider.minimum_privacy floor if needed. A privacy tier does not translate directly from the old flag. |
| Model suffixes | Review the supported suffixes. Free routes require account opt-in and explicit consent to Anonymous routing. See free models. |
max_tokens | Use max_completion_tokens or keep max_tokens. If you send both, their values must match. |
| Tools, structured output, or image inputs | Check the selected route’s capabilities. Use tools instead of legacy functions. JSON Schema enforcement depends on the provider. See compatibility restrictions. |
| Reasoning options | Use supported effort values for the chosen model. See reasoning controls for valid fields and disable behavior. |
| Plugins or web search | Use the AnonRouter web search tool where supported. Unsupported top-level chat fields can be silently dropped. |
Model fallbacks
Compatibility mode tries the primary model first. It can try the next ID
in models after an eligible failure before any output, such as no available
route or a rate limit. It does not switch models after output starts or retry
invalid credentials with a different model. Set a privacy floor if every
candidate must meet the same minimum. See provider routing
for fallback between providers of one model.
4. Test the rest of your app
- If you stream, test stream completion and interruption. Treat a stream that
ends without
[DONE]as incomplete. Review ambiguous failures before retrying to avoid a second charge. - If you use embeddings, choose a callable embedding model and test
client.embeddings.create(...)separately. - Image generation and speech require the Studio flow. The static-key Chat Completions setup does not enable those endpoints.
- The Responses API and single-model retrieval are unavailable on this
endpoint. Use Chat Completions and
client.models.list(). - Keep SDK error handling, but check the HTTP status and AnonRouter’s
error.codebefore branching on a provider-specific error.
See the API reference for endpoint details and compatibility mode for authentication and request restrictions.