can1357/oh-my-pi · error · ProviderHttpError

Gemini image request failed (${resp.status}): ${message}

Error message

Gemini image request failed (${resp.status}): ${message}

What it means

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.

Source

Thrown at packages/coding-agent/src/tools/image-gen.ts:1690

									method: "POST",
									headers: {
										"Content-Type": "application/json",
										"x-goog-api-key": key,
									},
									body: JSON.stringify(requestBody),
									signal: requestSignal,
								},
							);
							const text = await resp.text();
							if (!resp.ok) {
								let message = text;
								try {
									const parsed = JSON.parse(text) as { error?: { message?: string } };
									message = parsed.error?.message ?? message;
								} catch {
									// Keep raw text.
								}
								throw new ProviderHttpError(
									`Gemini image request failed (${resp.status}): ${message}`,
									resp.status,
									{
										headers: resp.headers,
									},
								);
							}
							return text;
						},
						{ signal: requestSignal },
					);

					const data = JSON.parse(rawText) as GeminiGenerateContentResponse;
					const responseParts = combineParts(data);
					const responseText = collectResponseText(responseParts);
					const inlineImages = collectInlineImages(responseParts);

					if (inlineImages.length === 0) {

View on GitHub (pinned to 9690622007)

Solutions

  1. Inspect error.message inside the thrown ProviderHttpError — Google's message identifies the exact problem.
  2. Validate GEMINI_API_KEY / GOOGLE_API_KEY in Google AI Studio; regenerate if revoked.
  3. Check quota and billing; wait out 429 rate limits or raise limits.
  4. Confirm the requested Gemini/Imagen model id and image_size are supported for your key/region.
  5. Retry on transient 5xx with backoff, or let the tool fall through to other credentialed providers.
Defensive patterns

Strategy: try-catch

Validate before calling

const key = process.env.GEMINI_API_KEY ?? process.env.GOOGLE_API_KEY;
if (!key) throw new Error('Set GEMINI_API_KEY (or GOOGLE_API_KEY) for Gemini image generation');

Try / catch

try {
  return await geminiImage(params);
} catch (err) {
  if (err instanceof ProviderHttpError) {
    if (err.status === 429) return retryWithBackoff(() => geminiImage(params));
    if (err.status === 400) throw new Error(`Gemini rejected request params: ${err.message}`);
  }
  throw err;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/92138ee6b0aa2f7d. Report an issue: GitHub.