Migrate from the OpenAI API
Keep the OpenAI SDK, change the base URL and the key, and every model on ai.ml is available through /v1/chat/completions with the same streaming and tool calls.
Before
from openai import OpenAI
client = OpenAI(api_key="sk-…")
client.chat.completions.create(model="gpt-5-mini", messages=msgs, stream=True)After
from openai import OpenAI
client = OpenAI(base_url="https://api.ai.ml/v1", api_key="aiml-live-…")
client.chat.completions.create(model="openai/gpt-5-mini", messages=msgs, stream=True)Headers
| OpenAI | ai.ml |
|---|---|
| Authorization: Bearer sk-… | Authorization: Bearer aiml-live-… |
| OpenAI-Organization | not needed (the key belongs to an org and project) |
| x-aiml-route (optional) | override the routing policy for one request |
| x-aiml-idempotency-key (optional) | replay-safe retries |
What changes, what does not
- Model ids carry the vendor: openai/gpt-5-mini, anthropic/claude-sonnet-4.5, deepseek/deepseek-v3.2. Bare OpenAI names still resolve to the OpenAI vendor.
- Responses carry an aiml block with the cost lines, the endpoint that served the request and any capability warnings (a parameter dropped for a provider that lacks it).
- Structured outputs, tools, vision and prompt caching work where the provider supports them; the model page lists what each endpoint can do.
- Budget headers: x-aiml-required-micro on a 402, x-aiml-limit on a 429, retry-after when the provider had no capacity.