Overview
OpenRouter provides a unified API that gives you access to hundreds of AI models through a single endpoint. Many teams use it to keep one SDK while switching models or providers. With Laminar, you can trace OpenRouter traffic by using the OpenAI SDK pointed at the OpenRouter base URL.OpenRouter-specific headers are optional. Setting them allows your app to appear on the OpenRouter leaderboards.
Recommended: OpenAI SDK with OpenRouter
Laminar automatically instruments the OpenAI SDK. If you set the OpenAI SDK base URL to OpenRouter, Laminar will capture those calls as LLM spans.- TypeScript
- Python
1. Install Laminar and OpenAI
2. Set up your environment variables
Store your API keys in a.env file:Using OpenRouter inside Next.js? The Vercel AI SDK page covers the Next.js-specific setup (
serverExternalPackages, instrumentation.ts, and Laminar.patch for direct SDK clients).3. Initialize Laminar and OpenAI
4. Use OpenRouter as usual
OpenRouter SDK (Beta)
Laminar does not auto-instrument the OpenRouter SDK. Wrap your call withobserve() to capture inputs/outputs and group it in a trace. LLM-specific fields (tokens, cost) are not added automatically in this mode.
Using the OpenRouter API directly
Direct HTTP calls are captured as custom spans via
observe(). LLM-specific fields (tokens, cost) are not extracted automatically from raw responses.Monitoring Your OpenRouter Usage
When you use the OpenAI SDK integration above, Laminar will create LLM spans so you can:- View detailed traces of each OpenRouter request, including request and response
- Track token usage when OpenRouter returns usage data
- See cost estimates when pricing data for the model is available in Laminar
- Monitor latency and performance metrics
- Open LLM spans in Playground for prompt engineering
Advanced Features
- Enrich traces with sessions, user IDs, metadata, and tags via the SDK reference.
- Wrap custom functions with
observeto capture business logic alongside model calls. - Images sent to vision-capable models are captured automatically - see Tracing Images.