Skip to main content
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

2

Set environment variables

.env

Auto-instrumentation

Braintrust provides automatic tracing for OpenRouter calls. This is the recommended setup for most projects.
Run with the import hook:
The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

Manual instrumentation

Trace an OpenRouter client explicitly by wrapping it with wrapOpenRouter.

What Braintrust traces

For the @openrouter/sdk package, Braintrust traces:
  • Chat completions via chat.send(), including streaming
  • Embeddings via embeddings.generate()
  • Reranking via rerank.rerank(), with topN and document count in metadata and each result captured as { index, relevance_score }
  • Responses API via beta.responses.send(), including streaming