OpenAI SDK
LLM API OdiRouter совместим с OpenAI. Существующие клиенты OpenAI SDK могут вызывать OdiRouter через API key и Base URL.
Требования
Заголовок раздела «Требования»| Требование | Значение |
|---|---|
| Python-пакет | openai |
| Node.js-пакет | openai |
| Base URL | https://www.odirouter.ai/v1 |
| API Key | API key OdiRouter |
| Model | ID LLM-модели в OdiRouter |
Установите
Заголовок раздела «Установите»pip install openainpm install openaifrom 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
Заголовок раздела «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
Заголовок раздела «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 ?? "");}Диагностика
Заголовок раздела «Диагностика»| Симптом | Исправление |
|---|---|
| SDK вызывает OpenAI вместо OdiRouter | Проверьте base_url или baseURL |
401 или invalid key | Используйте API key OdiRouter |
| Model not found | Используйте модель из GET https://www.odirouter.ai/v1/models |
| Browser build раскрывает ключ | Перенесите вызов SDK в server route или backend process |