Skip to main content

OpenRouter Python SDK tracing

Trace calls made through the dedicated openrouter Python SDK with the maintained traceAI-openrouter package. For the OpenAI-compatible client, use traceAI-openai instead; do not instrument the same request with both packages or HTTPX tracing.

pip install traceAI-openrouter

Set FI_API_KEY, FI_SECRET_KEY, and OPENROUTER_API_KEY in your environment. Then:

import os

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from openrouter import OpenRouter
from traceai_openrouter import OpenRouterInstrumentor

provider = register(project_type=ProjectType.OBSERVE, project_name="openrouter-demo")
OpenRouterInstrumentor().instrument(tracer_provider=provider)
client = OpenRouter(api_key=os.environ["OPENROUTER_API_KEY"])
answer = client.chat.send(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "What is the capital of Japan?"}],
)
print(answer.choices[0].message.content)
provider.force_flush()

Find the openrouter.chat span in your Future AGI project. The adapter covers synchronous and asynchronous Chat, Embeddings, Responses and deprecated beta.responses calls. Streams finish when fully consumed or closed; final usage is available only when the server sends a usage chunk. For early exits, close the stream, or use a context manager.

The default TraceConfig captures plain-text chat messages, plain-text Responses inputs and textual outputs, capped at 32 KiB. Structured or multimodal input, embedding vectors and content, image payloads, exception messages and stacks, and authorization headers are never included. Pass TraceConfig(hide_inputs=True, hide_outputs=True) to instrument(config=...) to remove prompt/response content. Directional message, text and image privacy flags also suppress the corresponding generic input/output attributes; hiding input images suppresses the entire input value because a text string can contain an image reference. The package does not send requests to OpenRouter on its own.

Metadata

Release files for traceAI-openrouter 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traceAI-openrouter 0.1.0
File Size Uploaded Provenance Actions
traceai_openrouter-0.1.0.tar.gz 5.2 kB Without provenance Details for traceai_openrouter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for traceAI-openrouter 0.1.0
File Interpreter ABI Platform Actions
traceai_openrouter-0.1.0-py3-none-any.whl Python 3 none any Details for traceai_openrouter-0.1.0-py3-none-any.whl

Total release size: 11.2 kB

Release files / traceai_openrouter-0.1.0.tar.gz

Download URL traceai_openrouter-0.1.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f63d10d70a0414e6c39d65a0b4304ca5b0e4ae941e6b15dee50a8e5c5dc070fd
BLAKE2b-256 checksum
How to use checksums
9875e3d0a5772aed64453119f79e2e287dcdcfd53cec7ba56db4340998950481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / traceai_openrouter-0.1.0-py3-none-any.whl

Download URL traceai_openrouter-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b3694ca814bc0cacfa06ebdef627c96d9912796920a04f604fb9eaed016dacb
BLAKE2b-256 checksum
How to use checksums
f0fcd282e695afb301970535948c37f5f24a11c169510c1a4ff94e48b402a864
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for traceAI-openrouter 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page