{"record":{"id":"92138ee6b0aa2f7d","repo":"can1357/oh-my-pi","slug":"gemini-image-request-failed-resp-status-me","errorCode":null,"errorMessage":"Gemini image request failed (${resp.status}): ${message}","messagePattern":"Gemini image request failed \\((.+?)\\): (.+?)","errorType":"http","errorClass":"ProviderHttpError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/image-gen.ts","lineNumber":1690,"sourceCode":"\t\t\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t\t\t\t\t\"x-goog-api-key\": key,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tbody: JSON.stringify(requestBody),\n\t\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst text = await resp.text();\n\t\t\t\t\t\t\tif (!resp.ok) {\n\t\t\t\t\t\t\t\tlet message = text;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst parsed = JSON.parse(text) as { error?: { message?: string } };\n\t\t\t\t\t\t\t\t\tmessage = parsed.error?.message ?? message;\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t// Keep raw text.\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthrow new ProviderHttpError(\n\t\t\t\t\t\t\t\t\t`Gemini image request failed (${resp.status}): ${message}`,\n\t\t\t\t\t\t\t\t\tresp.status,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\theaders: resp.headers,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn text;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ signal: requestSignal },\n\t\t\t\t\t);\n\n\t\t\t\t\tconst data = JSON.parse(rawText) as GeminiGenerateContentResponse;\n\t\t\t\t\tconst responseParts = combineParts(data);\n\t\t\t\t\tconst responseText = collectResponseText(responseParts);\n\t\t\t\t\tconst inlineImages = collectInlineImages(responseParts);\n\n\t\t\t\t\tif (inlineImages.length === 0) {","sourceCodeStart":1672,"sourceCodeEnd":1708,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/image-gen.ts#L1672-L1708","documentation":"Google Gemini's image generation endpoint returned a non-2xx status. The tool parses the Google-style error envelope (error.message), falls back to raw body text, and throws a ProviderHttpError carrying the status and response headers.","triggerScenarios":"Failed HTTP call to the Gemini image API: invalid GEMINI_API_KEY/GOOGLE_API_KEY (401/403), quota exhausted (429), unsupported model or aspect ratio (400), region-blocked API (403), or Google-side 5xx, at image-gen.ts:1690.","commonSituations":"Using an API key without Generative Language API enabled; free-tier quota exhausted; wrong model name (e.g. nonexistent imagen version); API key from a different Google Cloud project; restricted API key lacking the API in its allowlist.","solutions":["Inspect error.message inside the thrown ProviderHttpError — Google's message identifies the exact problem.","Validate GEMINI_API_KEY / GOOGLE_API_KEY in Google AI Studio; regenerate if revoked.","Check quota and billing; wait out 429 rate limits or raise limits.","Confirm the requested Gemini/Imagen model id and image_size are supported for your key/region.","Retry on transient 5xx with backoff, or let the tool fall through to other credentialed providers."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const key = process.env.GEMINI_API_KEY ?? process.env.GOOGLE_API_KEY;\nif (!key) throw new Error('Set GEMINI_API_KEY (or GOOGLE_API_KEY) for Gemini image generation');","typeGuard":null,"tryCatchPattern":"try {\n  return await geminiImage(params);\n} catch (err) {\n  if (err instanceof ProviderHttpError) {\n    if (err.status === 429) return retryWithBackoff(() => geminiImage(params));\n    if (err.status === 400) throw new Error(`Gemini rejected request params: ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Confirm the key has the Generative Language API enabled and the right region","Use exact Gemini/Imagen model ids supported for your key tier","Back off on 429; free-tier quotas reset per minute/day","Surface Google's error.message verbatim — it is diagnostic"],"tags":["network","http","gemini","google","image-generation","provider-error"],"backgroundTag":"http-error-response","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}