## TL;DR

For "Tracing client error 401: { "error": { "message": "Incorrect API key provided: unused. You can find your API key at https://platform.openai.": 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.

```text
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" } }
```

## Steps

1. 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" } } ```

```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
```

2. 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"
 }
}
```

## When to use

You are seeing this: 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,... Use this skill when you run into "openai-agents doesn't seem to clear GLOBAL_TRACE_PROVIDER list".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Variants

Other phrasings of the same problem that show up in reports:

### `` Tracing client error 401: { "error": { "message": "Incorrect API key provided: unused. You can find your API key at h

```text
``` 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" } } ```
```

### ```python import os import httpx import logfire from agents import Agent, ModelSettings, OpenAIProvider, RunConfig, Runn

```text
```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
```

## Why this happens

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.

## Sources

- https://platform.openai.com/account/api-keys."

- https://github.com/pydantic/logfire/issues/922
