jackwener/OpenCLI · error · ConfigError
Missing ${MINIMAX_API_KEY_VAR}
Error message
Missing ${MINIMAX_API_KEY_VAR} What it means
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.
Source
Thrown at clis/minimax/utils.js:18
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { randomUUID } from 'node:crypto';
import { ArgumentError, AuthRequiredError, CommandExecutionError, ConfigError, TimeoutError } from '@jackwener/opencli/errors';
export const MINIMAX_API_KEY_VAR = 'MINIMAX_API_KEY';
export const MUSIC_REGIONS = {
global: { host: 'api.minimax.io', endpoint: 'https://api.minimax.io/v1/music_generation' },
cn: { host: 'api.minimaxi.com', endpoint: 'https://api.minimaxi.com/v1/music_generation' },
};
const AUTH_CODES = new Set([1004, 2049]);
export function requireApiKey() {
const key = String(process.env[MINIMAX_API_KEY_VAR] ?? '').trim();
if (!key) {
throw new ConfigError(
`Missing ${MINIMAX_API_KEY_VAR}`,
`Export an API key issued for the selected MiniMax region as ${MINIMAX_API_KEY_VAR}.`,
);
}
return key;
}
export function buildRequest(options) {
const body = {
model: options.model,
output_format: options.outputFormat,
audio_setting: { format: options.audioFormat },
};
if (options.prompt) body.prompt = options.prompt;
if (options.lyrics) body.lyrics = options.lyrics;
if (options.sampleRate != null) body.audio_setting.sample_rate = options.sampleRate;
if (options.bitrate != null) body.audio_setting.bitrate = options.bitrate;
if (options.instrumental) body.is_instrumental = true;View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before (shell) minimax music --prompt "lofi beat" // Error: Missing MINIMAX_API_KEY // after (shell) export MINIMAX_API_KEY="eyJhbGciOi..." minimax music --prompt "lofi beat"
Defensive patterns
Strategy: validation
Validate before calling
// run before invoking the library
if (!process.env.MINIMAX_API_KEY || !process.env.MINIMAX_API_KEY.trim()) {
throw new Error('Set MINIMAX_API_KEY before calling minimax commands');
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Bilibili user ${mid} is blocked; unblock first before follow
- Browser session required for bilibili subtitle
- Browser page required
- Browser session required for discord-app delete
- Browser session required for gmail attachments
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a0a7421729864d47.
Report an issue: GitHub.