{"record":{"id":"23d51658f7945d6c","repo":"jackwener/OpenCLI","slug":"minimax-region-host-rejected-minimax-api-key-23d516","errorCode":null,"errorMessage":"MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (service ${base.status_code}${message}).","messagePattern":"MiniMax (.+?) rejected (.+?) \\(service (.+?)(.+?)\\)\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/minimax/utils.js","lineNumber":95,"sourceCode":"    } 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');\n    }\n    if (base.status_code !== 0) {\n        const message = typeof base.status_msg === 'string' && base.status_msg.trim()\n            ? `: ${base.status_msg.trim()}`\n            : '';\n        if (AUTH_CODES.has(base.status_code)) {\n            throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (service ${base.status_code}${message}).`);\n        }\n        throw new CommandExecutionError(`MiniMax music failed (service ${base.status_code}${message})`);\n    }\n    const data = payload.data;\n    if (!data || typeof data !== 'object' || Array.isArray(data) || !Number.isInteger(data.status)) {\n        throw new CommandExecutionError('MiniMax music response is missing integer data.status');\n    }\n    if (data.status === 1) {\n        const traceId = typeof payload.trace_id === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(payload.trace_id.trim())\n            ? payload.trace_id.trim()\n            : '';\n        throw new CommandExecutionError(\n            `MiniMax music returned status 1 (in progress) without a resumable task id${traceId ? ` (trace_id: ${traceId})` : ''}`,\n            'Do not resubmit blindly: this endpoint exposes no query command, so check MiniMax account history first.',\n        );\n    }\n    if (data.status !== 2) {\n        throw new CommandExecutionError(`MiniMax music returned unknown data.status ${data.status}`);","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/minimax/utils.js#L77-L113","documentation":"An AuthRequiredError thrown by parseCompletedMusic() when the response body reports a service-level auth failure: base_resp.status_code is 1004 or 2049 (the AUTH_CODES set). Even though HTTP status was 2xx, MiniMax rejected the API key at the application layer, so the library demands a valid key for the region.","triggerScenarios":"The music_generation endpoint returns HTTP 200 with base_resp.status_code 1004 (invalid/missing API key) or 2049 (insufficient balance/quota auth rejection), with an optional status_msg appended to the message.","commonSituations":"Expired or revoked key still exported in the environment; cn-region key used against the global host or vice versa; account balance exhausted (2049 commonly indicates billing/quota); key without music product entitlement.","solutions":["Regenerate a valid API key for the correct region in the MiniMax console and re-export MINIMAX_API_KEY.","If status_code is 2049, top up or verify your MiniMax account balance/quota for the music product.","Match the region: ensure the key belongs to the host in use (api.minimax.io vs api.minimaxi.com).","Re-run and inspect the appended status_msg for the exact rejection reason."],"exampleFix":"// before\n// service 2049: balance exhausted\nminimax music --prompt \"ambient\"\n\n// after topping up / reissuing key\nexport MINIMAX_API_KEY=\"<new-key>\"\nminimax music --prompt \"ambient\"","handlingStrategy":"try-catch","validationCode":"// pre-check balance/quota in console or via account API before long jobs\n// and ensure key matches region host\nconst key = process.env.MINIMAX_API_KEY ?? '';\nif (!key.trim()) throw new Error('Export MINIMAX_API_KEY for the selected region');","typeGuard":null,"tryCatchPattern":"try {\n  const done = parseCompletedMusic(payload, region);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error(`Service-level auth rejection from ${e.host}: reissue key or top up balance.`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Monitor MiniMax account balance before batch generation runs.","Keep keys fresh and region-matched to the host being called.","Treat codes 1004/2049 as credential/billing signals, not transient errors.","Rotate and re-export keys promptly after revocation."],"tags":["auth","api-key","service-error","billing","region-mismatch"],"backgroundTag":"api-key-rejected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}