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
- OpenRouter routes your AI calls to the best model provider (OpenAI, Anthropic, Google, etc.)
- Observability broadcasts traces: OpenRouter sends an OTLP span for each completion with
gen_ai.*attributes - 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
- Go to OpenRouter Settings → Observability (opens in a new tab)
- Enable Broadcast
- Click Add Destination next to OpenTelemetry Collector
- Fill in the connection details:
| Field | Value |
|---|---|
| Name | Traceway (or any label) |
| Endpoint | https://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.
- Click Test Connection to verify. OpenRouter only saves the destination if the test passes.
- 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 theuser.idon 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 thex-session-idheader) 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:
| Field | Source Attribute | Example |
|---|---|---|
| Model | gen_ai.request.model | openai/gpt-4-turbo |
| Provider | gen_ai.system | openai |
| Operation | gen_ai.operation.name | chat |
| Input Tokens | gen_ai.usage.input_tokens | 50 |
| Output Tokens | gen_ai.usage.output_tokens | 100 |
| Cached Tokens | gen_ai.usage.input_tokens.cached | 20 |
| Reasoning Tokens | gen_ai.usage.output_tokens.reasoning | 10 |
| Input Cost | gen_ai.usage.input_cost | 0.005 |
| Output Cost | gen_ai.usage.output_cost | 0.015 |
| Total Cost | gen_ai.usage.total_cost | 0.020 |
| Finish Reason | gen_ai.response.finish_reason | stop |
| Prompt | gen_ai.prompt | Full messages JSON |
| Completion | gen_ai.completion | Full response JSON |
| User ID | user.id | The user field from your request; falls back to your OpenRouter account id |
| Conversation | session.id | The session_id field from your request |
| Trace Name | Span name | Set it with trace_name inside the request's trace object |
| Temperature | gen_ai.request.temperature | 0.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/tracesThe rest of the configuration is identical: project token in the Authorization header, same format.
Next Steps
- AI Tracing concepts: Understand how AI traces are stored and queried
- OpenTelemetry: Send traces from any OTel-instrumented application