{"record":{"id":"5986f6c099c310fa","repo":"linshenkx/prompt-optimizer","slug":"generation-failed-5986f6","errorCode":"GENERATION_FAILED","errorMessage":"${errorMessage}","messagePattern":"\\$\\{errorMessage\\}","errorType":"error_code","errorClass":"ImageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/image/adapters/ollama.ts","lineNumber":178,"sourceCode":"    }\n\n    const response = await fetch(url, {\n      method: 'POST',\n      headers,\n      body: JSON.stringify(payload)\n    })\n\n    if (!response.ok) {\n      let errorMessage = `Ollama API error: ${response.status} ${response.statusText}`\n      try {\n        const errorData = await response.json()\n        if (typeof errorData?.error?.message === 'string') {\n          errorMessage = errorData.error.message\n        }\n      } catch {\n        // ignore JSON parse errors\n      }\n      throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, errorMessage)\n    }\n\n    const json = await response.json()\n    return this.parseImageResponse(json, config)\n  }\n\n  private parseImageResponse(response: any, config: ImageModelConfig): ImageResult {\n    if (!response?.data || !Array.isArray(response.data)) {\n      throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)\n    }\n\n    const images = response.data.map((item: any) => {\n      if (!item?.b64_json || typeof item.b64_json !== 'string') {\n        throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)\n      }\n      const dataUrl = `data:image/png;base64,${item.b64_json}`\n      return {\n        b64: item.b64_json,","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/image/adapters/ollama.ts#L160-L196","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded error message from Ollama's response","Verify the model is pulled and supports image generation (ollama pull / model list)","Upgrade Ollama to a version with the images API enabled","Simplify paramOverrides to isolate rejected parameters"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!/^[\\w:.-]+$/.test(config.modelId)) throw new Error('invalid Ollama model id')","typeGuard":null,"tryCatchPattern":"try { ... } catch (e) {\n  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.GENERATION_FAILED) {\n    if (/not found|pull/i.test(e.message)) hint('ollama pull <model>')\n  }\n}","preventionTips":["Pre-pull image-capable models with `ollama pull`","Keep Ollama updated for the experimental images API","Test connectivity with a minimal request before batch jobs"],"tags":["ollama","http-error","model-not-found","image-generation"],"backgroundTag":"image-generation-api-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}