Skip to main content

OpenAI OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the OpenAI framework. It enables tracing and monitoring of applications built with OpenAI.

Installation

  1. Install traceAI OpenAI
pip install traceAI-openai

Set environment variables

Set the Future AGI keys for tracing and the OpenAI key for the Quickstart request:

export FI_API_KEY="your-future-agi-api-key"
export FI_SECRET_KEY="your-future-agi-secret-key"
export OPENAI_API_KEY="your-openai-api-key"

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="openai_app"
)

Configure OpenAI Instrumentation

Set up your OpenAI client with built-in observability. This includes support for text, image, and audio models.

from traceai_openai import OpenAIInstrumentor

OpenAIInstrumentor().instrument(tracer_provider=trace_provider)

Make a traced request

Create the client after calling OpenAIInstrumentor().instrument(...).

from openai import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Tell me a short joke."}],
)
print(response.choices[0].message.content)
trace_provider.force_flush()  # Flush before a short-lived script exits.

Vercel AI Gateway

Use the same OpenAIInstrumentor for Chat Completions sent to Vercel AI Gateway; no gateway-specific package or OpenAI key is needed. Set AI_GATEWAY_API_KEY to your Vercel AI Gateway key and AI_GATEWAY_MODEL to a current model ID:

export AI_GATEWAY_API_KEY="your-vercel-ai-gateway-key"
export AI_GATEWAY_MODEL="<provider>/<model>"

Keep the tracer registration and instrumentation from the Quickstart above, then replace its OpenAI client and request with:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://ai-gateway.vercel.sh/v1",
    api_key=os.environ["AI_GATEWAY_API_KEY"],
)
response = client.chat.completions.create(
    model=os.environ["AI_GATEWAY_MODEL"],
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(response.choices[0].message.content)
trace_provider.force_flush()  # Flush before a short-lived script exits.

The documented gateway host is labelled gen_ai.provider.name="vercel". This identifies the service the client calls, not the upstream model provider or a fallback provider. Unknown proxies and look-alike hosts retain their existing provider label. Sync, async, streamed and failed calls use the same attribution.

Client spans capture prompts, responses and returned token usage. They do not reconstruct gateway routing, retries, cost or provider attempts. Vercel's separate Trace Drains provide those gateway details but omit prompts and completions. A drain is not configured by OpenAIInstrumentor; do not sum client and drain token counts for the same request as separate model usage.

Metadata

Release files for traceAI-openai 0.1.12

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-openai 0.1.12
File Size Uploaded Provenance Actions
traceai_openai-0.1.12.tar.gz 23.4 kB With provenance Details for traceai_openai-0.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for traceAI-openai 0.1.12
File Interpreter ABI Platform Actions
traceai_openai-0.1.12-py3-none-any.whl Python 3 none any Details for traceai_openai-0.1.12-py3-none-any.whl

Total release size: 52.4 kB

Release files / traceai_openai-0.1.12.tar.gz

Download URL traceai_openai-0.1.12.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
43456dc0034edc2e61373267e08f1e219e7a93d33508733fd259ba2a61106052
BLAKE2b-256 checksum
How to use checksums
e2ded6804184510346c03a154ccd3414682573f80fb45b54afcca01e70f9f08d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Release files / traceai_openai-0.1.12-py3-none-any.whl

Download URL traceai_openai-0.1.12-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
171b6808d6cbd1e982a74ae16e042157135bd651ea3827ad71af49448b46ad6c
BLAKE2b-256 checksum
How to use checksums
043296254db009703d5361aa5560586113c5abb08714aea3f87480141f48ecb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 1, 2026.

Transparency log

Security for traceAI-openai 0.1.12

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for traceai_openai-0.1.12.tar.gz

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 Nov 1, 2026.

Transparency log

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.

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