OpenRouter

OpenRouter Integration

Trace every model routed through OpenRouter. wrapOpenRouter() captures which model was actually served, cost, latency, and token usage — across 100+ models.

OpenRouter is an API gateway that routes requests to 100+ LLMs from OpenAI, Anthropic, Google, Meta, Mistral, and others through a single OpenAI-compatible endpoint.

zespan.com — openrouter trace
Zespan trace showing an OpenRouter call with the actual served model and cost

Getting Started

1

Install the SDK

Install @zespan/sdk — OpenRouter uses an OpenAI-compatible API.

bash
npm install @zespan/sdk openai
2

Wrap the OpenRouter client

Configure an OpenAI client pointing at OpenRouter's base URL and pass it to wrapOpenRouter().

typescript
import OpenAI from 'openai';
import { Zespan, wrapOpenRouter } from '@zespan/sdk';

const lt = new Zespan({ apiKey: process.env.ZESPAN_API_KEY });
const openrouter = wrapOpenRouter(
  new OpenAI({
    baseURL: 'https://openrouter.ai/api/v1',
    apiKey: process.env.OPENROUTER_API_KEY,
  }),
  lt
);

const res = await openrouter.chat.completions.create({
  model: 'anthropic/claude-3-5-sonnet',
  messages: [{ role: 'user', content: 'Hello' }],
});
3

View traces in Zespan

Open Trace Explorer. Each trace shows the actual model served, token usage, and USD cost with OpenRouter's per-model pricing.

What's captured automatically

  • Actual model served: captures the routed model, not just the requested one
  • 100+ models: GPT-4o, Claude 3.5, Llama 3, Gemini, Mistral, and more
  • Per-model cost: OpenRouter's pricing applied per call
  • Fallback tracking: if OpenRouter reroutes to a fallback model, it's recorded
  • Standard OpenAI-compatible response tracing

FAQ

Does Zespan capture which model OpenRouter actually served?

Yes. wrapOpenRouter() reads the model field from OpenRouter's response, so the trace always shows the actual served model, not the requested one.

Start for free — 10K traces/month, no card needed

OpenRouter integration works on all plans including the free tier.

← All integrations