{"record":{"id":"e0eeae01be48e58f","repo":"CherryHQ/cherry-studio","slug":"errordata-error-image-generation-failed","errorCode":null,"errorMessage":"errorData.error || 'Image generation failed'","messagePattern":"errorData\\.error \\|\\| 'Image generation failed'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/provider/custom/ollama/ollamaTransport.ts","lineNumber":73,"sourceCode":"    const fetchImpl = this.fetch ?? fetch\n    const response = await fetchImpl(`${this.baseURL}/generate`, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json', ...this.headers },\n      body: JSON.stringify({\n        model: input.modelId,\n        prompt: input.prompt ?? '',\n        stream: false,\n        ...(width !== undefined && height !== undefined && { width, height }),\n        ...(typeof steps === 'number' && { steps }),\n        ...(input.seed !== undefined && { options: { seed: input.seed } })\n      }),\n      signal: input.signal,\n      ...(this.fetch ? {} : { dispatcher: longRunningDispatcher })\n    } as RequestInit)\n\n    if (!response.ok) {\n      const errorData = await response.json().catch(() => ({ error: `HTTP ${response.status}` }))\n      throw new Error(errorData.error || 'Image generation failed')\n    }\n\n    const data = await response.json()\n    if (!data.image) {\n      return { imageUrls: [] }\n    }\n    // Return the bare base64 payload, not a `data:` URI: the patched `ai` SDK's\n    // generateImage() only auto-downloads strings starting with `http(s)://`;\n    // anything else is passed straight through as `GeneratedFile.data` verbatim\n    // and later base64-decoded as-is, so a `data:image/png;base64,` prefix here\n    // would corrupt the decode with non-base64 characters (`:`, `;`, `,`).\n    return { imageUrls: [data.image] }\n  }\n}\n\nexport function createOllamaTransport(settings: OllamaTransportSettings): OllamaTransport {\n  return new OllamaTransport(settings)\n}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/provider/custom/ollama/ollamaTransport.ts#L55-L91","documentation":"Thrown by OllamaTransport.submit() when POST {baseURL}/generate returns a non-ok response. The error message is taken from the JSON body's `error` field, falling back to 'Image generation failed' (the inner .catch produces `HTTP {status}` if the body isn't JSON). This is the single failure path for Ollama image generation since the transport is synchronous (no polling).","triggerScenarios":"Ollama returns non-2xx from /api/generate. Concrete causes: the requested image model id (e.g. x/z-image-turbo) is not pulled (`model not found`), Ollama is running but on the wrong port, Ollama crashed mid-request, malformed prompt/options, or the model lacks image-generation capability.","commonSituations":"First use before `ollama pull` of the multi-GB image model; baseURL set without the /api suffix or to the wrong host; cold-load crash; Ollama version too old to serve the model.","solutions":["Run `ollama list` and `ollama pull <modelId>` to ensure the image model is present locally.","Confirm Ollama is running and baseURL is correct (the transport appends /generate, so baseURL must include /api).","Read the embedded `error` field — it usually names the exact cause (model not found, out of memory, etc.).","Check Ollama logs for crashes during cold-load of large image models."],"exampleFix":"// before\nconst r = await fetchImpl(`${this.baseURL}/generate`, ...)\nif (!r.ok) throw new Error(errorData.error || 'Image generation failed')\n// after — include status for diagnostics\nif (!r.ok) throw new Error(`Ollama image generation failed (${response.status}): ${errorData.error || response.statusText}`)","handlingStrategy":"validation","validationCode":"// Pre-flight: confirm the model is pulled and Ollama is up\nconst listRes = await fetch(`${baseURL}/tags`)\nif (!listRes.ok) throw new Error(`Ollama not reachable at ${baseURL}`)\nconst { models } = await listRes.json()\nif (!models?.some((m: any) => m.name === modelId)) {\n  throw new Error(`Ollama model '${modelId}' not pulled. Run: ollama pull ${modelId}`)\n}","typeGuard":"export function isOllamaImageError(e: unknown): boolean {\n  return e instanceof Error && /Image generation failed|model not found/i.test(e.message)\n}","tryCatchPattern":"try {\n  await transport.submit(input)\n} catch (e) {\n  if (e instanceof Error && /model not found/i.test(e.message)) {\n    throw new Error(`Ollama image model not pulled. Run: ollama pull ${input.modelId}`)\n  }\n  throw e\n}","preventionTips":["Run `ollama pull <modelId>` before first use; cold-loading multi-GB models takes minutes.","Verify Ollama is running and baseURL includes /api (the transport appends /generate).","Read the embedded `error` field — it names the exact cause."],"tags":["ollama","image-generation","local-server","configuration"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}