Using the OpenAI SDK

Python and Node official SDKs need one parameter changed.

Python

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-token",
    base_url="https://api.router.ai/v1",
)

resp = client.chat.completions.create(
    model="gpt-5.6-terra",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-your-token",
  baseURL: "https://api.router.ai/v1",
});

Streaming

Pass stream=True (stream: true in Node) — identical to the official usage.

Blog