An AI image failed: reading the error and getting the reserved credits back

All in One AIAI Images·· 1 view· 3 min read

In short: an image can fail at two moments. Right at the request, with an error and a code; then nothing is reserved or charged. Or during the generation, with the failed status; then nothing is charged and the reserved credits go back to your balance on their own. In neither case do you need to ask for a refund.

It failed right at the request

POST /v1/media/generations answers with an error instead of 202. The code is in error.code:

Status and code What it means What to do
402 insufficient_credits The balance does not cover the reservation. details.required and details.balance say how much you need and how much you have. Buy credits, or choose a cheaper model or options.
403 insufficient_scope The key does not have ai:write. Create a key with ai:read and ai:write.
404 model_not_found The id is wrong or the model is not an image model (a text model, for example). Copy the id from the Models tab.
422 validation_failed A required field is missing or a value is not one of the model's options. See details and the fields in GET /v1/models/{id}.
429 rate_limited Too many requests in the same minute. Wait the seconds in Retry-After.
502 upstream_error The AI service did not respond as expected. Try again shortly, or with another model.

It failed during the generation

The request was accepted (202), but the status check returns failed:

curl "https://api.interweb.co.mz/v1/media/generations/<id>" \
-H "Authorization: Bearer $INTERWEB_API_KEY"

Field With failed
status failed
error The reason, in plain language.
outputs No files.
credits_charged 0: nothing was charged and the reservation went back to your balance.

Checking that the credits came back

See your balance with GET /v1/ai/balance, with aio balance or on the All in One AI page:

curl "https://api.interweb.co.mz/v1/ai/balance" -H "Authorization: Bearer $INTERWEB_API_KEY"

The same goes for the MCP server and for aio: a generation that fails costs nothing.

Trying again

1 Read the error or the error code: it says what to change.
2 Change what is needed: the prompt, an option or the model.
3 Send a new request. If you use Idempotency-Key, a fixed request gets a new value: the same value would return the saved answer.

If the error is not clear, open a support ticket with the error's correlation_id (or the generation id) and the time. Never send the key.

For a video or a voice, the statuses are the same: see an AI video or voice is taking long or has failed.

Want to check your balance after a failure? It is on the All in One AI page.

See All in One AI

SEE ALSO

An AI video or voice is taking long or has failed: the statuses and what to do

AI API errors: 402, 403, 404, 422, 429 and 502, and what to do in each case

What an AI image costs in credits: the price per image, the reserve and the refund

The fields an image model accepts: GET /v1/models/{id} and the size option

All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.