Skip to main content

Documentation Index

Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt

Use this file to discover all available pages before exploring further.

OpenRouter lets you call models from many providers through a single API.
If you’re using OpenRouter’s agent toolkit package (@openrouter/agent), see OpenRouter Agent.

Setup

1

Install packages

# pnpm
pnpm add braintrust @openrouter/sdk
# npm
npm install braintrust @openrouter/sdk
2

Set environment variables

.env
OPENROUTER_API_KEY=<your-openrouter-api-key>
BRAINTRUST_API_KEY=<your-braintrust-api-key>

# If you are self-hosting Braintrust, set the URL of your hosted dataplane
# BRAINTRUST_API_URL=<your-braintrust-api-url>

Auto-instrumentation

Braintrust provides automatic tracing for OpenRouter calls. This is the recommended setup for most projects.
import { initLogger } from "braintrust";
import { OpenRouter } from "@openrouter/sdk";

initLogger({
  projectName: "My Project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});

const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });

const response = await client.chat.send({
  chatRequest: {
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "What is observability?" }],
  },
});
Run with the import hook:
node --import braintrust/hook.mjs app.js
If you’re using a bundler or Next.js Turbopack, see Trace LLM calls for plugin/loader setup.

Manual instrumentation

Trace an OpenRouter client explicitly by wrapping it with wrapOpenRouter.
import { initLogger, wrapOpenRouter } from "braintrust";
import { OpenRouter } from "@openrouter/sdk";

initLogger({
  projectName: "My Project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});

const client = wrapOpenRouter(
  new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }),
);

const response = await client.chat.send({
  chatRequest: {
    model: "openai/gpt-5-mini",
    messages: [{ role: "user", content: "What is observability?" }],
  },
});

What Braintrust traces

For the @openrouter/sdk package, Braintrust traces:
  • Chat completions via chat.send(), including streaming
  • Embeddings via embeddings.generate()
  • Responses API via beta.responses.send(), including streaming