Skip to main content

Overview

Laminar is an open-source, OpenTelemetry-native observability platform for AI agents. Trace, debug, and monitor every OpenRouter call your app makes, with prompts, responses, token counts, cost, and latency on each span, in both TypeScript and Python. OpenRouter gives you access to hundreds of models through a single API, so teams use it to switch models and providers without changing code. Laminar auto-instruments the OpenRouter SDK: initialize Laminar once and every chat, responses, and embeddings call is traced.
OpenRouter-specific headers are optional. Setting them allows your app to appear on the OpenRouter leaderboards.

Getting Started

1. Install Laminar and the OpenRouter SDK

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.

3. Initialize Laminar

@openrouter/sdk is an ES module, so pass it to instrumentModules for Laminar to patch it:

4. Use the OpenRouter SDK as usual

All OpenRouter SDK calls are now traced in Laminar.
Using OpenRouter inside Next.js? The Vercel AI SDK page covers the Next.js-specific setup (serverExternalPackages and instrumentation.ts).

What Laminar captures

Each call becomes an LLM span named after the resource you called:
  • openrouter.chat for client.chat.send.
  • openrouter.responses for client.responses.send.
  • openrouter.embeddings for client.embeddings.generate.
Every span carries the model, the request messages, the response, token counts, and cost, whether the call returns a single response or a stream. Streamed responses are recorded once the stream is consumed.

Using the OpenAI SDK with OpenRouter

If you reach OpenRouter through the OpenAI SDK, Laminar traces those calls too. Point the OpenAI client’s base URL at OpenRouter and initialize Laminar as usual.

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.

See what happened in a trace

Open a trace in Laminar and you land on the transcript view: Laminar extracts the agent input, the model’s turns, and any tool calls into a conversation, so you read what happened instead of clicking through a tree of span names. Token counts, cost, and latency sit on each LLM span, and you can open any span in the playground to iterate on the prompt. More on the trace UX: Viewing traces.

Track outcomes with Signals

Traces answer what happened on this run. Signals answer the cross-trace question: how often does a model refuse, which runs fell back to a second provider, when do responses come back empty. A Signal pairs a plain-language prompt with a JSON output schema. Laminar runs it live on new traces (Triggers) or backfills it across history (Jobs) and records a structured event every time it matches. From there you query, cluster, and alert on events across every trace.
Every new project ships with a Failure Detector Signal that categorizes issues on any trace over 1000 tokens. Open it from the Signals sidebar to see events as soon as your OpenRouter traces arrive.

Query across traces

  • SQL editor for ad-hoc queries across traces, spans, signals, and evals.
  • SQL API for programmatic access from scripts and pipelines.
  • CLI (lmnr-cli sql query) for terminal-driven queries and piping JSON into shell tools or coding agents.
  • MCP server to query Laminar directly from Claude Code, Cursor, Codex, or any MCP-aware client.

Enrich your OpenRouter traces

  • Attach sessions, user IDs, metadata, and tags to OpenRouter spans via the SDK reference.
  • Wrap the functions around your OpenRouter calls with observe and mark them as TOOL spans so they show up in the transcript.
  • Images you send to vision-capable models are captured automatically (Tracing Images).

What’s next

Viewing traces

Read the transcript view, filter, and search across traces.

Signals

Detect behaviors and failures across every run, then query, cluster, and alert on them.

SQL editor and MCP server

Query traces programmatically from the UI, API, or your IDE.

Tracing structure

Add sessions, metadata, and tags, and group calls under your own spans.

OpenAI

Trace the OpenAI SDK directly in TypeScript and Python.

Anthropic

Trace the Anthropic SDK directly in TypeScript and Python.

LiteLLM

One integration for every model LiteLLM routes to.

Gemini

Trace Gemini calls made with the Google Gen AI SDK.

Vercel AI SDK

Trace generateText and streamText in Next.js and Node.js.

All integrations

Browse every provider, framework, coding agent, and browser integration Laminar supports.