OpenRouter
Setup Guide

OpenRouter Integration

Send AI traces from OpenRouter (opens in a new tab) to Traceway with zero code changes. OpenRouter's built-in observability feature exports OTLP traces for every LLM call, giving you full visibility into costs, token usage, latency, and conversations.

How It Works

  1. OpenRouter routes your AI calls to the best model provider (OpenAI, Anthropic, Google, etc.)
  2. Observability broadcasts traces: OpenRouter sends an OTLP span for each completion with gen_ai.* attributes
  3. Traceway captures and stores: Model, tokens, costs, duration, and conversation content appear in your AI Traces dashboard

No SDK or code changes are needed. OpenRouter handles the instrumentation automatically.

Setup

1. Get Your Traceway Project Token

AI Tracing works with any backend or OpenTelemetry project in Traceway. If you don't have a project yet, create a new one and select OpenTelemetry as the framework. This gives you a project token you can use for the OpenRouter integration.

In your Traceway dashboard, go to Connection and copy your project token.

2. Configure OpenRouter Observability

  1. Go to OpenRouter Settings → Observability (opens in a new tab)
  2. Enable Broadcast
  3. Click Add Destination next to OpenTelemetry Collector
  4. Fill in the connection details:
FieldValue
NameTraceway (or any label)
Endpointhttps://cloud.tracewayapp.com/api/otel/v1/traces
Headers{"Authorization": "Bearer YOUR_PROJECT_TOKEN"}

Replace YOUR_PROJECT_TOKEN with your actual project token. If you're self-hosting, replace the endpoint with your instance URL.

  1. Click Test Connection to verify. OpenRouter only saves the destination if the test passes.
  2. Click Add to save

3. Verify in Traceway

Make an API request through OpenRouter, then open your Traceway dashboard and navigate to AI Traces. The call appears within a few seconds.

Configuration Options

OpenRouter provides several configuration options for the observability destination:

Privacy Mode

When enabled, OpenRouter excludes prompt and completion content from traces. Only metadata (model, tokens, cost, duration) is sent. Enable this if you don't want conversation data stored in Traceway.

Sampling Rate

Controls what percentage of traces are sent to Traceway. Set to 1 (100%) to capture every call, or lower it to reduce volume. Default is 1.

API Key Filter

Optionally filter traces to only include calls made with specific API keys. Useful if you have multiple environments sharing the same OpenRouter organization.

End-User and Conversation Attribution

Two request-level fields unlock Traceway's Conversations and Users analytics. Pass them on every chat completion request:

{
  "model": "anthropic/claude-sonnet-5",
  "messages": [...],
  "user": "account-8a41",
  "session_id": "thread-129af3"
}
  • user (up to 128 characters) identifies the end user of your product and becomes the user.id on the trace. Use a stable customer identifier: your internal account id, a tenant id, or an email. Do not pass session ids or random values here; the same user must carry the same value across all their conversations, or the per-user medians on the Users page become meaningless. If you leave it out, calls attribute to your OpenRouter account itself, which makes every customer look like one user. If PII must stay out of telemetry, use an internal id or a hash.
  • session_id (up to 256 characters, also accepted as the x-session-id header) groups requests into one conversation on the Conversations page. Use your chat/thread id, stable for the life of the conversation.

What Gets Captured

Every OpenRouter completion generates a trace with:

FieldSource AttributeExample
Modelgen_ai.request.modelopenai/gpt-4-turbo
Providergen_ai.systemopenai
Operationgen_ai.operation.namechat
Input Tokensgen_ai.usage.input_tokens50
Output Tokensgen_ai.usage.output_tokens100
Cached Tokensgen_ai.usage.input_tokens.cached20
Reasoning Tokensgen_ai.usage.output_tokens.reasoning10
Input Costgen_ai.usage.input_cost0.005
Output Costgen_ai.usage.output_cost0.015
Total Costgen_ai.usage.total_cost0.020
Finish Reasongen_ai.response.finish_reasonstop
Promptgen_ai.promptFull messages JSON
Completiongen_ai.completionFull response JSON
User IDuser.idThe user field from your request; falls back to your OpenRouter account id
Conversationsession.idThe session_id field from your request
Trace NameSpan nameSet it with trace_name inside the request's trace object
Temperaturegen_ai.request.temperature0.7

Any other key you pass in the request's trace object arrives as a trace.metadata.* span attribute and shows up in the metadata list on the call detail page.

Self-Hosted Setup

If you're running Traceway on your own infrastructure, use your instance URL as the endpoint:

https://your-traceway-instance.com/api/otel/v1/traces

The rest of the configuration is identical: project token in the Authorization header, same format.

Next Steps