fix: add configurable User-Agent for custom providers - #24306
Closed
wait4xx wants to merge 1 commit into
Closed
Conversation
…dpoints
Third-party API proxies often sit behind Cloudflare or similar WAFs
that block SDK User-Agent strings (Anthropic/Python, OpenAI/Python),
causing HTTP 403 errors on every request.
Add optional field to custom_providers config, defaulting
to 'hermes-agent' for third-party endpoints.
Changes across 4 files (37 lines):
- agent/anthropic_adapter.py: add user_agent param to
build_anthropic_client(), with input validation (truncate 256 chars,
strip CR/LF to prevent HTTP header injection)
- hermes_cli/runtime_provider.py: read user_agent from custom provider
config in both new-style (providers: dict) and legacy
(custom_providers: list) resolution paths
- gateway/run.py: pass user_agent through runtime kwargs pipeline
including the fallback provider path
- run_agent.py: accept user_agent in AIAgent.__init__(), store as
self._user_agent, and propagate to all 8 build_anthropic_client()
call sites (init, OAuth refresh, credential pool rotation, rebuild,
fallback activation, session recovery)
Config example:
custom_providers:
- name: my-proxy
base_url: https://example.com
api_mode: anthropic_messages
user_agent: my-custom-agent # optional, defaults to 'hermes-agent'
Collaborator
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.
Summary
Fixes #24293
Third-party API proxies behind Cloudflare WAFs block SDK User-Agent
strings, causing HTTP 403 errors. This PR adds an optional
user_agentfield to
custom_providersconfig that overrides the SDK's defaultUser-Agent.
Changes
agent/anthropic_adapter.pyuser_agentparam tobuild_anthropic_client()hermes_cli/runtime_provider.pyuser_agentfrom config (both providers: dict and custom_providers: list paths)gateway/run.pyuser_agentthrough runtime kwargs + fallback providerrun_agent.pyuser_agentto all 8build_anthropic_client()call sitesConfig Usage
Safety
str | None = NoneTest Plan
https://ai.tvt.wiki) behind Cloudflare — requests now return 200 instead of 403anthropic_messagesmode (Anthropic SDK path)chat_completionsmode (OpenAI SDK path)'hermes-agent'is used whenuser_agentis not configured