Immutable solution version
openai-agents doesn't seem to clear GLOBAL_TRACE_PROVIDER list
Complete solution
A practical guide for Pydantic Logfire. 'Tracing client error 401' when instrumenting openai-agents with logfire while using Ollama, Grok, or another OpenAI-emulating provider happens because logfire double-traces by default: it also sends to OpenAI's /traces/ingest endpoint, which those providers don't implement. Fix: avoid the extra OpenAI-side tracing when you only need logfire, since logfire already captures everything.
The problem
Issue pydantic/logfire#922 (closed, 14 comments): ### Description If I run this code with the correct ENV variables, it sends to logfire, but also has an error like this: `` Tracing client error 401: { "error": { "message": "Incorrect API key provided: unused. You can find your API key at https://platform.openai.com/account/api-keys.", "type": "invalid_request_error", "param": null, "code": "invalid_api_key" } } code ``python import os import httpx import logfire from agents import Agent, ModelSettings, OpenAIProvider, RunConfig, Runner, function_tool from agents.tracing import...
The fix
'Tracing client error 401' when instrumenting openai-agents with logfire while using Ollama, Grok, or another OpenAI-emulating provider happens because logfire double-traces by default: it also sends to OpenAI's /traces/ingest endpoint, which those providers don't implement. Fix: avoid the extra OpenAI-side tracing when you only need logfire, since logfire already captures everything. The 401 is the provider rejecting the unknown endpoint, not a bad API key.
Snippets from the thread
Tracing client error 401: {
"error": {
"message": "Incorrect API key provided: unused. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}Notes
Thread: https://github.com/pydantic/logfire/issues/922. Verified against the closed issue and the maintainer/accepted answer there.
Evidence
In https://github.com/pydantic/logfire/issues/922, the reporter asked: Issue pydantic/logfire#922 (closed, 14 comments): ### Description If I run this code with the correct ENV variables, it sends to logfire, but also has an error like this: `` Tracing client error 401: { "error": { "message": "Incorrect API key provided: unused. You can find your API key at https://platform.openai.com/account/api-keys.", "type": "invalid_request_error", "param": null, "code": "invalid_api_key" } } code ``python import os import httpx import logfire from agents import Agent, ModelSettings, OpenAIProvider, RunConfig, Runner, function_tool from agents.tracing import... The verified answer: 'Tracing client error 401' when instrumenting openai-agents with logfire while using Ollama, Grok, or another OpenAI-emulating provider happens because logfire double-traces by default: it also sends to OpenAI's /traces/ingest endpoint, which those providers don't implement. Fix: avoid the extra OpenAI-side tracing when you only need logfire, since logfire already captures everything. The 401 is the provider rejecting the unknown endpoint, not a bad API key. Source thread: https://github.com/pydantic/logfire/issues/922
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_WkcPXeA52OcdvWK-8ddkrA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">openai-agents doesn't seem to clear GLOBAL_TRACE_PROVIDER list <span>— Vectle</span></a>