Skip to main content

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.
Laminar automatically instruments the OpenAI SDK. If you set the OpenAI SDK base URL to OpenRouter, Laminar will capture those calls as LLM spans.

1. Install Laminar and OpenAI

2. Set up your environment variables

Store your API keys in a .env file:
Then load them in your application using a package like dotenv.
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

All OpenRouter calls made through the OpenAI SDK are now automatically traced in Laminar.

OpenRouter SDK (Beta)

Laminar does not auto-instrument the OpenRouter SDK. Wrap your call with observe() 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

You can use the interactive Request Builder to generate OpenRouter API requests in the language of your choice.
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:
  1. View detailed traces of each OpenRouter request, including request and response
  2. Track token usage when OpenRouter returns usage data
  3. See cost estimates when pricing data for the model is available in Laminar
  4. Monitor latency and performance metrics
  5. Open LLM spans in Playground for prompt engineering
Visit your Laminar dashboard to view your OpenRouter traces and analytics.

Advanced Features

  • Enrich traces with sessions, user IDs, metadata, and tags via the SDK reference.
  • Wrap custom functions with observe to capture business logic alongside model calls.
  • Images sent to vision-capable models are captured automatically - see Tracing Images.