fix(cli): set User-Agent on /v1/models probe (Cloudflare 1010)#12906
Closed
farion1231 wants to merge 1 commit into
Closed
fix(cli): set User-Agent on /v1/models probe (Cloudflare 1010)#12906farion1231 wants to merge 1 commit into
farion1231 wants to merge 1 commit into
Conversation
Custom Claude proxies fronted by Cloudflare with Browser Integrity Check
enabled (e.g. `packyapi.com`) reject requests with the default
`Python-urllib/*` signature, returning HTTP 403 "error code: 1010".
`probe_api_models` swallowed that in its blanket `except Exception:
continue`, so `validate_requested_model` returned the misleading
"Could not reach the <provider> API to validate `<model>`" error even
though the endpoint is reachable and lists the requested model.
Advertise the probe request as `hermes-cli/<version>` so Cloudflare
treats it as a first-party client. This mirrors the pattern already used
by `agent/gemini_native_adapter.py` and `agent/anthropic_adapter.py`,
which set a descriptive UA for the same reason.
Reproduction (pre-fix):
python3 -c "
import urllib.request
req = urllib.request.Request(
'https://www.packyapi.com/v1/models',
headers={'Authorization': 'Bearer sk-...'})
urllib.request.urlopen(req).read()
"
urllib.error.HTTPError: HTTP Error 403: Forbidden
(body: b'error code: 1010')
Any non-urllib UA (Mozilla, curl, reqwest) returns 200 with the
OpenAI-compatible models listing.
Tested on macOS (Python 3.11). No cross-platform concerns — the change
is a single header addition to an existing `urllib.request.Request`.
Contributor
|
Merged via PR #12999 (#12999). Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks @farion1231! |
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
probe_api_models(inhermes_cli/models.py) sends requests with Python'sdefault
Python-urllib/3.xUser-Agent. Custom Claude proxies fronted byCloudflare with Browser Integrity Check enabled reject that signature with
HTTP 403
error code: 1010. Because the function wraps the call in ablanket
except Exception: continue, the failure silently degrades to{"models": None}, which surfaces viavalidate_requested_modelas themisleading:
— even though the endpoint is reachable and the model is in its listing.
Fix
Advertise the probe as
hermes-cli/<version>so Cloudflare treats it as afirst-party client. Mirrors the pattern already used in
agent/gemini_native_adapter.py(hermes-agent (gemini-native)) andagent/anthropic_adapter.py(claude-cli/<version> (external, cli)).One-line change in
probe_api_models; version comes fromhermes_cli.__version__(already exported).Reproduction
Before:
With any non-urllib UA (Mozilla, curl, reqwest — I tested all three) the
same request returns 200 with the OpenAI-compatible models listing.
After the fix,
/model claude-opus-4-7 --provider=custom:packy-cc(orwhichever slug the user configured) succeeds end-to-end.