@openrouter/agent) to capture events and traces for model calls, tool execution, and multi-turn agent loops.
Installation
Quick Start
ModelResult is consumed with getText(), getResponse(), or a stream method.
Standalone callModel
If you import OpenRouter’s standalone callModel helper, wrap that function once and call the wrapped version:
What Gets Traced
- Agent calls - input, output, model, response ID, response status, and token usage when OpenRouter returns it
- Tool calls - client tool executions captured as
ai.toolCalltrace spans linked to the root event - Conversation grouping - pass
convoIdto group related agent calls - Errors - failed OpenRouter calls finalize an error event before re-throwing to your application
- Signals and users - use the included
signals.trackandusers.identifyAPIs alongside automatic events
Configuration
Identify Users
Associate traits with a user for filtering and trajectories:Track Signals
Attach feedback, labels, or other signals to the most recently captured event:Flushing and Shutdown
Always callflush() or shutdown() before your process exits to ensure all telemetry is shipped:
Known Limitations
- Creating a
ModelResultwithout consuming it does not ship an event. - Client tool spans wrap the local tool execution function, so their timing reflects local tool runtime.
- Server-executed OpenRouter tools are represented from response items when OpenRouter returns them after the provider response completes. Client function tools have the richest live trace data.