fix(auth): support modern Qwen CLI v0.18+ API-key authentication - #46851
Open
liuhao1024 wants to merge 1 commit into
Open
liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
Qwen CLI v0.18+ removed the 'qwen auth qwen-oauth' command and stores credentials in ~/.qwen/settings.json with DASHSCOPE_API_KEY instead of the legacy ~/.qwen/oauth_creds.json OAuth flow. - Add _try_read_qwen_settings_api_key() to read API key from settings.json - Fall back to settings.json when oauth_creds.json is missing - Skip OAuth refresh logic for API-key auth (no expiry, no refresh token) - Update error messages to remove references to deprecated CLI command - Add 10 new tests for settings.json fallback and API-key auth flow Fixes NousResearch#46771
1 task
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for adding coverage for the modern Qwen CLI credential file. The compatibility gap is real on current main: hermes_cli/auth.py:2220-2227 only accepts oauth_creds.json.
Problems
hermes_cli/auth.py:2167setsshould_refresh = bool(force_refresh)even forqwen-settings-json; thereforeforce_refresh=Truestill invokes OAuth refresh at line 2171, contrary to the new no-refresh contract. The added test attests/hermes_cli/test_auth_qwen_provider.py:562-582covers onlyrefresh_if_expiring=True.- The new parser recognizes
selectedType=openai(hermes_cli/auth.py:1970) but returns it throughqwen-oauthwith the Portal base URL (hermes_cli/auth.py:2180-2183). Current main defines that endpoint ashttps://portal.qwen.ai/v1(hermes_cli/auth.py:96), while the documentedDASHSCOPE_API_KEYpath is the distinct Alibaba/DashScope provider (website/docs/integrations/providers.md:430-431).
Suggested changes
- Suppress refresh when the source is settings.json even if
force_refresh=True, with a direct regression test. - Preserve the API-key route's provider and endpoint explicitly, and test final provider/base-URL resolution rather than only credential parsing.
Automated hermes-sweeper review.
| # API-key auth (from settings.json) has no expiry or refresh token — | ||
| # skip OAuth refresh logic entirely. | ||
| is_api_key_auth = tokens.get("source") == "qwen-settings-json" | ||
| should_refresh = bool(force_refresh) |
Collaborator
There was a problem hiding this comment.
force_refresh=True still makes this API-key credential enter _refresh_qwen_cli_tokens() at line 2171. Gate this initialization on not is_api_key_auth too, and add a force-refresh regression test.
5 tasks
1 task
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.
What does this PR do?
Adds support for modern Qwen CLI v0.18+ API-key authentication. When the legacy
oauth_creds.jsonfile is absent, Hermes now falls back to reading the API key from~/.qwen/settings.json(where Qwen CLI v0.18+ stores credentials). Also updates error messages to remove references to the deprecatedqwen auth qwen-oauthcommand.Related Issue
Fixes #46771
Type of Change
Changes Made
hermes_cli/auth.py: Add_try_read_qwen_settings_api_key()helper that reads API key from~/.qwen/settings.json; modify_read_qwen_cli_tokens()to fall back to settings.json whenoauth_creds.jsonis missing; modifyresolve_qwen_runtime_credentials()to skip OAuth refresh for API-key auth (no expiry, no refresh token); update 4 error messages to remove deprecatedqwen auth qwen-oauthreferenceshermes_cli/model_setup_flows.py: Update guidance message from deprecated command to modern DASHSCOPE_API_KEY setuphermes_cli/status.py: Update status display message for not-logged-in statetests/hermes_cli/test_auth_qwen_provider.py: Add 10 new tests covering settings.json fallback (nested auth, top-level key, DASHSCOPE_API_KEY, missing file, no key, invalid JSON), fallback integration, refresh skip, and auth statusHow to Test
pytest tests/hermes_cli/test_auth_qwen_provider.py -v— all 41 tests pass~/.qwen/settings.jsonwith{"security": {"auth": {"apiKey": "test-key"}}}and verifyhermes auth statusshows Qwen as logged inoauth_creds.jsonandsettings.jsonare absent, the error message says "Set DASHSCOPE_API_KEY" instead of "Run 'qwen auth qwen-oauth'"Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
hermes_cli/auth.py_read_qwen_cli_tokens,_try_read_qwen_settings_api_key,resolve_qwen_runtime_credentials