İçeriğe geç

Node.js SDK

LLMTR, OpenAI Node.js SDK ile birebir uyumludur. Sadece baseURL ve apiKey değiştirilir.

Terminal window
npm install openai
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);
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 ?? "");
}

SDK tam TypeScript desteği sağlar:

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 ?? "";
}
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://..." } }
]
}]
});
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)”

OpenAI SDK Edge runtime’da da çalışır:

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());
}