Skip to main content

respan-instrumentation-openai

Respan instrumentation for direct OpenAI Python SDK usage. The native integration captures typed sync and async Chat Completions, Responses, Completions, and Embeddings calls, including Chat and Responses parse methods, tools, usage, and provider failures.

SDK compatibility

Supports openai>=3.0.0,<4.0.0 on Python 3.11–3.13. Verified against OpenAI 3.0.0 and 3.19.2 (September 27, 2026); CI runs the real SDK tests against the minimum and newest available 3.x release with released Respan runtime dependencies.

Chat Completions and Responses support both create(stream=True) and the .stream() context manager helpers. Consuming a stream or explicitly closing it emits one span. An early close retains the text and function arguments received so far; token usage is included only when the provider has supplied it. Async streams must be consumed or closed with await stream.close() or an async context manager. Responses response.failed events mark the span as an error while leaving the SDK event stream unchanged.

Content capture applies to these typed methods. Raw HTTP response wrappers (with_raw_response and with_streaming_response), existing-response retrieval, Realtime, and other OpenAI resources are outside this capture support.

Install

pip install respan-ai 'respan-instrumentation-openai[instruments]'

The base instrumentation package keeps OpenAI optional. Use the instruments extra above to install a compatible SDK, or manage openai yourself.

Configuration

Set RESPAN_API_KEY for trace export and OPENAI_API_KEY for model requests. RESPAN_BASE_URL optionally changes the Respan export endpoint; OPENAI_BASE_URL optionally changes the OpenAI client endpoint.

import os

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

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    instrumentations=[OpenAIInstrumentor()],
)

with OpenAI() as client:
    response = client.responses.create(
        model="gpt-4.1-nano",
        input="Hello!",
    )
    print(response.output_text)

respan.flush()
respan.shutdown()

View exported traces on the Respan dashboard.

Examples and validation

See respan-example-projects/python/tracing/openai-sdk for deterministic examples that execute the real SDK request and response parsing layers through an in-process HTTP transport, plus an opt-in live-provider example.

Run the package regressions locally with:

pip install -e '.[instruments]' pytest pytest-asyncio
pytest -q tests

Metadata

Release files for respan-instrumentation-openai 1.2.3

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

Source distribution (sdist)

Source distribution for respan-instrumentation-openai 1.2.3
File Size Uploaded
respan_instrumentation_openai-1.2.3.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for respan-instrumentation-openai 1.2.3
File Interpreter ABI Platform
respan_instrumentation_openai-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.3 kB

Release files / respan_instrumentation_openai-1.2.3.tar.gz

Download URL respan_instrumentation_openai-1.2.3.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
75084b5a63820aed29f4e26ae9acb51b243f3f3bc86356750634b0dfcca2bad2
BLAKE2b-256 checksum
How to use checksums
26913fae3a5b673a174b066386431694142b25dc1b4eb04a8594855d430f038e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / respan_instrumentation_openai-1.2.3-py3-none-any.whl

Download URL respan_instrumentation_openai-1.2.3-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f946b1c5edde505790ebc5e52e5fa2a0a6479cc5d37dea633307e26cfb6ff03
BLAKE2b-256 checksum
How to use checksums
cef382a020b51b9ceb5a1097409934d4543539be362fbbd6d2fc34958b064233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.0.1

2 release files

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