cli icon indicating copy to clipboard operation
cli copied to clipboard

[bug] request Authorization header uses root-level api_key instead of active profile key; config show disagrees with the wire; config edits have no effect

Open prcuzz opened this issue 1 month ago • 1 comments

CLI version

2.3.1

Skill version (optional)

2.3.1

Node version

n/a (standalone binary install channel, no Node on machine)

OS

Windows 10 10.0.19045 x86_64 (MINGW64/Git Bash)

Region

cn

Command to reproduce

bl video task get --task-id 00000000-0000-0000-0000-000000000000 --verbose

Expected behavior

The Authorization header should match the active profile's api_key — the same key bl config show reports as active — so the request authenticates against the profile's base_url.

Actual behavior

  • The > Auth: mask printed by --verbose matches the ROOT-level api_key [REDACTED root-level key], while the request URL is the PROFILE's base_url (token-plan regional endpoint) → HTTP 401 InvalidApiKey (request_id: 04ad1d6d-68ff-4a1e-ab6b-562fb8956883, a79cdf7b-a2d0-40ed-9e51-59a2daa02c6e).
  • bl config show reports the PROFILE key [REDACTED profile key] as active — the CLI's own config view contradicts what is sent on the wire.
  • Removing the root-level api_key from config.json does NOT change the key sent on the wire (same root-key mask on the next request) → suggests a credential store outside config.json silently takes precedence.
  • Explicit --config <profile> does not change the sent key either.
  • Control experiments: root key + root base_url → HTTP 200; profile endpoint + explicitly passed valid profile key → HTTP 200. Only the mixed pairing (root key + profile endpoint) fails — which is what the CLI produces by itself.
  • Reproduced on both 1.27.0 and 2.3.1 (on 2.3.1 the wrong Auth header is visible in --verbose before the unrelated HTTP crash of #263).

Full output

> GET https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/tasks/00000000-0000-0000-0000-000000000000
> Auth: [REDACTED root-level key]
> x-dashscope-source-config: {"channel":"bailian-cli","tags":{"t1":"public","t2":"bl","t3":"1.27.0"}}
< 401 Unauthorized
request_id: 04ad1d6d-68ff-4a1e-ab6b-562fb8956883

Error:       Invalid API-key provided.
Status:      HTTP 401 (InvalidApiKey)
Exit code:   1

JSON error (optional)


Already tried

  • [x] bl update and skill version aligned with CLI
  • [ ] bl auth status OK for this command
  • [ ] Different network / region — still reproduces

How often does this happen?

Always

How was bl invoked?

Agent (Cursor, Claude, etc.)

Notes (optional)

  • Related: #171 (closed) covered 401s for the upload-policy endpoint under token-plan profiles; this report is about the broader credential precedence/mixing affecting every request.
  • Security/UX concern: a key the user can no longer see or edit in config.json keeps being used; there is no documented way to inspect or clear that external credential store via bl.
  • Attribution: automatically drafted and submitted by the agentic assistant (model: qwen3.8-max) of Qoder CN Desktop v0.4.3 (build 0.4.3.0) on behalf of the account owner, who reviewed and approved the content before submission.

prcuzz avatar Oct 17 '26 05:10 prcuzz

Thanks for the report. This is fixed in 2.7.1. Please upgrade with bl update.

What happened: the API key and the base URL are resolved on separate chains.

  • API key: --api-key > DASHSCOPE_API_KEY > the selected profile's api_key
  • Base URL: --base-url > DASHSCOPE_BASE_URL > the selected profile's base_url

There is no second credential store. If DASHSCOPE_API_KEY is set in the process that launches bl (a shell profile, or an agent session), that key is sent even after the root api_key is removed from config.json, and --config does not override it. The profile base_url is still used when DASHSCOPE_BASE_URL is unset. That mixed pair is what produced 401 InvalidApiKey against the token-plan endpoint. bl config show previously printed only the key stored in the profile, so it disagreed with the request.

2.7.1 makes the effective source visible:

  • bl config show prints both the profile value and DASHSCOPE_API_KEY / DASHSCOPE_BASE_URL when set, and marks the one that will actually be used with (active).
  • When a request's API key and base URL come from different sources, the CLI prints a warning before the call. --quiet suppresses it. --output json emits a warning object with code API_KEY_BASE_URL_SOURCE_MISMATCH.

To send the profile key with the profile base URL, unset DASHSCOPE_API_KEY (and DASHSCOPE_BASE_URL if you set it) in that same environment, then run the command again. bl config show should show the profile api_key as active.

Closing this issue. Please reopen if 2.7.1 still sends a key that bl config show does not mark as active.

hopelynd avatar Oct 30 '26 02:10 hopelynd