telemetry-dev-openrouter
OpenRouter SDK instrumentation for telemetry.dev. It wraps the official openrouter Python SDK
and emits telemetry.dev generation and embedding spans through telemetry-dev.
Docs: https://telemetry.dev/docs/integrations/openrouter
Install
pip install telemetry-dev-openrouter
Requires Python 3.10 or later and openrouter 1.1.0 or a later 1.x release.
Initialize the core SDK first. init() reads your project API key from the TELEMETRY_DEV_API_KEY environment variable, so set it before you start the app:
import telemetry_dev
telemetry_dev.init(service_name="my-service")
Versions of telemetry-dev before 0.3.0 sent data to https://ingest.telemetry.dev by default.
That hostname reaches the same service and stays supported: if a firewall allows only it, set
TELEMETRY_DEV_BASE_URL to it.
Per-client wrapping
from openrouter import OpenRouter
from telemetry_dev_openrouter import wrap_open_router
client = wrap_open_router(OpenRouter(api_key="sk-or-v1-..."))
client.chat.send(
model="openai/gpt-6-luna",
messages=[{"role": "user", "content": "Tell me a joke about OpenTelemetry"}],
)
Use this when you want explicit control over which clients are instrumented. The same wrapped
client supports synchronous methods and their *_async counterparts.
Global instrumentation
from openrouter import OpenRouter
from telemetry_dev_openrouter import instrument_openrouter, uninstrument_openrouter
instrument_openrouter()
client = OpenRouter(api_key="sk-or-v1-...")
try:
client.responses.send(model="openai/gpt-6-luna", input="Explain OpenTelemetry briefly")
finally:
uninstrument_openrouter()
Use this as the app-wide one-liner at startup when all OpenRouter clients should be instrumented.
Repeated wrapping or global instrumentation is safe, and uninstrument_openrouter() restores the
original SDK methods.
Instrumented surfaces
Synchronous and asynchronous variants are covered:
client.chat.send(...)andclient.chat.send_async(...)client.responses.send(...)andclient.responses.send_async(...)client.embeddings.generate(...)andclient.embeddings.generate_async(...)
All spans use gen_ai.provider.name = "openrouter". Generation spans capture the request model and
input, supported sampling parameters, response model and ID, finish reasons, output messages, and
token usage. Embedding spans capture the request input, request and response models, and token
usage; embedding vectors are intentionally not captured as output.
Generation spans also list the request's tools in gen_ai.tool.definitions: each tool's type and
name, and with capture_input on the description and parameters of each function and custom tool
(a custom tool's input format), which pass through mask.
When OpenRouter returns cost information, the integration records gen_ai.usage.cost from
usage.cost. If that field is absent, it falls back to
usage.cost_details.upstream_inference_cost. The cost attribute is omitted when neither value is
available.
When usage.is_byok is True, the request uses your own provider key. Your provider bills the
inference, and usage.cost is only the OpenRouter fee. The integration then records the sum of
usage.cost and usage.cost_details.upstream_inference_cost. If the response has no
upstream_inference_cost, the integration records no cost.
Streaming
Chat and Responses API streams are traced for sync and async callers. The integration accumulates captured output, records time to first chunk, and maps terminal usage and cost when OpenRouter provides them. Terminal Responses API events close the span, including completed, failed, incomplete, and error events.
Responses stream output can include reconstructed output items followed by bounded
{"type": "telemetry.dev.response_stream_event", "event_type": ..., "payload": ...} entries for
consumed image-generation lifecycle and partial-image events, apply-patch diff events, fusion
lifecycle, analysis, and panel events, web-search lifecycle events, and debug timing events.
OpenRouter debug upstream request-body echoes are not retained. These provider-event entries share
the stream capture budget and set
telemetry.dev.capture.truncated = true when only a prefix can be retained.
Requests are passed to OpenRouter unchanged. The integration does not add or modify
stream_options, so streaming usage and cost are available only when they are present in the
stream returned by OpenRouter.
Failure behavior
Instrumentation is fail-open when telemetry_dev.init() has not been called: OpenRouter requests
still execute and return their normal SDK values without exporting telemetry.
Limitations
- Unconsumed streams end their spans only when the stream is exhausted, errors, or is closed.
- Streaming output is kept up to 16 MiB, and all streams in flight share the
max_stream_bytesbound of the core (64 MiB by default); terminal metadata and usage can still be recorded after the bound is reached. The configuredmax_attribute_lengthdoes not shrink this retention bound; the core applies it to the exported attribute after the mask runs. These bounds need atelemetry-devcore withmax_stream_bytes; with an older core, each stream keeps up to 64 KiB and 1,024 items. - A chat stream that is cut at the bound, closed early, or fails, and a Responses stream that is cut
at the bound, ends without a terminal response, or ends with an
errorevent settelemetry.dev.capture.truncated = true. With a mask configured, the incomplete reconstructed output is omitted because the mask cannot inspect the complete value. - Only the SDK methods listed above are instrumented in this version.
- Video generation (
client.video_generation) is not traced; submitted and polled video jobs produce no spans.
Development
From sdks/python-openrouter:
uv sync
uv run ruff format .
uv run pytest
uv run ruff format --check .
uv run ruff check .
uv run pyright
License
MIT. See LICENSE.
Metadata
Release files for telemetry-dev-openrouter 0.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| telemetry_dev_openrouter-0.2.7.tar.gz | 18.7 kB | Without provenance | Details for telemetry_dev_openrouter-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| telemetry_dev_openrouter-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for telemetry_dev_openrouter-0.2.7-py3-none-any.whl |
Total release size: 38.3 kB
Release files / telemetry_dev_openrouter-0.2.7.tar.gz
| Download URL | telemetry_dev_openrouter-0.2.7.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2201cda108175bfa25e4ea6652be6da4148a892bc9864f1c9ca236a05bc3800
|
|
BLAKE2b-256 checksum How to use checksums |
8dfdb0fa4fe2364ec6b1f25ec0ead2488b3fe8dc99c398c13e5019b41d9c30d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / telemetry_dev_openrouter-0.2.7-py3-none-any.whl
| Download URL | telemetry_dev_openrouter-0.2.7-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cdfb05d51bb7b062c9be0822a16d4065f5b4a54b880f9b48027621dcb28b1486
|
|
BLAKE2b-256 checksum How to use checksums |
1995ab5423eb25f238cfb7e43d8fd5174dc12c073e287d285a32ea5d7c2ff499
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for telemetry-dev-openrouter 0.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.