TensorLoop
Examples

JavaScript / TypeScript

Use the official OpenAI JS SDK against TensorLoop.

Install

npm install openai

Basic call

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://litellm.tensorloop.tech/v1",
  apiKey: process.env.TENSORLOOP_KEY!,
});

const response = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello, briefly." }],
});

console.log(response.choices[0].message.content);

Streaming

const stream = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Count to ten." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0].delta.content ?? "");
}

Browser usage

Calling TensorLoop from the browser would leak your key. Don't do it. Always proxy through your own backend:

// Next.js Route Handler — server-side only
import OpenAI from "openai";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const client = new OpenAI({
    baseURL: "https://litellm.tensorloop.tech/v1",
    apiKey: process.env.TENSORLOOP_KEY!,
  });
  const response = await client.chat.completions.create({
    model: "gpt-4o-mini",
    messages,
  });
  return Response.json(response);
}

Edge runtimes

The OpenAI SDK works on Cloudflare Workers, Vercel Edge, and other fetch-based runtimes:

const client = new OpenAI({
  baseURL: "https://litellm.tensorloop.tech/v1",
  apiKey: env.TENSORLOOP_KEY, // from the runtime's env binding
  fetch: globalThis.fetch,
});

On this page