Skip to main content
@openrouter/agent is OpenRouter’s TypeScript agent toolkit for agent loops.

Setup

1

Install packages

2

Set environment variables

.env
Braintrust supports @openrouter/agent v0.1.2 and later.

Auto-instrumentation

Braintrust can auto-instrument OpenRouter.callModel() 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 Agent client explicitly by wrapping it with wrapOpenRouterAgent.

What Braintrust traces

Braintrust captures the agent run as a trace tree:
  • A top-level LLM span for the call, with the final output and aggregated token usage across all turns.
  • One nested LLM span per agent loop turn, with per-turn input, output, and usage, plus step and step_type (initial or continue) metadata.
  • One tool span per tool invocation the agent makes, with the tool name, input, and output.