jackwener/OpenCLI · error · CommandExecutionError

MiniMax music returned malformed JSON: ${error?.message ?? e

Error message

MiniMax music returned malformed JSON: ${error?.message ?? error}

What it means

A CommandExecutionError thrown by generateMusic() when response.json() rejects — the endpoint returned an HTTP 2xx response whose body is not valid JSON (or the body was already consumed). The library treats this as a protocol violation: a successful music generation response must always be JSON with a base_resp envelope.

Source

Thrown at clis/minimax/utils.js:78

            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');
    }
    if (base.status_code !== 0) {
        const message = typeof base.status_msg === 'string' && base.status_msg.trim()
            ? `: ${base.status_msg.trim()}`
            : '';
        if (AUTH_CODES.has(base.status_code)) {
            throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (service ${base.status_code}${message}).`);
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Capture the raw response body (e.g. curl the endpoint with your key) to see what non-JSON content is actually returned.
  2. Disable or bypass any TLS-intercepting proxy/antivirus that may rewrite the response, then retry.
  3. Retry on a stable network; truncated bodies are usually transient transport problems.
  4. Verify region.endpoint was not overridden to a non-MiniMax URL (check MUSIC_REGIONS config).

Example fix

// diagnose outside the CLI
curl -s -H "authorization: Bearer $MINIMAX_API_KEY" \
  -H 'content-type: application/json' \
  -d '{...}' https://api.minimax.io/v1/music_generation | head -c 500

// if HTML appears, fix the proxy or use a direct connection instead of retrying blind
Defensive patterns

Strategy: fallback

Try / catch

try {
  const payload = await generateMusic(region, apiKey, body, 60);
} catch (e) {
  if (e instanceof CommandExecutionError && /malformed JSON/.test(e.message)) {
    // bypass suspect proxy, verify endpoint URL, then retry once
  } else throw e;
}

Prevention

When it happens

Trigger: await response.json() throws inside generateMusic()'s try/catch after a 2xx status — truncated/garbled response body, an HTML error page from a proxy/CDN served with 200, empty body, or mismatched content-type causing a JSON parse failure.

Common situations: Transparent proxies or captive portals injecting HTML with 200; TLS-intercepting appliances; body truncation on flaky mobile networks; pointing the endpoint at a wrong/gateway URL in a modified region config.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f79743cb8e2a026c. Report an issue: GitHub.