Documentation

OpenAI SDK · Python / TS

Use Chat Completions with /v1 in the Base URL.

Prepare

Set the environment variables and select a model supporting Chat Completions. Use https://api.neatrouter.com/v1 as Base URL without adding /chat/completions yourself.

Python

Code
python -m pip install openai
python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["RELAY_API_KEY"],
    base_url="https://api.neatrouter.com/v1",
)
response = client.chat.completions.create(
    model=os.environ["RELAY_MODEL_ID"],
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

TypeScript

Code
npm install openai
typescript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.RELAY_API_KEY,
  baseURL: "https://api.neatrouter.com/v1",
});
const response = await client.chat.completions.create({
  model: process.env.RELAY_MODEL_ID!,
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content);

Select the protocol

These examples use Chat Completions. Responses is a separate protocol; confirm model and route support first. A method in the SDK does not establish platform availability. Keep the key on your server.

See the official Python and TypeScript SDK documentation.

Still have a question?

Support details have not been published.

On this page