Skip to content

Support OPENAI_BASE_URL in tracing #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tabletcorry
Copy link

Agent tracing was hardcoded against the API endpoint, so any client using a proxy or alternate route to the OpenAI AI endpoint would encounter errors.

So this modify the tracing init code to use OPENAI_BASE_URL when present, if the local environment hasn't overridden anything.

Note: Because this code path is generally executed at import time, the environment variable needs to be set prior to importing any openai-agents code.

@seratch seratch added enhancement New feature or request feature:tracing labels Jul 8, 2025
@seratch seratch requested a review from rm-openai July 8, 2025 13:12
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@rm-openai rm-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is generally not a safe backwards compatible change. For example, environments may set OPENAI_BASE_URL to a proxy to allow tracing/cost tracking, but that proxy doens't necessarily support tracing (since only thje specific openai api supports it). Would prefer something more explicit where users opt-in to setting the tracing url.

@tabletcorry
Copy link
Author

Nod, I searched around a fair bit to see if OpenAI had any variable or name for the tracing endpoint, and couldn't find one, so I decided to piggyback instead.

Given the lasting nature of an env var name like this, it seems like something y'all should define, rather than me.

@tabletcorry
Copy link
Author

Also since the token is shared for API access and tracing access, I am not sure how a proxy would work that doesn't support both.

It would be somewhat odd to give someone a real OpenAI token, then tell them to use a proxy with a different token instead.

@seratch
Copy link
Member

seratch commented Jul 16, 2025

@rm-openai Do you think OPENAI_TRACES_INGEST_ENDPOINT env variable (or anything like that) can work? Or do prefer asking devs to instantiate TracingExporter with the endpoint string in code? I don't have strong opinion here.

@rm-openai
Copy link
Collaborator

Yeah let's add a URL method similar to set_tracing_export_api_key().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants