can1357/oh-my-pi · error · ProviderHttpError

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

Error message

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

What it means

OpenRouter's image generation HTTP endpoint returned a non-2xx response. The tool wraps the status code and the provider's error message (extracted from the JSON error.message field, or the raw body text if unparsable) into a ProviderHttpError, preserving response headers.

Source

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

									method: "POST",
									headers: {
										"Content-Type": "application/json",
										Authorization: `Bearer ${key}`,
										...getOpenRouterHeaders(),
									},
									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(
										`OpenRouter image request failed (${resp.status}): ${message}`,
										resp.status,
										{ headers: resp.headers },
									);
								}
								return text;
							},
							{ signal: requestSignal },
						);

						const data = JSON.parse(rawText) as OpenRouterResponse;
						const message = data.choices?.[0]?.message;
						const responseText = collectOpenRouterResponseText(message);
						const imageUrls = extractOpenRouterImageUrls(message);
						const inlineImages: InlineImageData[] = [];
						for (const imageUrl of imageUrls) {
							inlineImages.push(await loadImageFromUrl(imageUrl, fetchImpl, requestSignal));
						}

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the embedded provider message in the error — it states the actual cause (auth, credits, model, rate limit).
  2. Check the key: OPENROUTER_API_KEY valid and active at openrouter.ai/keys.
  3. Check credits/billing on the OpenRouter account for the chosen model.
  4. Verify the model slug exists and supports image generation; fix the model id.
  5. For 429/5xx, retry with backoff; the tool may have already tried other credentialed providers (see aggregate error).
Defensive patterns

Strategy: try-catch

Validate before calling

if (!process.env.OPENROUTER_API_KEY) throw new Error('OPENROUTER_API_KEY required for OpenRouter image requests');

Try / catch

try {
  return await openRouterImage(params);
} catch (err) {
  if (err instanceof ProviderHttpError) {
    if (err.status === 429 || err.status >= 500) return retryWithBackoff(() => openRouterImage(params));
    if (err.status === 401 || err.status === 402) throw new Error(`OpenRouter auth/billing issue: ${err.message}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Any failed HTTP call to OpenRouter's image API — 401 invalid OPENROUTER_API_KEY, 402 insufficient credits, 404 unknown model slug, 429 rate limit, 5xx upstream — surfacing at image-gen.ts:1558.

Common situations: Expired or revoked OpenRouter key; account out of credits for a paid image model; mistyped model id (e.g. wrong vendor prefix); hitting free-tier rate limits; OpenRouter outage.

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/464f6a3a2a77b8b0. Report an issue: GitHub.