OpenAI SDK
OdiRouter’s LLM API is OpenAI-compatible. Existing OpenAI SDK clients can call OdiRouter by setting the API key and Base URL.
Requirements
Section titled “Requirements”| Requirement | Value |
|---|---|
| Python package | openai |
| Node.js package | openai |
| Base URL | https://www.odirouter.ai/v1 |
| API Key | OdiRouter API key |
| Model | An OdiRouter LLM model ID |
Install
Section titled “Install”pip install openainpm install openaiPython
Section titled “Python”from openai import OpenAI
client = OpenAI( api_key="YOUR_API_KEY", base_url="https://www.odirouter.ai/v1",)
response = client.chat.completions.create( model="gpt-5.5", messages=[ {"role": "user", "content": "Reply with a one-line integration test."} ],)
print(response.choices[0].message.content)Node.js
Section titled “Node.js”import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.ODIROUTER_API_KEY, baseURL: "https://www.odirouter.ai/v1",});
const response = await client.chat.completions.create({ model: "gpt-5.5", messages: [ { role: "user", content: "Reply with a one-line integration test." }, ],});
console.log(response.choices[0].message.content);Streaming
Section titled “Streaming”const stream = await client.chat.completions.create({ model: "gpt-5.5", messages: [{ role: "user", content: "Stream three short bullets." }], stream: true,});
for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}Troubleshooting
Section titled “Troubleshooting”| Symptom | Fix |
|---|---|
| SDK calls OpenAI instead of OdiRouter | Confirm base_url or baseURL is set to https://www.odirouter.ai/v1 |
401 or invalid key | Use an OdiRouter API key |
| Model not found | Use a model returned by GET https://www.odirouter.ai/v1/models |
| Browser build exposes key | Move the SDK call to a server route or backend process |