Integrations / OpenRouter

Trace OpenRouter calls

To trace OpenRouter with Tracify, point the OpenAI client at OpenRouter's base URL and wrap it with the Tracify SDK. Each request is recorded with the model you chose, tokens, latency and any error.

Your code

OpenRouter

Tracify

One run.

  • 01The model slug you requested
  • 02Token usage and latency
  • 03Provider errors and rate limits
  • 04Calls grouped into the agent run

Setup

5 steps.

  1. 01

    Install

    OpenRouter uses the OpenAI library.

    bash
    npm install tracify-sdk openai
  2. 02

    Set your project key

    Create a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.

    bash
    export TRACIFY_API_KEY="tracify_sk_live_..."
  3. 03

    Wrap the client

    Set OpenRouter's base URL and your OpenRouter key, then wrap the client.

    typescript
    import OpenAI from "openai";
    import { wrapOpenAI } from "tracify-sdk";
    
    const openrouter = wrapOpenAI(
      new OpenAI({
        apiKey: process.env.OPENROUTER_API_KEY,
        baseURL: "https://openrouter.ai/api/v1",
      }),
    );
    
    const reply = await openrouter.chat.completions.create({
      model: "anthropic/claude-sonnet-4.5",
      messages: [{ role: "user", content: "Hello" }],
    });
  4. 04

    Or in Python

    The same two lines in Python.

    python
    import os
    import tracify
    from openai import OpenAI
    
    openrouter = tracify.wrap_openai(OpenAI(
        api_key=os.environ["OPENROUTER_API_KEY"],
        base_url="https://openrouter.ai/api/v1",
    ))
    
    reply = openrouter.chat.completions.create(
        model="anthropic/claude-sonnet-4.5",
        messages=[{"role": "user", "content": "Hello"}],
    )
  5. 05

    Run it once and look

    Run your code one time, then open the Tracing page of your project. Your OpenRouter call shows up as a run with its steps in order, plus the tokens, time and any error for each call.

Good to know

Shown with the OpenAI label

The wrapper reads the OpenAI call format, so calls are labeled as OpenAI-style in the trace. The model name you send is always the one shown, so you can still tell models apart.

Good to know

Compare models in one place

Because the model slug is recorded on every call, you can run the same agent on two models and compare their runs side by side in Tracify.

Good to know

About cost

Tracify records the tokens the provider returns. A dollar cost is shown when you give the wrapper your own rates with calculate_cost (Python) or calculateCost (TypeScript), so the number always matches your real price plan.

Full details in the documentation. All integrations are listed on the integrations page.

Does tracing OpenRouter change my requests or responses?
No. The wrapper passes your call straight through and records a copy. Your request, the response and any error reach your code unchanged.
Does it record which provider OpenRouter used behind the scenes?
Tracify records what the response returns. The model name is always saved. Extra routing details are saved only when OpenRouter includes them in the response.
Do model names with a slash work?
Yes. Slugs like anthropic/claude-sonnet-4.5 are stored exactly as you send them.

Send your first trace.

Free to start.