jackwener/OpenCLI · error · AuthRequiredError
MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP
Error message
MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}). What it means
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.
Source
Thrown at clis/minimax/utils.js:70
'content-type': 'application/json',
accept: 'application/json',
},
body: JSON.stringify(body),
signal: controller.signal,
});
} catch (error) {
if (controller.signal.aborted) {
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.');
}
throw new CommandExecutionError(
`MiniMax music request failed: ${error?.message ?? error}`,
`Check that ${region.host} is reachable. The request may have reached MiniMax; check account history before retrying.`,
);
} finally {
clearTimeout(timer);
}
if (response.status === 401 || response.status === 403) {
throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}).`);
}
if (!response.ok) {
throw new CommandExecutionError(`MiniMax music returned HTTP ${response.status} from ${region.host}`);
}
try {
return await response.json();
} catch (error) {
throw new CommandExecutionError(`MiniMax music returned malformed JSON: ${error?.message ?? error}`);
}
}
export function parseCompletedMusic(payload, region) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError('MiniMax music returned a malformed response envelope');
}
const base = payload.base_resp;
if (!base || typeof base !== 'object' || !Number.isInteger(base.status_code)) {
throw new CommandExecutionError('MiniMax music response is missing integer base_resp.status_code');View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before (cn key against global region) export MINIMAX_API_KEY="<cn-region-key>" minimax music --region global ... // HTTP 401 // after (key matches region) export MINIMAX_API_KEY="<global-region-key>" minimax music --region global ...
Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check key shape before calling
const key = process.env.MINIMAX_API_KEY ?? '';
if (!key.trim() || key.length < 20) {
throw new Error('MINIMAX_API_KEY looks invalid for this region');
} Try / catch
try {
const res = await generateMusic(region, apiKey, body, 60);
} catch (e) {
if (e instanceof AuthRequiredError) {
console.error(`Re-export MINIMAX_API_KEY with a key valid for ${e.host} and retry.`);
process.exitCode = 2;
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Gmail ${operation} returned HTTP ${status}
- 未登录或登录已过期,请先在浏览器中登录贝壳找房
- LinkedIn Learning auth failed (HTTP ${result.status ?? ''}).
- MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (serv
- NotebookLM RPC returned auth error (${errorCode})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4212cf1b1a50805a.
Report an issue: GitHub.