Migration
Migrating from OpenAI
Move OpenAI API traffic to TokenRouter with a base URL swap.
Migration is two lines: change the base URL and swap your OpenAI key for a tr_ key. Everything else — request shapes, streaming, tools, SDK types — stays the same.
The change
from openai import OpenAI
client = OpenAI(
- api_key=os.environ["OPENAI_API_KEY"],
+ api_key=os.environ["TOKENROUTER_API_KEY"], # tr_...
+ base_url="https://api.tokenrouter.io/v1",
)Model names keep working: gpt-5-mini resolves as a bare alias, or use the explicit openai/gpt-5-mini. Add a provider key for OpenAI in the console first — TokenRouter forwards requests on your key, with zero markup.
What carries over
/v1/chat/completionswith streaming,stream_options.include_usage, tool calling, JSON mode, and vision inputs./v1/responses— stateless subset./v1/embeddings— passthrough to OpenAI embedding models./v1/models— now lists every model across your providers.
Not supported
Routes outside the gateway’s scope are not proxied: fine-tuning, Assistants, Files, Batches, and Uploads. Keep calling api.openai.com directly for those workflows; point your inference traffic at TokenRouter.
The upside
Once traffic flows through the gateway, you can put hard-cap budgets on every team, restrict models per environment, and swap in any of the other 12 providers — or auto — without touching application code again.