@openrouter/agent is OpenRouter’s TypeScript agent toolkit for agent loops.
- TypeScript
Setup
1
Install packages
2
Set environment variables
.env
@openrouter/agent v0.1.2 and later.Auto-instrumentation
Braintrust can auto-instrumentOpenRouter.callModel() calls. This is the recommended setup for most projects.node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects. Compile your TypeScript to JavaScript and run the compiled file with the import hook, or run TypeScript directly with a TypeScript loader.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 withwrapOpenRouterAgent.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
stepandstep_type(initialorcontinue) metadata. - One tool span per tool invocation the agent makes, with the tool name, input, and output.