Skip to content

fix(auth): use bearer auth for MiniMax Anthropic endpoints - #4002

Closed
kshitijk4poor wants to merge 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/minimax-anthropic-bearer
Closed

fix(auth): use bearer auth for MiniMax Anthropic endpoints#4002
kshitijk4poor wants to merge 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/minimax-anthropic-bearer

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Problem

MiniMax's Anthropic-compatible /anthropic endpoints were failing with HTTP 401 authentication errors in Hermes gateway sessions even when MINIMAX_API_KEY was configured correctly.

The user-visible failure matched MiniMax's auth error exactly:

  • login fail: Please carry the API secret key in the 'Authorization' field of the request header

This broke Telegram and Discord replies for MiniMax-backed sessions.

Root Cause

Hermes routes MiniMax through anthropic_messages mode, but build_anthropic_client() inferred auth mode only from Anthropic token shape:

  • native Anthropic API keys -> x-api-key
  • everything else -> Anthropic OAuth/setup-token bearer flow

MiniMax is Anthropic-compatible at the message API layer, but not at the auth layer. Its /anthropic endpoints expect regular API keys via Authorization: Bearer ..., not Anthropic's native x-api-key header.

Because MiniMax secrets do not use Anthropic's sk-ant-api prefix, Hermes could also misclassify them as Anthropic OAuth/setup tokens and attach Claude Code OAuth headers that do not belong on MiniMax requests.

Fix

  • add _requires_bearer_auth() to detect Anthropic-compatible providers that require bearer auth
  • force MiniMax global and China /anthropic endpoints through auth_token instead of api_key
  • keep native Anthropic auth behavior unchanged
  • check provider-specific bearer handling before Anthropic OAuth token-shape detection
  • add a regression test covering MiniMax's Anthropic endpoint auth path

Testing

  • uv run --with pytest --with pytest-xdist python -m pytest tests/test_anthropic_adapter.py tests/test_run_agent.py -q -k 'anthropic or minimax'
    • 118 passed

Research Notes

Checked the adjacent ecosystem before patching:

  • MiniMax's docs show Authorization: Bearer <key> for ChatCompletion v2 requests
  • bkerf/claude-code-multi configures MiniMax with auth_token
  • MiniMax-AI/Mini-Agent explicitly sets Authorization: Bearer {api_key} even when using Anthropic's SDK
  • OpenClaw has matching bug reports for MiniMax Anthropic-mode 401s caused by incorrect auth-header behavior

@teknium1

Copy link
Copy Markdown
Contributor

Merged via #4028 onto current main. Cherry-picked with authorship preserved. Fixed 3 test values that had display-tool redaction artifacts. MiniMax Anthropic endpoints now correctly use Bearer auth. Thanks @kshitijk4poor!

@teknium1 teknium1 closed this Mar 30, 2026
@kshitijk4poor
kshitijk4poor deleted the fix/minimax-anthropic-bearer branch August 5, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants