CherryHQ/cherry-studio · error · Error
Image generation failed
Error message
Image generation failed
What it means
Thrown by AiService.generateImage when an image-generation job finishes in a non-completed, non-cancelled state (i.e. 'failed', or any unrecognized terminal status). The fallback string 'Image generation failed' is used only when snapshot.error?.message is empty/falsy — the code uses || (not ??) deliberately so that a vendor returning a non-OK response with an empty body still surfaces a human-readable message rather than a message-less Error. A cancelled job throws an AbortError DOMException instead and never reaches this line.
Source
Thrown at src/main/ai/AiService.ts:960
let snapshot: JobSnapshot
try {
snapshot = await handle.finished
} finally {
signal?.removeEventListener('abort', onAbort)
}
if (snapshot.status === 'completed') {
const output = snapshot.output as ImageGenerationJobOutput | null
return { files: output?.files ?? [] }
}
if (snapshot.status === 'cancelled') {
throw new DOMException('Image generation aborted', 'AbortError')
}
// `||` not `??`: a job can fail with an empty-string error message (a vendor that
// returns a non-OK response with no body), which would otherwise surface as a
// message-less `Error` the renderer can't show.
throw new Error(snapshot.error?.message || 'Image generation failed')
}
// ── Embedding ──
async embedMany(request: AsInProcess<AiEmbedRequest>): Promise<AiEmbedResult> {
logger.info('embedMany started', { assistantId: request.assistantId, count: request.values.length })
const signal = request.requestOptions?.signal
const { sdkConfig, credentialReceipt, provider, model, assistant } = await this.buildAgentParamsFor(request, signal)
const usageContext = createCaptureContext({
provider,
model,
sdkModelId: sdkConfig.modelId,
credentialReceipt,
source: sourceSnapshotForAssistant(assistant),
messageRef: null
})
View on GitHub (pinned to 726446b54c)
Solutions
- Inspect snapshot.error?.message in logs (or the toast) — if present it carries the vendor's reason; address that root cause (auth, quota, content policy).
- Verify the provider credentials and base URL are correct and that the selected model supports image generation.
- Retry after ruling out a transient vendor error; for rate limits, back off.
- If the message is the generic fallback (empty vendor message), enable request/response logging for the image provider to capture the raw vendor response and adjust the request accordingly.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const result = await aiService.generateImage(req, { signal })
// use result.files
} catch (err) {
if (err instanceof DOMException && err.name === 'AbortError') {
// user cancelled — handle gracefully
return
}
// surfaced vendor/generic error — show err.message to the user, offer retry
showErrorToast(err instanceof Error ? err.message : 'Image generation failed')
} Prevention
- Validate provider credentials, base URL, and model id before invoking image generation.
- Handle AbortError separately so user-cancelled jobs do not show as failures.
- Log snapshot.error?.message and the raw vendor response when the message is the generic fallback, to diagnose empty-body vendor errors.
- Retry transient vendor errors with backoff, but surface auth/quota/content-policy errors to the user.
When it happens
Trigger: The underlying image vendor returned an error (rate limit, auth failure, content-policy rejection, malformed request, model unavailable); the job handler threw during processing; the network request errored; or the vendor returned a non-OK status with no error body, yielding the generic fallback message.
Common situations: Expired or invalid API key; exceeded quota/rate limit; prompt rejected by content filter; unsupported image model id; vendor outage or 5xx; misconfigured base URL pointing at a non-image endpoint; malformed request payload (wrong parameters for the selected model).
Related errors
- Failed to generate image: ${error.message}
- Failed to resolve image model: ${modelId} for provider: ${pr
- Unsupported agent runtime type: ${entry.agentType}
- OpenAI-compatible reranking model only supports text documen
- Rerank response must contain a results array
AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12).
Data as JSON: /api/errors/cc1c2f1d5a88f579.
Report an issue: GitHub.