fix: classify Replicate prediction failures instead of 500ing (PUT-1608) (#3719)

A Replicate prediction that ran and ended `failed` reaches the provider as a
plain Error with no HTTP status, so the driver-boundary translator could not
classify it and it surfaced as an unhandled 500, a critical alarm, and an
on-call page. Most of these are the model's content filter refusing the
user's prompt.

Wrap the run call and classify the failure: content-filter refusals become
a 400 with `errorCode: moderation_flagged` (the code chat refusals already
use); anything else becomes a 502 `upstream_failed`, which the alarm gate
skips. Status-bearing SDK errors pass through untouched so the boundary
translator keeps handling them. Upstream messages are stripped of markup and
bounded so an HTML error page can no longer ride into a response body or an
alarm signature.

Documents the codes callers can now act on in the txt2img reference.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
404oops
2026-09-02 11:51:08 -07:00
committed by GitHub
co-authored by Claude Fable 5.1
parent 262f1dc5c5
commit fd7b517448
3 changed files with 169 additions and 4 deletions
+12
View File
@@ -171,6 +171,18 @@ Absolute paths (`/username/Pictures/sunset.png`) and home-relative paths (`~/Pic
A `Promise` that resolves to an `HTMLImageElement`. The elements `src` points at a data URL containing the image.
## Errors
A rejection carries the error body as the backend sent it: `{ message, code }`, plus `errorCode` when a more specific code is available alongside a general one.
| Code | Meaning |
| --- | --- |
| `errorCode: moderation_flagged` | The model's content filter refused the prompt or the generated image. Arrives as HTTP 400 with `code: bad_request`. Change the prompt rather than retrying it as-is. Not every provider reports refusals distinctly; when one does, this is how. |
| `upstream_failed` | The provider accepted the request but generation failed on their side. Safe to retry. |
| `insufficient_funds` | Your balance cannot cover the estimated cost of the image. Arrives as HTTP 402. |
Other `upstream_*` codes mean the provider rejected the request or was unavailable; the `message` carries the provider's reason.
## Examples
<strong class="example-title">Generate an image of a cat using AI</strong>