Skip to content

fix(run_agent): use public default_headers attr when preserving routed client headers#8799

Closed
andrewhosf wants to merge 1 commit into
NousResearch:mainfrom
andrewhosf:fix-default-headers-attr
Closed

fix(run_agent): use public default_headers attr when preserving routed client headers#8799
andrewhosf wants to merge 1 commit into
NousResearch:mainfrom
andrewhosf:fix-default-headers-attr

Conversation

@andrewhosf

Copy link
Copy Markdown
Contributor

Problem

In run_agent.py, when falling back to the centralized provider router (resolve_provider_client), the code attempts to preserve the default_headers that the router may have set on the returned OpenAI client. However, it checks for the private attribute ._default_headers instead of the public .default_headers attribute exposed by the OpenAI Python SDK.

Because hasattr(_routed_client, '_default_headers') is always False on current versions of the openai package, the routed client's headers are silently dropped. This causes API requests to Kimi (and potentially other providers that rely on default_headers) to fail with an HTTP 403 because the required User-Agent: KimiCLI/1.30.0 header is missing.

Closes #8779

Change

- if hasattr(_routed_client, '_default_headers') and _routed_client._default_headers:
-     client_kwargs["default_headers"] = dict(_routed_client._default_headers)
+ if hasattr(_routed_client, 'default_headers') and _routed_client.default_headers:
+     client_kwargs["default_headers"] = dict(_routed_client.default_headers)

The codebase already correctly uses getattr(fb_client, "default_headers", None) elsewhere (line 5514), so this just brings the provider-router fallback branch in line with the rest of the file.

Verification

  • Confirmed that openai.OpenAI instances expose default_headers as a public attribute in openai>=1.0
  • With this change, Kimi Coding requests correctly include User-Agent: KimiCLI/1.30.0 and no longer return 403

…d client headers

The OpenAI Python SDK stores default headers on the public
 attribute, not the private .
Because the code checked for the private attribute, provider-specific
headers (e.g. Kimi's User-Agent) were silently dropped, causing 403
errors for Kimi Coding API users.

Fixes NousResearch#8779
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/kimi Kimi / Moonshot duplicate This issue or pull request already exists labels Apr 28, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8784 — same fix: _default_headers to default_headers in routed client header preservation. Both fix #8779.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8784

@andrewhosf

Copy link
Copy Markdown
Contributor Author

Stale — the buggy code no longer exists in main. Already fixed upstream.

@andrewhosf andrewhosf closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: run_agent.py uses _default_headers instead of default_headers, dropping routed client headers and breaking Kimi API

2 participants