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.
Configuration
Section titled “Configuration”| Setting | Value |
|---|---|
| API key | OMROUTER_API_KEY |
| Base URL | https://omrouter.com/v1 |
| Model | Model name shown on the Pricing page |
Python
Section titled “Python”python -m pip install openaiimport osfrom 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)JavaScript
Section titled “JavaScript”npm install openaiimport 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);Add more features
Section titled “Add more features”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.