Set the OpenAI base_url to https://api.toapis.com/v1. Keep the /v1 suffix and your existing SDK version so request bodies stay untouched.
5-Minute Migration to One OpenAI-Compatible Gateway
ToAPIs keeps the OpenAI request shape, so migration is a configuration change rather than a rewrite: swap the endpoint, issue a key, map your model names, then tune retries. This page is the reference for that path, and for routing, billing, and error handling afterwards.
Quickstart
Four steps take an existing OpenAI SDK client onto the gateway. Keep your SDK version, your request bodies, and your streaming handlers.
https://api.toapis.com/v1Create a key in the console, store it as an environment variable, and send it as a Bearer token in the Authorization header.
Replace the model id with the ToAPIs model name from the catalog. Text, image, and video models all sit behind the same host.
Add exponential backoff with jitter for 429 and 5xx responses, and pin a request timeout per workload class.
from openai import OpenAIclient = OpenAI(base_url="https://api.toapis.com/v1",api_key="your-toapis-key")response = client.chat.completions.create(model="gpt-5.6-terra",messages=[{"role": "user", "content": "Hello!"}])
Keys and Access
One key covers every model on the gateway. Scope a key per environment instead of sharing a single key across development and production.
- Create a key in the console for the environment it serves (development, staging, production).
- Store it in your secret manager or environment file, never in client-side code.
- Send it on every request as Authorization: Bearer <key>.
- Rotate the key from the console if it leaks; a replacement key works without a redeploy.
Routing, Failover, and Fallback
Route pools keep one logical call working when a provider degrades. Choose the pool by task, then name a primary and a fallback for each pool.
Chat, image, and video models are addressed through the same host and the same Authorization header, so a single client reaches all of them.
Name a primary model and at least one fallback per workload, so a retryable error or a rate limit on the primary does not end the user request.
Retry 429 and 5xx with exponential backoff, then move to the fallback model instead of surfacing the failure.
Send high-priority traffic to the quality tier and batch or low-priority traffic to the lower-cost tier, then reconcile consumption against the quotas on the pricing page.
Keep a fallback inside the same capability class as its primary. Swapping across classes changes output shape and quality mid-conversation.
Billing and Credits
One account, one credit balance, and one invoice across every model family on the gateway.
- Text models are metered by token, image models per request, and video models by duration; the billing unit is stated next to each model.
- Credits are consumed while requests are served, so you are not billed for output that was never produced.
- Monthly and annual plans include a credit allowance for the billing period; unused subscription credits expire with that period.
- Consumption, invoices, and payment methods live under Settings, in Billing.
Error Reference
The gateway keeps OpenAI error codes, so existing error handling keeps working.
| 401 | Invalid key | Confirm the key exists, is not revoked, and is sent as Authorization: Bearer <key>. |
| 402 / 403 | No credit or no permission | Confirm the account has an active plan or a usable credit balance, then retry the request. |
| 404 | Unknown model | Use a model id from the catalog verbatim. Ids that only exist at a single provider are not routable here. |
| 429 | Rate limit | Back off exponentially with jitter, lower concurrency, or shift traffic to the fallback model. |
| 5xx | Upstream failure | Retry with backoff. If it persists, switch the pool to its fallback and send the model id to support. |
Next Steps
Shortlist a model, confirm what it costs, then read the plan rules that apply to your account.
Ready to point one endpoint at 50+ models?
Change the endpoint, issue a key, then confirm cost and default routing on the pricing page.