{"record":{"id":"4212cf1b1a50805a","repo":"jackwener/OpenCLI","slug":"minimax-region-host-rejected-minimax-api-key","errorCode":null,"errorMessage":"MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}).","messagePattern":"MiniMax (.+?) rejected (.+?) \\(HTTP (.+?)\\)\\.","errorType":"http","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/minimax/utils.js","lineNumber":70,"sourceCode":"                'content-type': 'application/json',\n                accept: 'application/json',\n            },\n            body: JSON.stringify(body),\n            signal: controller.signal,\n        });\n    } catch (error) {\n        if (controller.signal.aborted) {\n            throw new TimeoutError('MiniMax music generation', timeoutSeconds, 'The request may have been accepted; result and billing state are unknown. The API exposes no task id to resume, so check account history before submitting again.');\n        }\n        throw new CommandExecutionError(\n            `MiniMax music request failed: ${error?.message ?? error}`,\n            `Check that ${region.host} is reachable. The request may have reached MiniMax; check account history before retrying.`,\n        );\n    } finally {\n        clearTimeout(timer);\n    }\n    if (response.status === 401 || response.status === 403) {\n        throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}).`);\n    }\n    if (!response.ok) {\n        throw new CommandExecutionError(`MiniMax music returned HTTP ${response.status} from ${region.host}`);\n    }\n    try {\n        return await response.json();\n    } catch (error) {\n        throw new CommandExecutionError(`MiniMax music returned malformed JSON: ${error?.message ?? error}`);\n    }\n}\n\nexport function parseCompletedMusic(payload, region) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('MiniMax music returned a malformed response envelope');\n    }\n    const base = payload.base_resp;\n    if (!base || typeof base !== 'object' || !Number.isInteger(base.status_code)) {\n        throw new CommandExecutionError('MiniMax music response is missing integer base_resp.status_code');","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/minimax/utils.js#L52-L88","documentation":"An AuthRequiredError thrown by generateMusic() when MiniMax responds with HTTP 401 or 403, meaning the Bearer token from MINIMAX_API_KEY was rejected at the HTTP layer. The library classifies this as an auth problem requiring a new/valid key issued for the selected region, distinct from service-level auth codes returned inside the JSON body.","triggerScenarios":"POST to region.endpoint returns status 401 or 403 — e.g. an expired or revoked API key, a key issued for the wrong region (a global api.minimax.io key used against cn api.minimaxi.com or vice versa), a malformed/placeholder key, or a key without music-generation permission.","commonSituations":"Rotated or deleted keys still in the environment; region mismatch between MINIMAX_API_KEY and --region flag; keys pasted with quotes/whitespace or truncated; free-tier accounts lacking access to the music endpoint; org-level key restrictions.","solutions":["Generate a fresh API key in the MiniMax console for the region you are calling (global vs cn) and re-export MINIMAX_API_KEY.","Confirm region alignment: keys for api.minimax.io differ from api.minimaxi.com — match the key to your --region choice.","Re-paste the key carefully without quotes or trailing whitespace, then confirm with: node -e \"console.log(process.env.MINIMAX_API_KEY.slice(0,8))\".","Check the key's permissions/quota in the MiniMax console; ensure the account has music_generation access."],"exampleFix":"// before (cn key against global region)\nexport MINIMAX_API_KEY=\"<cn-region-key>\"\nminimax music --region global ...\n// HTTP 401\n\n// after (key matches region)\nexport MINIMAX_API_KEY=\"<global-region-key>\"\nminimax music --region global ...","handlingStrategy":"try-catch","validationCode":"// sanity-check key shape before calling\nconst key = process.env.MINIMAX_API_KEY ?? '';\nif (!key.trim() || key.length < 20) {\n  throw new Error('MINIMAX_API_KEY looks invalid for this region');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await generateMusic(region, apiKey, body, 60);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error(`Re-export MINIMAX_API_KEY with a key valid for ${e.host} and retry.`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Store region-keyed credentials separately (MINIMAX_API_KEY_GLOBAL vs _CN) and select deliberately.","Rotate keys on a schedule and update the environment immediately after revocation.","Paste keys without surrounding quotes or whitespace.","Verify key entitlements for the music product in the console."],"tags":["auth","http-401","http-403","api-key","region-mismatch"],"backgroundTag":"api-key-rejected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}