Skip to main content

Respan instrumentation plugin for direct OpenAI SDK usage (native, Traceloop-free)

Project description

respan-instrumentation-openai

Respan instrumentation plugin for direct OpenAI SDK usage. A native, Traceloop-free instrumentation: it patches the OpenAI SDK directly and emits Respan's own LLM span conventions (llm.request.type, gen_ai.*, traceloop.entity.*, respan.entity.log_type), so chat, responses, completions, and embeddings calls are traced as real LLM calls with token/cost roll-up. Covers sync, async, and streaming.

Configuration

1. Install

pip install respan-instrumentation-openai

2. Set Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Your Respan API key. Authenticates both proxy and tracing.
RESPAN_BASE_URL No Defaults to https://api.respan.ai.

All vendor-specific variables (e.g. OPENAI_API_KEY) are derived from these in your application code.

Quickstart

3. Run Script

import os
from openai import OpenAI
from respan import Respan
from respan_instrumentation_openai import OpenAIInstrumentor

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai")

respan = Respan(
    api_key=respan_api_key,
    base_url=respan_base_url,
    instrumentations=[OpenAIInstrumentor()],
)

client = OpenAI(
    api_key=respan_api_key,
    base_url=f"{respan_base_url}/api/openai",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

respan.flush()

4. View Dashboard

After running the script, traces appear on your Respan dashboard.

Further Reading

See the examples/openai-sdk/ directory for runnable examples including streaming, tool use, Responses API, and gateway routing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respan_instrumentation_openai-1.2.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

respan_instrumentation_openai-1.2.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file respan_instrumentation_openai-1.2.0.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_openai-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0ba3a12188eb060ded51b5f97346aec2b52ce3aecf68d912b7b9b32db801f66a
MD5 2126dc56d1b8df4d98fcf0c88617b9cc
BLAKE2b-256 e1b58620a784276b6c6f549c30a1e2de9de0b959b0803935dd2c91768af79e22

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_openai-1.2.0.tar.gz:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file respan_instrumentation_openai-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_openai-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9138638929a1dbf06c7b2f87e6571d989d0b7bceaa3ef713de8ba1ee4a08f12a
MD5 c6265075c78ddb95e135003ab2934b5f
BLAKE2b-256 929e99edad8dd276c3427c5c317b6b1ca7abfb6794a0eaf9d61ebac424a3de10

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_openai-1.2.0-py3-none-any.whl:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page