fix(auth): resolve timeout when API key uses x-api-key auth style#78
Open
Piyash1 wants to merge 1 commit intoMiniMax-AI:mainfrom
Open
fix(auth): resolve timeout when API key uses x-api-key auth style#78Piyash1 wants to merge 1 commit intoMiniMax-AI:mainfrom
Piyash1 wants to merge 1 commit intoMiniMax-AI:mainfrom
Conversation
- detect-region: probe both Bearer and x-api-key auth styles so region detection succeeds regardless of which header the endpoint accepts. - refresh: add 10s AbortSignal.timeout to refreshAccessToken fetch so a slow/unreachable auth server surfaces a clear error instead of hanging. - handler: catch TimeoutError alongside AbortError and improve timeout hint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users with valid API keys were experiencing timeouts on every request after
running
mmx auth login --api-key sk-xxxxx. The CLI would hang or return"LLM request timed out" even though the same key worked fine with direct
curlcalls.Root Cause (3 bugs)
Bug 1 — Wrong region selected silently (
detect-region.ts)The region detection probe that runs during
mmx auth loginonly sentAuthorization: Bearer <key>headers. Some MiniMax API key types onlyauthenticate via
x-api-keyheader. This caused all region probes to failsilently, fall back to
global, and route every subsequent request to thewrong endpoint — producing timeouts or 401s on all commands.
Bug 2 — Token refresh hangs indefinitely (
refresh.ts)refreshAccessToken()calledfetch()with no timeout signal. If the OAuthtoken endpoint was slow or unreachable, the CLI would freeze with no error
message and no way to recover except Ctrl+C.
Bug 3 — Timeout error was too generic (
handler.ts)When a timeout did occur, the error hint only said "try increasing --timeout".
Users with a correct key and a wrong-region issue had no indication that
region misconfiguration was the likely cause.
Changes
src/config/detect-region.tsprobeRegion()now tries bothAuthorization: Bearerandx-api-keyauth headers per region before giving up
src/auth/refresh.tsAbortSignal.timeout(10_000)to the token refreshfetch()callCLIErrorwithExitCode.AUTHand a clear message distinguishing timeout fromsession expired
src/errors/handler.tsAbortErrorandTimeoutError(the latter is thrown byBun and modern runtimes when
AbortSignal.timeout()fires)mmx auth statusandmmx config set regionas diagnostic steps when a timeout occurs on every request
Testing
Added
test/auth/timeout-fix.test.tscovering:Bearerauthx-api-keyauthglobalwhen key is invalid for all styles/regionsrefreshAccessTokenthrowsCLIErrorwithExitCode.AUTHon non-ok responserefreshAccessTokenreturns fresh tokens on successensureFreshTokenreturns cached token when not near expirymmx auth statusand region hintsReproduction
Related Issues
Closes #[issue number] — "Auth timeout on every request with valid API key"