jackwener/OpenCLI · error · CommandExecutionError
Midjourney history endpoint returned a malformed payload
Error message
Midjourney history endpoint returned a malformed payload
What it means
fetchHistoryPage calls /api/imagine with user_id, page_size, and optional cursor, then validates the payload. It throws CommandExecutionError if the response is not an object with an Array 'data' field, since pagination cannot proceed without the expected rows/cursor structure.
Source
Thrown at clis/midjourney/utils.js:326
throw new CommandExecutionError(
'No Midjourney generation credits remain for this billing period.',
`Check usage at ${MIDJOURNEY_URL}/account.`,
);
}
}
export async function fetchHistory(page, userId, limit = 20) {
return (await fetchHistoryPage(page, userId, limit)).data;
}
export async function fetchHistoryPage(page, userId, limit = 20, cursor = null) {
const cursorQuery = cursor ? `&cursor=${encodeURIComponent(cursor)}` : '';
const payload = await midjourneyJson(
page,
`/api/imagine?user_id=${encodeURIComponent(userId)}&page_size=${encodeURIComponent(limit)}${cursorQuery}`,
);
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.data)) {
throw new CommandExecutionError('Midjourney history endpoint returned a malformed payload');
}
return {
data: payload.data,
cursor: stringOrNull(payload.cursor),
checkpoint: stringOrNull(payload.checkpoint),
};
}
export async function fetchJobStatuses(page, jobIds) {
if (!Array.isArray(jobIds) || !jobIds.length) return [];
const payload = await midjourneyJson(page, '/api/job-status', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: { jobIds, _frontend_source: 'opencli_adapter' },
});
if (!Array.isArray(payload)) {
throw new CommandExecutionError('Midjourney job-status endpoint returned a malformed payload');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Log the raw payload from /api/imagine to inspect the actual shape.
- Re-authenticate in Chrome and retry to rule out an auth-related error envelope.
- Verify the user_id passed to fetchHistoryPage matches getMidjourneyAccount's user_id.
- If the API shape changed (e.g. data renamed), update the CLI's history parsing and response validation.
Example fix
// before
const page = await fetchHistoryPage(mjPage, userId, { limit: 20 });
// after
const raw = await midjourneyJson(mjPage, `/api/imagine?user_id=${userId}&page_size=20`);
if (!raw || !Array.isArray(raw.data)) console.error('unexpected history payload:', raw);
const page = await fetchHistoryPage(mjPage, userId, { limit: 20 }); Defensive patterns
Strategy: type-guard
Validate before calling
const payload = await midjourneyJson(page, `/api/imagine?user_id=${userId}&page_size=20`);
if (payload == null || typeof payload !== 'object' || !Array.isArray(payload.data)) console.error('unexpected history payload', payload); Type guard
function isHistoryPayload(value) {
return value != null && typeof value === 'object' && !Array.isArray(value) && Array.isArray(value.data);
} Try / catch
try {
const pageData = await fetchHistoryPage(page, userId, { limit: 20 });
} catch (err) {
if (/history endpoint returned a malformed payload/.test(err.message)) {
console.error('History API shape unexpected; re-authenticate or update the CLI parser.');
} else throw err;
} Prevention
- Validate user_id comes from a live getMidjourneyAccount call
- Log raw history responses to catch API contract changes early
- Re-authenticate before long history crawls
- Guard pagination loops with the payload type guard before reading cursor/checkpoint
When it happens
Trigger: The history endpoint returns null, a non-object, an object without data, or data is not an array — e.g. auth interstitial JSON, API contract change, empty error body, or wrong user_id parameter causing an error envelope.
Common situations: Midjourney renaming or nesting the history response (e.g. data moved under results), Cloudflare challenge JSON, expired session returning an error object without data, or passing a malformed userId.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Midjourney subscription endpoint returned a malformed payloa
- Bilibili view API did not return pages[] for --page selectio
- 分P 序号超出范围:p=${pageNum}(该视频共 ${total} 集)
- Chess.com stats payload for ${kind} is not an object
- Chess.com stats payload for ${kind}.last is not an object
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/53bd196158ee857c.
Report an issue: GitHub.