OpenAI SDK
The OpenAI SDK works with the gateway once its base URL is changed. It reaches every model in the catalogue: text models through Chat Completions, and the image, voice and embeddings models through their own calls.
Install
Section titled “Install”pip install openainpm install openaiPoint the client at the gateway
Section titled “Point the client at the gateway”Two things change: the base URL, which ends in /v1, and the key.
import osfrom openai import OpenAI
client = OpenAI( base_url="https://api.exoticrouter.com/v1", api_key=os.environ["EXOTIC_API_KEY"],)
reply = client.chat.completions.create( model="anthropic/claude-sonnet-5-5", messages=[{"role": "user", "content": "Say hello in five words."}],)print(reply.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.exoticrouter.com/v1", apiKey: process.env.EXOTIC_API_KEY,});
const reply = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5-5", messages: [{ role: "user", content: "Say hello in five words." }],});console.log(reply.choices[0].message.content);AsyncOpenAI takes the same two arguments.
Or set it in the environment
Section titled “Or set it in the environment”The SDK reads its base URL and key from two variables, so code that makes a plain OpenAI() needs no change at all. Many tools built on the SDK read the same two.
export OPENAI_BASE_URL="https://api.exoticrouter.com/v1"export OPENAI_API_KEY="sk-er-..."$env:OPENAI_BASE_URL = "https://api.exoticrouter.com/v1"$env:OPENAI_API_KEY = "sk-er-..."What you can call
Section titled “What you can call”| SDK call | Models | Page |
|---|---|---|
client.chat.completions.create |
Every text model | Chat Completions |
client.responses.create |
Every text model | Responses |
client.embeddings.create |
Embeddings models | Embeddings |
client.images.generate, client.images.edit |
Image models | Images |
client.audio.speech.create |
Speech models | Audio |
client.audio.transcriptions.create |
Transcription models | Audio |
client.models.list, client.models.retrieve |
The live catalogue | Models and ids |
The calls that keep things on OpenAI’s side are not served: files, batches, moderations, fine-tuning, assistants, realtime sessions, and fetching a stored response.
Any model, by its id
Section titled “Any model, by its id”model takes any id from the catalogue, whatever lab made the model. The same client talks to all of them:
for model in ["anthropic/claude-sonnet-5-5", "openai/gpt-6.2-astra", "google/gemini-4-neon", "deepseek/deepseek-v4-pro"]: reply = client.chat.completions.create( model=model, messages=[{"role": "user", "content": "Name yourself in three words."}], ) print(model, "->", reply.choices[0].message.content)for (const model of ["anthropic/claude-sonnet-5-5", "openai/gpt-6.2-astra", "google/gemini-4-neon", "deepseek/deepseek-v4-pro"]) { const reply = await client.chat.completions.create({ model, messages: [{ role: "user", content: "Name yourself in three words." }], }); console.log(model, "->", reply.choices[0].message.content);}Timeouts and retries
Section titled “Timeouts and retries”- The SDK retries a failed request twice by itself: on a 429, on the 5xx statuses and on a dropped connection.
max_retrieschanges that. - Its default timeout is ten minutes. A slow image can take about that long; long text answers are better streamed.
Where next
Section titled “Where next”- Chat Completions: Streaming, tools, images and JSON.
- Integrations: Frameworks and tools built on this SDK.