{"record":{"id":"a0a7421729864d47","repo":"jackwener/OpenCLI","slug":"missing-minimax-api-key-var","errorCode":null,"errorMessage":"Missing ${MINIMAX_API_KEY_VAR}","messagePattern":"Missing (.+?)","errorType":"exception","errorClass":"ConfigError","httpStatus":null,"severity":"error","filePath":"clis/minimax/utils.js","lineNumber":18,"sourceCode":"import * as fs from 'node:fs';\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport { randomUUID } from 'node:crypto';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, ConfigError, TimeoutError } from '@jackwener/opencli/errors';\n\nexport const MINIMAX_API_KEY_VAR = 'MINIMAX_API_KEY';\nexport const MUSIC_REGIONS = {\n    global: { host: 'api.minimax.io', endpoint: 'https://api.minimax.io/v1/music_generation' },\n    cn: { host: 'api.minimaxi.com', endpoint: 'https://api.minimaxi.com/v1/music_generation' },\n};\n\nconst AUTH_CODES = new Set([1004, 2049]);\n\nexport function requireApiKey() {\n    const key = String(process.env[MINIMAX_API_KEY_VAR] ?? '').trim();\n    if (!key) {\n        throw new ConfigError(\n            `Missing ${MINIMAX_API_KEY_VAR}`,\n            `Export an API key issued for the selected MiniMax region as ${MINIMAX_API_KEY_VAR}.`,\n        );\n    }\n    return key;\n}\n\nexport function buildRequest(options) {\n    const body = {\n        model: options.model,\n        output_format: options.outputFormat,\n        audio_setting: { format: options.audioFormat },\n    };\n    if (options.prompt) body.prompt = options.prompt;\n    if (options.lyrics) body.lyrics = options.lyrics;\n    if (options.sampleRate != null) body.audio_setting.sample_rate = options.sampleRate;\n    if (options.bitrate != null) body.audio_setting.bitrate = options.bitrate;\n    if (options.instrumental) body.is_instrumental = true;","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/minimax/utils.js#L1-L36","documentation":"A ConfigError thrown by requireApiKey() in clis/minimax/utils.js when the MINIMAX_API_KEY environment variable is unset or contains only whitespace. The library requires a MiniMax API key before any request to the music generation endpoint. It refuses to proceed because every call sends the key as a Bearer token, and an empty key can only produce an auth failure downstream.","triggerScenarios":"Calling any command that resolves an API key via requireApiKey() (through the apiKey helper) while String(process.env.MINIMAX_API_KEY ?? '').trim() yields an empty string — the variable is unset, exported as empty, or contains only spaces.","commonSituations":"Fresh clones where .env is not sourced; running the CLI under cron/CI where the shell profile that exports the key is not loaded; using a different shell (e.g. switching from zsh to sh) that lacks the export; typos like MINIMAX_APIKEY; docker containers started without -e MINIMAX_API_KEY.","solutions":["Export the key: export MINIMAX_API_KEY=\"your-key\" in the current shell before running the command.","Add the export to your shell profile (~/.bashrc, ~/.zshrc) or to the .env file your tooling loads, then restart the shell.","In CI/CD or Docker, pass the variable explicitly (e.g. docker run -e MINIMAX_API_KEY=... or the CI secrets panel).","Verify with: node -e \"console.log(!!process.env.MINIMAX_API_KEY)\" that the variable is visible to Node."],"exampleFix":"// before (shell)\nminimax music --prompt \"lofi beat\"\n// Error: Missing MINIMAX_API_KEY\n\n// after (shell)\nexport MINIMAX_API_KEY=\"eyJhbGciOi...\"\nminimax music --prompt \"lofi beat\"","handlingStrategy":"validation","validationCode":"// run before invoking the library\nif (!process.env.MINIMAX_API_KEY || !process.env.MINIMAX_API_KEY.trim()) {\n  throw new Error('Set MINIMAX_API_KEY before calling minimax commands');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the export in ~/.bashrc or ~/.zshrc and in CI secret config, not ad-hoc per shell.","Add a startup check script that asserts MINIMAX_API_KEY is non-empty before running workflows.","Use dotenv loading in scripts so the key travels with the project environment.","Avoid lookalike variable names; standardize on MINIMAX_API_KEY."],"tags":["config","environment-variable","api-key","precondition"],"backgroundTag":"missing-env-var","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}