Qwen Code 401 checklist

Qwen Code 401 usually means your key, plan, region and endpoint do not match.

Before changing random settings, split the problem into three routes: Coding Plan, DashScope OpenAI-compatible, and OAuth. The same visible Qwen model can fail if the request is sent to the wrong host for the key you generated.

Need one working OpenAI-compatible route now?

Use this only if the official Qwen/DashScope account, payment, or region setup is blocking you. Pay $5, create an account, send the receipt, and get manually credited for one real request.

Do not paste real API keys into GitHub issues. Share only the endpoint host, auth type, model id, region, and whether the key prefix matches the plan.

1. Match the key to the host

Route Typical host Typical env key Common 401 cause
Alibaba Coding Plan, China https://coding.dashscope.aliyuncs.com/v1 BAILIAN_CODING_PLAN_API_KEY Using an international or standard DashScope key on the coding-plan route.
Alibaba Coding Plan, International https://coding-intl.dashscope.aliyuncs.com/v1 BAILIAN_CODING_PLAN_API_KEY Using a key from a different plan, region, or dashboard.
DashScope OpenAI-compatible, China https://dashscope.aliyuncs.com/compatible-mode/v1 DASHSCOPE_API_KEY Using Coding Plan keys or an international Model Studio key.
DashScope OpenAI-compatible, International https://dashscope-intl.aliyuncs.com/compatible-mode/v1 DASHSCOPE_API_KEY Model/workspace not authorized, payment not active, or endpoint-region mismatch.

2. Test the exact route outside Qwen Code

If raw curl fails with 401, Qwen Code is probably not the first thing to debug.

curl https://coding-intl.dashscope.aliyuncs.com/v1/chat/completions \
  -H "Authorization: Bearer $BAILIAN_CODING_PLAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.5-plus",
    "messages": [{"role": "user", "content": "hi"}]
  }'

For DashScope OpenAI-compatible keys, use the compatible-mode host instead:

curl https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-plus",
    "messages": [{"role": "user", "content": "hi"}]
  }'

3. If curl works but Qwen Code fails

  1. Run /about and confirm the final Auth, Base URL, and Model.
  2. Check shell overrides: echo $BAILIAN_CODING_PLAN_API_KEY, echo $DASHSCOPE_API_KEY, and echo $OPENAI_API_KEY.
  3. Inspect ~/.qwen/settings.json for stale OAuth or old provider entries.
  4. Keep Coding Plan, DashScope compatible-mode, OpenRouter, and custom OpenAI-compatible routes as separate provider entries.
  5. Restart the terminal after env changes so Qwen Code does not reuse stale variables.

4. If the official provider account is the blocker

If the blocker is not Qwen Code but provider onboarding, payment method, workspace authorization, or non-mainland verification, use a small independent OpenAI-compatible test route before committing more time.

Black Eagle AI is an independent gateway, not an official Alibaba or Qwen partner. It is useful when you need one prepaid Chinese-model route to verify the client workflow while sorting out direct provider access.

curl https://api.blackeaglecambodia.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-black-eagle-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Say hello in one sentence."}]
  }'
See the $5 starter flow Qwen Code setup guide No China phone guide Billing FAQ