linshenkx/prompt-optimizer · error · ImageError

GENERATION_FAILED

GENERATION_FAILED

Error message

${errorMessage}

What it means

When the HTTP response from Ollama's image endpoint is not ok, doGenerate throws GENERATION_FAILED with errorMessage extracted from the JSON body's error.message (falling back to a status-based default).

Source

Thrown at packages/core/src/services/image/adapters/ollama.ts:178

    }

    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload)
    })

    if (!response.ok) {
      let errorMessage = `Ollama API error: ${response.status} ${response.statusText}`
      try {
        const errorData = await response.json()
        if (typeof errorData?.error?.message === 'string') {
          errorMessage = errorData.error.message
        }
      } catch {
        // ignore JSON parse errors
      }
      throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, errorMessage)
    }

    const json = await response.json()
    return this.parseImageResponse(json, config)
  }

  private parseImageResponse(response: any, config: ImageModelConfig): ImageResult {
    if (!response?.data || !Array.isArray(response.data)) {
      throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)
    }

    const images = response.data.map((item: any) => {
      if (!item?.b64_json || typeof item.b64_json !== 'string') {
        throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)
      }
      const dataUrl = `data:image/png;base64,${item.b64_json}`
      return {
        b64: item.b64_json,

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Read the embedded error message from Ollama's response
  2. Verify the model is pulled and supports image generation (ollama pull / model list)
  3. Upgrade Ollama to a version with the images API enabled
  4. Simplify paramOverrides to isolate rejected parameters
Defensive patterns

Strategy: try-catch

Validate before calling

if (!/^[\w:.-]+$/.test(config.modelId)) throw new Error('invalid Ollama model id')

Try / catch

try { ... } catch (e) {
  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.GENERATION_FAILED) {
    if (/not found|pull/i.test(e.message)) hint('ollama pull <model>')
  }
}

Prevention

When it happens

Trigger: Ollama returns 4xx/5xx from its experimental OpenAI-compatible images endpoint — model not pulled, endpoint not enabled in the Ollama version, connection refused surfaced as HTTP error from a proxy, or invalid parameters.

Common situations: Ollama version predating the experimental images API, referencing a multimodal model without image-generation support, parameter keys Ollama rejects, or auth on an Ollama proxy.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/5986f6c099c310fa. Report an issue: GitHub.