claude-code - 💡(How to fix) Fix 2.1.118: 401 auth error with custom ANTHROPIC_BASE_URL (third-party provider, worked in 2.1.112) [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52307Fetched 2026-04-24 06:10:39
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×6commented ×2

Error Message

401 error. The key is confirmed valid — direct curl calls to the same endpoint with the same key succeed:

Fix Action

Workaround

Roll back to 2.1.112:

ln -sf ~/.local/share/claude/versions/2.1.112 ~/.local/bin/claude

Code Example

{
  "agents": {
    "providers": {
      "bailian": {
        "extends": "claude",
        "env": {
          "ANTHROPIC_API_KEY": "<bailian-key>",
          "ANTHROPIC_BASE_URL": "https://dashscope.aliyuncs.com/apps/anthropic"
        },
        "models": [
          { "id": "qwen3.6-plus", "label": "Qwen 3.6 Plus", "isDefault": true }
        ]
      }
    }
  }
}

---

curl -X POST https://dashscope.aliyuncs.com/apps/anthropic/v1/messages \
  -H "x-api-key: <key>" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen3.6-plus","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
# Returns valid response ✓

---

ln -sf ~/.local/share/claude/versions/2.1.112 ~/.local/bin/claude
RAW_BUFFERClick to expand / collapse

Bug Description

After auto-updating from 2.1.112 → 2.1.118, Claude Code agents started returning 401 Unauthorized errors when using a custom ANTHROPIC_BASE_URL with a third-party provider (DashScope/Bailian). Rolling back to 2.1.112 immediately fixes the issue.

Environment

  • Claude Code version: 2.1.118 (broken) / 2.1.112 (works)
  • OS: macOS 24.1.0
  • Shell: zsh
  • Launched via: Paseo (Claude Code shell app), agent ID cc798e0f-2f7e-45cf-a733-fa98ee507d15

Configuration

Custom provider configured via agents.json:

{
  "agents": {
    "providers": {
      "bailian": {
        "extends": "claude",
        "env": {
          "ANTHROPIC_API_KEY": "<bailian-key>",
          "ANTHROPIC_BASE_URL": "https://dashscope.aliyuncs.com/apps/anthropic"
        },
        "models": [
          { "id": "qwen3.6-plus", "label": "Qwen 3.6 Plus", "isDefault": true }
        ]
      }
    }
  }
}

Steps to Reproduce

  1. Configure a custom provider with ANTHROPIC_BASE_URL pointing to a non-Anthropic Anthropic-compatible endpoint
  2. Use an API key valid for that endpoint (not a real Anthropic key)
  3. Run Claude Code 2.1.118 with this configuration
  4. Any agent/conversation immediately returns 401 Unauthorized

Expected Behavior

Same as 2.1.112: requests are forwarded to the custom ANTHROPIC_BASE_URL with the provided key, without additional Anthropic-side key validation.

Actual Behavior

401 error. The key is confirmed valid — direct curl calls to the same endpoint with the same key succeed:

curl -X POST https://dashscope.aliyuncs.com/apps/anthropic/v1/messages \
  -H "x-api-key: <key>" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen3.6-plus","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
# Returns valid response ✓

Hypothesis

2.1.118 may have introduced an additional validation/telemetry call against the real Anthropic API (e.g., statsig, usage tracking, or key verification) that runs before or alongside the custom base URL path. This call would use the third-party key against Anthropic's own auth endpoint, causing a 401.

Relevant 2.1.118 changelog entries that might be related:

  • "Fixed /login having no effect in a session launched with CLAUDE_CODE_OAUTH_TOKEN — the env token is now cleared so disk credentials take effect"
  • "Fixed connecting to a remote session overwriting your local model setting"

Workaround

Roll back to 2.1.112:

ln -sf ~/.local/share/claude/versions/2.1.112 ~/.local/bin/claude

extent analysis

TL;DR

The most likely fix is to roll back to Claude Code version 2.1.112, as the issue is introduced in version 2.1.118.

Guidance

  • Verify that the custom ANTHROPIC_BASE_URL and API key are correctly configured in the agents.json file.
  • Test the API key with a direct curl call to the custom endpoint to ensure it is valid, as shown in the issue description.
  • If the issue persists, try setting the CLAUDE_CODE_OAUTH_TOKEN environment variable to an empty string to prevent any potential interference with the custom API key.
  • Consider monitoring the changelog for future updates that may address this issue in version 2.1.118 or later.

Example

No code snippet is provided as the issue is related to configuration and versioning rather than code.

Notes

The root cause of the issue is likely related to the changes introduced in version 2.1.118, possibly due to additional validation or telemetry calls. Rolling back to version 2.1.112 is a reliable workaround, but it may not be a long-term solution.

Recommendation

Apply the workaround by rolling back to version 2.1.112, as it is a reliable and immediate fix for the issue. This will allow for continued use of the custom ANTHROPIC_BASE_URL with the third-party provider until a more permanent solution is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING