CherryHQ/cherry-studio · error · Error

errorData.error || 'Image generation failed'

Error message

errorData.error || 'Image generation failed'

What it means

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).

Source

Thrown at src/main/ai/provider/custom/ollama/ollamaTransport.ts:73

    const fetchImpl = this.fetch ?? fetch
    const response = await fetchImpl(`${this.baseURL}/generate`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', ...this.headers },
      body: JSON.stringify({
        model: input.modelId,
        prompt: input.prompt ?? '',
        stream: false,
        ...(width !== undefined && height !== undefined && { width, height }),
        ...(typeof steps === 'number' && { steps }),
        ...(input.seed !== undefined && { options: { seed: input.seed } })
      }),
      signal: input.signal,
      ...(this.fetch ? {} : { dispatcher: longRunningDispatcher })
    } as RequestInit)

    if (!response.ok) {
      const errorData = await response.json().catch(() => ({ error: `HTTP ${response.status}` }))
      throw new Error(errorData.error || 'Image generation failed')
    }

    const data = await response.json()
    if (!data.image) {
      return { imageUrls: [] }
    }
    // Return the bare base64 payload, not a `data:` URI: the patched `ai` SDK's
    // generateImage() only auto-downloads strings starting with `http(s)://`;
    // anything else is passed straight through as `GeneratedFile.data` verbatim
    // and later base64-decoded as-is, so a `data:image/png;base64,` prefix here
    // would corrupt the decode with non-base64 characters (`:`, `;`, `,`).
    return { imageUrls: [data.image] }
  }
}

export function createOllamaTransport(settings: OllamaTransportSettings): OllamaTransport {
  return new OllamaTransport(settings)
}

View on GitHub (pinned to 726446b54c)

Solutions

  1. Run `ollama list` and `ollama pull <modelId>` to ensure the image model is present locally.
  2. Confirm Ollama is running and baseURL is correct (the transport appends /generate, so baseURL must include /api).
  3. Read the embedded `error` field — it usually names the exact cause (model not found, out of memory, etc.).
  4. Check Ollama logs for crashes during cold-load of large image models.

Example fix

// before
const r = await fetchImpl(`${this.baseURL}/generate`, ...)
if (!r.ok) throw new Error(errorData.error || 'Image generation failed')
// after — include status for diagnostics
if (!r.ok) throw new Error(`Ollama image generation failed (${response.status}): ${errorData.error || response.statusText}`)
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: confirm the model is pulled and Ollama is up
const listRes = await fetch(`${baseURL}/tags`)
if (!listRes.ok) throw new Error(`Ollama not reachable at ${baseURL}`)
const { models } = await listRes.json()
if (!models?.some((m: any) => m.name === modelId)) {
  throw new Error(`Ollama model '${modelId}' not pulled. Run: ollama pull ${modelId}`)
}

Type guard

export function isOllamaImageError(e: unknown): boolean {
  return e instanceof Error && /Image generation failed|model not found/i.test(e.message)
}

Try / catch

try {
  await transport.submit(input)
} catch (e) {
  if (e instanceof Error && /model not found/i.test(e.message)) {
    throw new Error(`Ollama image model not pulled. Run: ollama pull ${input.modelId}`)
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/e0eeae01be48e58f. Report an issue: GitHub.