Skip to content

OpenAI SDKs

Unless you have a specific requirement, we recommend using the OpenAI request format for every model on Omrouter. It is the easiest format to add to existing applications and makes switching models simpler.

Setting Value
API key OMROUTER_API_KEY
Base URL https://omrouter.com/v1
Model Model name shown on the Pricing page
Terminal window
python -m pip install openai
example.py
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["OMROUTER_API_KEY"],
base_url="https://omrouter.com/v1",
)
response = client.chat.completions.create(
model=os.environ["OMROUTER_MODEL_ID"],
messages=[
{"role": "user", "content": "Explain what an API gateway does."},
],
)
print(response.choices[0].message.content)
Terminal window
npm install openai
example.mjs
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.OMROUTER_API_KEY,
baseURL: 'https://omrouter.com/v1',
});
const response = await client.chat.completions.create({
model: process.env.OMROUTER_MODEL_ID,
messages: [
{ role: 'user', content: 'Explain what an API gateway does.' },
],
});
console.log(response.choices[0].message.content);

Start with the simple request above. After it works, add streaming, tools, image input, or JSON output as needed. Model features vary, so test after adding each feature.

If you use an existing client instead of writing code, see Configure existing applications and tools.