Skip to main content
OpenRouter is OpenAI-compatible: use the standard openai SDK with the OpenRouter base URL (https://openrouter.ai/api/v1). TraceRoot captures these calls through the existing OpenAI instrumentation — no new OpenRouter-specific instrumentor or enum is required. The same approach works for xAI, Moonshot, Z.AI and other OpenAI-compatible providers.

Install

Set up

Usage

Verify

Run your code and confirm the trace arrives:
  1. In the TraceRoot UI: Navigate to Tracing > Traces in TraceRoot Cloud. You should see a trace with root span ChatCompletion (OpenAI Chat Completions on TypeScript).
  2. Via the CLI: Run traceroot traces list to inspect your recent traces from the terminal.

What gets captured

Limitations

  • OpenRouter requests are traced through the standard OpenAI integration; token pricing requires provider-returned usage headers or recognized model mappings.

Run the example

Clone the repo and run a complete OpenRouter agent end-to-end.

Python

Run the Python OpenRouter tool-agent example

TypeScript

Run the TypeScript OpenRouter example

Next steps

Python SDK Reference

Explore the full Python SDK reference and instrumentation options.

Cost Tracking

Learn how TraceRoot calculates token costs and tracks model spend.