Skip to content

fix(minimax): fix streaming by suppressing unsupported anthropic-beta headers and adding Bearer auth#4

Merged
haoruilee merged 2 commits intomainfrom
cursor/minimax-provider-issue-b0de
Mar 14, 2026
Merged

fix(minimax): fix streaming by suppressing unsupported anthropic-beta headers and adding Bearer auth#4
haoruilee merged 2 commits intomainfrom
cursor/minimax-provider-issue-b0de

Conversation

@haoruilee
Copy link
Copy Markdown
Owner

@haoruilee haoruilee commented Mar 14, 2026

Summary

  • Problem: MiniMax streaming doesn't work in TUI — responses appear all at once instead of token-by-token (issue [Bug]: MiniMax streaming not working - output displays all at once instead of streaming openclaw/openclaw#45882).
  • Root cause (streaming): pi-ai unconditionally injects anthropic-beta: fine-grained-tool-streaming-2025-05-14, interleaved-thinking-2025-05-14 into every anthropic-messages request. MiniMax's Anthropic-compatible endpoint does not support these beta features. When these unrecognised headers are present, MiniMax returns the entire response as a single SSE chunk instead of incremental token deltas, which is why the TUI shows the complete response all at once.
  • Root cause (auth): MiniMax's Anthropic-compatible endpoint requires Authorization: Bearer <key>, but the Anthropic SDK sends X-Api-Key: <key> by default. The authHeader: true config flag existed in the schema and was set for MiniMax, but was never consumed at runtime — it was a no-op.
  • What changed: Added createBearerAuthWrapper and resolveProviderAuthHeader in extra-params.ts. When authHeader: true is set on a provider, a stream wrapper: (1) converts X-Api-Key auth to Authorization: Bearer, and (2) nulls out the anthropic-beta header so pi-ai's injected betas don't reach MiniMax. The Anthropic SDK treats null header values as explicit deletions. Added 4 unit tests.
  • What did NOT change: No provider configs, base URLs, or API types modified. Fix is a pure runtime wrapper.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Auth / tokens
  • Gateway / orchestration

Linked Issue/PR

User-visible / Behavior Changes

MiniMax streaming now works correctly in TUI — responses stream token-by-token instead of appearing all at once. No config changes required for existing users.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? Yes — API key is moved from X-Api-Key to Authorization: Bearer for providers with authHeader: true. Key value unchanged, only the header name changes.
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Ubuntu 24.04
  • Model/provider: minimax/MiniMax-M2.5-highspeed
  • Integration/channel: TUI

Steps

  1. Configure MINIMAX_API_KEY
  2. Send a message via TUI using a MiniMax model
  3. Without fix: response appears all at once
  4. With fix: response streams token-by-token

Expected

Response streams token-by-token

Actual (before fix)

Complete response displayed at once — no incremental streaming

Evidence

  • 4 new unit tests in extra-params.bearer-auth.test.ts, all passing; 812-test suite passes
  • Root cause confirmed: Anthropic SDK buildHeaders merge order places options.headers after defaultHeaders, so null values in options.headers delete pi-ai's injected betas (confirmed in SDK source internal/headers.js)

Human Verification (required)

  • Verified: SDK validateHeaders accepts authorization presence; null header values delete earlier headers via buildHeaders
  • Edge cases: no-apiKey passthrough (wrapper is no-op when no key), existing custom headers preserved, non-authHeader providers unaffected
  • Not verified: live MiniMax API call (provided key is expired)

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • Revert commits or set authHeader: false in provider config
  • File: src/agents/pi-embedded-runner/extra-params.ts

Risks and Mitigations

  • Risk: null-header deletion relies on Anthropic SDK internal buildHeaders behaviour
    • Mitigation: Same pattern used by SDK's own validateHeaders; tested with SDK 0.73.0
  • Risk: Suppressing anthropic-beta for all authHeader: true providers could block legitimate future betas for these endpoints
    • Mitigation: Only affects providers that explicitly opt into authHeader: true (third-party Anthropic-compatible endpoints). Standard Anthropic direct uses a different code path.
Open in Web Open in Cursor 

@cursor cursor Bot changed the title fix(minimax): honor authHeader=true by injecting Bearer auth for anthropic-compatible endpoints fix(minimax): fix streaming by suppressing unsupported anthropic-beta headers and adding Bearer auth Mar 14, 2026
@haoruilee haoruilee marked this pull request as ready for review March 14, 2026 10:00
@haoruilee haoruilee merged commit ee06f22 into main Mar 14, 2026
2 of 9 checks passed
haoruilee pushed a commit that referenced this pull request Mar 16, 2026
1. [P1] Treat remap failures as resume failures — if replaceSubagentRunAfterSteer
   returns false, do NOT clear abortedLastRun, increment failed count.

2. [P2] Count scan-level exceptions as retryable failures — set result.failed > 0
   in the outer catch block so scheduleOrphanRecovery retry logic triggers.

3. [P2] Persist resumed-session dedupe across recovery retries — accept
   resumedSessionKeys as a parameter; scheduleOrphanRecovery lifts the Set to
   its own scope and passes it through retries.

4. [Greptile] Use typed config accessors instead of raw structural cast for TLS
   check in lifecycle.ts.

5. [Greptile] Forward gateway.reload.deferralTimeoutMs to deferGatewayRestartUntilIdle
   in scheduleGatewaySigusr1Restart so user-configured value is not silently ignored.

6. [Greptile] Same as #4 — already addressed by the typed config fix.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

[Bug]: MiniMax streaming not working - output displays all at once instead of streaming

2 participants