fix(run_agent): use public default_headers attr when preserving routed client headers#8799
Closed
andrewhosf wants to merge 1 commit into
Closed
fix(run_agent): use public default_headers attr when preserving routed client headers#8799andrewhosf wants to merge 1 commit into
andrewhosf wants to merge 1 commit into
Conversation
…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
Collaborator
Collaborator
|
Likely duplicate of #8784 |
Contributor
Author
|
Stale — the buggy code no longer exists in main. Already fixed upstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
run_agent.py, when falling back to the centralized provider router (resolve_provider_client), the code attempts to preserve thedefault_headersthat the router may have set on the returned OpenAI client. However, it checks for the private attribute._default_headersinstead of the public.default_headersattribute exposed by the OpenAI Python SDK.Because
hasattr(_routed_client, '_default_headers')is alwaysFalseon current versions of theopenaipackage, the routed client's headers are silently dropped. This causes API requests to Kimi (and potentially other providers that rely ondefault_headers) to fail with an HTTP 403 because the requiredUser-Agent: KimiCLI/1.30.0header is missing.Closes #8779
Change
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
openai.OpenAIinstances exposedefault_headersas a public attribute inopenai>=1.0User-Agent: KimiCLI/1.30.0and no longer return 403