CoplayDev/unity-mcp · error · Exception
OpenRouter request failed
Error message
OpenRouter request failed (status={res?.Status}): {detail} What it means
Thrown by OpenRouterAdapter.ParseOk when the OpenRouter chat-completions request returns a non-ok HTTP status. The detail is read from json.error.message, then json.error, then truncated raw text, and scrubbed of the API key. OpenRouter is used for image generation via a multimodal model that returns an inline base64 image.
Solutions
- Read error.message from the exception text to get OpenRouter's reason.
- 401 -> set a valid OpenRouter API key in settings; 402 -> add credits; 429 -> back off.
- 400 with a modality/model complaint -> confirm the model supports image output (default google/gemini-2.5-flash-image) and leave model unset to use the default.
- Retry on 429/5xx with exponential backoff.
Defensive patterns
Strategy: retry
Try / catch
try { await openrouter.SubmitAsync(req, key, http, ct); }
catch (Exception ex)
{
bool transient = ex.Message.Contains("status=429") || ex.Message.Contains("status=5");
if (transient) await BackoffRetryAsync(() => openrouter.SubmitAsync(req, key, http, ct), ct);
} Prevention
- Confirm the model supports image output (default google/gemini-2.5-flash-image); leave model unset to use it.
- Keep OpenRouter credits funded and the key valid.
- Surface error.message to distinguish auth vs. model-capability vs. rate-limit.
When it happens
Trigger: 401 invalid OpenRouter key; 400 the selected model does not support image output or the 'modalities' field; 402 insufficient credits; 429 rate limit; model name typo (e.g. a discontinued model); content-policy rejection.
Common situations: Default model google/gemini-2.5-flash-image rotated or renamed by OpenRouter; user set a text-only model for image generation; credits exhausted; a prompt flagged by safety filters.
Related errors
- Sketchfab failed (status= )
- Sketchfab failed (status= )
- Cannot connect to Unity MCP server at
- Cannot reach
- Connection closed while reading
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/bf04281b53a62393.
Report an issue: GitHub.
Appendix: source
Thrown at MCPForUnity/Editor/Services/AssetGen/Providers/OpenRouterAdapter.cs:151
return null;
}
private static JObject ParseOk(HttpResult res, string apiKey)
{
string text = ProviderHttp.BodyText(res);
JObject json = null;
if (!string.IsNullOrEmpty(text))
{
try { json = JObject.Parse(text); } catch { /* non-JSON */ }
}
bool ok = res?.Ok == true;
if (!ok)
{
string detail = json?["error"]?["message"]?.ToString() ?? json?["error"]?.ToString()
?? ProviderHttp.Truncate(text);
throw new Exception(SecretRedactor.Scrub($"OpenRouter request failed (status={res?.Status}): {detail}", apiKey));
}
return json ?? new JObject();
}
}
}
View on GitHub (pinned to c21bf496bc)