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.3.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 respan-instrumentation-openai 1.3.0
File Size Uploaded
respan_instrumentation_openai-1.3.0.tar.gz 16.9 kB Details

Built distribution (wheel)

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

Total release size: 35.8 kB

Release files / respan_instrumentation_openai-1.3.0.tar.gz

Download URL respan_instrumentation_openai-1.3.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0f8d6eb08a090c978671fced8129826216dac35b95fe57037eace886079f32e7
BLAKE2b-256 checksum
How to use checksums
c591eb3227b36f470be917a0f53a39f10cd891b06ebd3ef97a03466eb923da3b
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 Oct 13, 2026.

Transparency log

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

Download URL respan_instrumentation_openai-1.3.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc664453cff0649462ec61cae56c2739ac5fb95395b8165bb3806575f852e5fe
BLAKE2b-256 checksum
How to use checksums
450c7517b3ad58382360be5dc393bbb13bdd316a510ea6b95d249555233e8b9f
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 Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.3

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