Migrate
From OpenRouter
Same model naming, same OpenAI-compatible route, different headers and billing.
OpenRouter users have the shortest path: model ids are already vendor/model and the route is already /v1/chat/completions.
The changes
- Base URL
https://openrouter.ai/api/v1becomeshttps://api.ai.ml/v1. - Key
sk-or-…becomesaiml-live-…. - Headers
HTTP-RefererandX-Titleare not needed. Put the app name inaiml.metadata.appif you want it in analytics.
from openai import OpenAI
client = OpenAI(base_url=os.environ.get("AIML_BASE_URL", "https://api.ai.ml") + "/v1", api_key=os.environ["AIML_API_KEY"])Mapping OpenRouter features
| OpenRouter | aiml |
|---|---|
provider: { order: [...], allow_fallbacks } | aiml.route.providers.order and aiml.route.fallbacks |
provider: { only: [...], ignore: [...] } | aiml.route.providers.only, aiml.route.providers.ignore |
provider: { data_collection: "deny" } | aiml.route.require.zdr: true (or data_policy: "no_train") |
provider: { sort: "price" } | aiml.route.sort |
provider: { max_price } | aiml.route.require.max_price |
models: [...] (model fallbacks) | one model per request; aiml.route.fallbacks moves between endpoints of that model |
transforms: ["middle-out"] | not offered; the gateway returns context_length_exceeded rather than silently truncating |
GET /api/v1/generation?id= | GET /v1/generation/{id} (the id is x-aiml-request-id) |
GET /api/v1/models | GET /v1/models; per-model endpoints at GET /v1/models/{vendor}/{model}/endpoints |
x-openrouter-* headers | x-aiml-* headers, see curl quick start |
Billing differences
- Prices are shown per million tokens in the catalog and billed as integer nano-USD per token; each usage line is rounded once.
aiml.cost.linesin the response breaks the total down. - The balance is reserved before the call from your estimate and settled from the provider's usage; you never see a charge larger than the settled cost.
- Top-ups are in your billing currency (INR via Razorpay with GST invoices, otherwise USD via Stripe); credits are always USD. See Billing.