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.1.tar.gz (10.0 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.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for respan_instrumentation_openai-1.2.1.tar.gz
Algorithm Hash digest
SHA256 62b501b83ecac1bfb14f939a95a6b5cdd9bbe7689b62340a2bde77af7076cfe0
MD5 2c8fb190f87426c087de34e74590f95d
BLAKE2b-256 909751fed241659ec59d49253fa2098ec4a9ade76c1176c615f653bcefdb363a

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_openai-1.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_openai-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29d8b032f0560a2c3cbb38028e25467678ac284bd0016719369c063df976d70e
MD5 bfef3b5d246a1284cf11649d11be1641
BLAKE2b-256 b7ccf6131be8304bd17c8c95f10f83c771dd15392a64093ea7e0fa8594705c5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_openai-1.2.1-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