Skip to content
exoticrouter.com ↗

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.

Python
pip install openai
TypeScript
npm install openai

Two things change: the base URL, which ends in /v1, and the key.

Python
import os
from 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)
TypeScript
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.

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.

Shell
export OPENAI_BASE_URL="https://api.exoticrouter.com/v1"
export OPENAI_API_KEY="sk-er-..."
PowerShell
$env:OPENAI_BASE_URL = "https://api.exoticrouter.com/v1"
$env:OPENAI_API_KEY = "sk-er-..."
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.

model takes any id from the catalogue, whatever lab made the model. The same client talks to all of them:

Python
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)
TypeScript
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);
}
  • The SDK retries a failed request twice by itself: on a 429, on the 5xx statuses and on a dropped connection. max_retries changes that.
  • Its default timeout is ten minutes. A slow image can take about that long; long text answers are better streamed.