Node.js SDK
LLMTR works with the OpenAI Node.js SDK unchanged. Just update baseURL and apiKey.
Install
Section titled “Install”npm install openaiBasic usage
Section titled “Basic usage”import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://llmtr.com/v1", apiKey: process.env.LLMTR_API_KEY});
const response = await client.chat.completions.create({ model: "openai/gpt-4o", messages: [ { role: "system", content: "You are concise." }, { role: "user", content: "Explain LLMTR in one line." } ], temperature: 0.3});
console.log(response.choices[0].message.content);Streaming
Section titled “Streaming”const stream = await client.chat.completions.create({ model: "anthropic/claude-sonnet-4.5", messages: [{ role: "user", content: "Write a haiku." }], stream: true});
for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}TypeScript
Section titled “TypeScript”First-class TypeScript support:
import OpenAI, { type ChatCompletion } from "openai";
const client = new OpenAI({ baseURL: "https://llmtr.com/v1", apiKey: process.env.LLMTR_API_KEY!});
async function ask(prompt: string): Promise<string> { const res: ChatCompletion = await client.chat.completions.create({ model: "openai/gpt-4o", messages: [{ role: "user", content: prompt }] }); return res.choices[0].message.content ?? "";}Image input
Section titled “Image input”const response = await client.chat.completions.create({ model: "google/gemini-2.5-flash", messages: [{ role: "user", content: [ { type: "text", text: "Describe this image" }, { type: "image_url", image_url: { url: "https://..." } } ] }]});Retry and timeout
Section titled “Retry and timeout”const client = new OpenAI({ baseURL: "https://llmtr.com/v1", apiKey: process.env.LLMTR_API_KEY, maxRetries: 3, timeout: 30_000});Edge runtime (Next.js, Vercel, Cloudflare)
Section titled “Edge runtime (Next.js, Vercel, Cloudflare)”The SDK runs on Edge too:
export const runtime = "edge";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://llmtr.com/v1", apiKey: process.env.LLMTR_API_KEY});
export async function POST(req) { const { messages } = await req.json(); const stream = await client.chat.completions.create({ model: "openai/gpt-4o", messages, stream: true }); return new Response(stream.toReadableStream());}