Closed
Description
Please read this first
- Have you read the docs?Agents SDK docs Yes
- Have you searched for related issues? Yes
Question
I managed to enable tracing to logfire with usage of gemini. But, I faced a dilemma. If the code is like this
BASE_URL = 'https://generativelanguage.googleapis.com/v1beta/openai/'
API_KEY = os.getenv("GEMINI_API_KEY") or ""
MODEL_NAME = 'gemini-2.0-flash'
client = AsyncOpenAI(
base_url=BASE_URL,
api_key=API_KEY,
)
set_default_openai_client(client=client, use_for_tracing=True)
set_default_openai_api("chat_completions")
set_tracing_disabled(disabled=True)
Then there is no trace sent to logfire.
If the code is like this
set_default_openai_client(client=client, use_for_tracing=True)
set_default_openai_api("chat_completions")
set_tracing_disabled(disabled=False)
Then logfire server gets the tracing. But there is always a error message shown as below.
Tracing client error 401: {
"error": {
"message": "Incorrect API key provided: AIzaSyAe***************************o4jk. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}
It looks the set_tracing_disabled
method controls both tracing to OpenAI and 3rd-party tracer. If set_tracing_disabled(disabled=True)
, there is no tracing sent; if set_tracing_disabled(disabled=False)
or miss this statement, tracing is sent to both logfire and openai which triggers the error message.
Is it possible to disable tracing to OpenAI and enable tracing with gemini + logfire?