can1357/oh-my-pi · error · ProviderHttpError

${options.label} image request failed (${resp.status}): ${me

Error message

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

What it means

postImageEndpointRequest wraps non-2xx HTTP responses from image provider endpoints (xAI, etc.) in a ProviderHttpError carrying the status, headers, and a message extracted from the JSON error body (`detail` or `error.message`) or the raw text. This is the provider rejecting the image request — authentication, billing, model access, or malformed request — and the message is the provider's own diagnostic.

Source

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

				method: "POST",
				headers: {
					Authorization: `Bearer ${key}`,
					"Content-Type": "application/json",
					"User-Agent": USER_AGENT,
				},
				body: JSON.stringify(options.body),
				signal: options.signal,
			});
			const rawText = await resp.text();
			if (!resp.ok) {
				let message = rawText;
				try {
					const parsedErr = JSON.parse(rawText) as { detail?: string; error?: { message?: string } };
					message = parsedErr.detail ?? parsedErr.error?.message ?? message;
				} catch {
					// Keep raw text.
				}
				throw new ProviderHttpError(
					`${options.label} image request failed (${resp.status}): ${message}`,
					resp.status,
					{
						headers: resp.headers,
					},
				);
			}
			return rawText;
		},
		{ signal: options.signal },
	);
}

/** Decode an OpenAI-style images response (`{data: [{b64_json, url}]}`) into inline images. */
async function collectImageEndpointImages(
	rawText: string,
	fetchImpl: FetchImpl,
	signal: AbortSignal | undefined,

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the embedded status and provider message to identify the exact rejection reason
  2. For 401/403, verify and rotate the provider API key (env var / providers config)
  3. For 429, add retry with backoff or raise the rate limit on the provider account
  4. For 400, check the request params (prompt, model id, aspect ratio) against the provider's API docs
  5. Confirm billing/credits are active on the provider account
Defensive patterns

Strategy: try-catch

Validate before calling

function requireImageProviderKey(prov: string): void {
	const key = process.env[`${prov.toUpperCase()}_API_KEY`];
	if (!key) throw new Error(`Missing API key for image provider '${prov}'`);
}

Try / catch

try {
	await genImage({ prompt });
} catch (err) {
	if (err instanceof ProviderHttpError) {
		if (err.status === 429 || err.status >= 500) return withBackoffRetry(() => genImage({ prompt }));
		if (err.status === 401 || err.status === 403) throw new Error("Check image provider API key/entitlements: " + err.message);
	}
	throw err;
}

Prevention

When it happens

Trigger: Any POST to the provider image endpoint returning non-2xx: invalid API key (401), insufficient credits (402/403), model not entitled (404), invalid params (400), or rate limits (429); raised via xaiRawText/rawText paths during image generation.

Common situations: Expired or rotated API keys in env/config; account without image-model access; exceeding rate limits or quota; wrong endpoint base URL or unsupported region.

Related errors


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