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

StatusCodeMeaning
400invalid_requestThe body is not valid JSON, or a required field is missing.
401invalid_api_keyThe key is missing, wrong or revoked.
402insufficient_balanceYour balance is lower than the task price. Add funds and retry.
403key_quota_exceededThis key reached its spending limit.
403key_disabledThis key has been disabled.
404not_foundNo such task of yours.
404model_not_foundNo such model.
409idempotency_conflictThe Idempotency-Key was already used for a different request.
422invalid_inputinput does not match the model's schema. See details.
429rate_limitedYou have too many unfinished tasks. Wait for some to finish; see Retry-After.
503model_unavailableThe model cannot take requests right now. Nothing was charged.
500internal_errorSomething 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.

CodeMeaning
upstream_rejectedThe model refused the input, for example because of its content rules.
upstream_failedThe model could not produce a result.
timeoutThe task did not finish in time.
internal_errorA 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 200 with the original task and the header Idempotent-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

SituationWhat to do
Timeout or connection error on POST /tasksRetry with the same Idempotency-Key.
429Wait for Retry-After seconds, then retry.
500 or 503Retry with backoff, using the same key.
4xx other than 429Do not retry as is; fix the request.
Task failCreate a new task if you want to try again. It is a new charge.