Errors and idempotency
Every error code, why a task can fail, and how to retry without being charged twice.
Error format
Errors use real HTTP status codes and one body shape:
{
"error": {
"code": "invalid_input",
"message": "The input does not match the model schema.",
"details": [{ "field": "input.resolution", "message": "must be one of 1K, 2K, 4K" }]
}
}Branch on code, not on message; messages can change. details appears when there is something field-specific to say.
Request errors
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request | The body is not valid JSON, or a required field is missing. |
| 401 | invalid_api_key | The key is missing, wrong or revoked. |
| 402 | insufficient_balance | Your balance is lower than the task price. Add funds and retry. |
| 403 | key_quota_exceeded | This key reached its spending limit. |
| 403 | key_disabled | This key has been disabled. |
| 404 | not_found | No such task of yours. |
| 404 | model_not_found | No such model. |
| 409 | idempotency_conflict | The Idempotency-Key was already used for a different request. |
| 422 | invalid_input | input does not match the model's schema. See details. |
| 429 | rate_limited | You have too many unfinished tasks. Wait for some to finish; see Retry-After. |
| 503 | model_unavailable | The model cannot take requests right now. Nothing was charged. |
| 500 | internal_error | Something went wrong on our side. |
Nothing is charged for a request that returns an error.
When a task fails
A task can be accepted and still fail. Then status is fail, error.code says why, and the full price is refunded automatically, exactly once.
| Code | Meaning |
|---|---|
upstream_rejected | The model refused the input, for example because of its content rules. |
upstream_failed | The model could not produce a result. |
timeout | The task did not finish in time. |
internal_error | A problem on our side. |
You do not need to claim a refund. The charge and the refund both show in your usage log.
Idempotency
Network calls fail in ambiguous ways: a request may time out after we already accepted it. To retry without paying twice, send an Idempotency-Key header on POST /tasks.
curl https://nsfwapi.io/api/v1/tasks \
-H "Authorization: Bearer $NSFWAPI_KEY" \
-H "Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \
-H "Content-Type: application/json" \
-d '{"model": "nano-banana-2.1", "input": {"prompt": "a lighthouse at dusk"}}'- Use a fresh random value, such as a UUID, for each new task, and reuse it only when you retry that same task. Keys are 1 to 128 characters: letters, digits and
_ . : -. - Same key and same request: we return
200with the original task and the headerIdempotent-Replayed: true. You are not charged again. - Same key and a different request:
409 idempotency_conflict. - Keys are remembered for at least 24 hours.
Retry guidance
| Situation | What to do |
|---|---|
Timeout or connection error on POST /tasks | Retry with the same Idempotency-Key. |
429 | Wait for Retry-After seconds, then retry. |
500 or 503 | Retry with backoff, using the same key. |
4xx other than 429 | Do not retry as is; fix the request. |
Task fail | Create a new task if you want to try again. It is a new charge. |