Core concepts
Errors
Request errors, job errors and what to do about each.
There are two kinds of errors: a request the API refuses, which returns an HTTP error, and a job that fails while running, which you read with a normal 200.
Request errors
Every refused request returns the same body:
{
"api_version": "v1",
"error": {
"code": "insufficient_funds",
"message": "Available API wallet funds are below the required pre-debit.",
"retryable": false,
"details": [
{
"field": "max_charge_amount",
"reason": "insufficient_available_balance"
}
]
},
"request_id": "req_5b2f8e1c-7a4d-4c3b-9e6f-1d8a2c7b4e90"
}| Field | Meaning |
|---|---|
error.code | A stable code. Branch on this, not on the message. |
error.message | Plain English for a person. It can change. |
error.retryable | Whether sending the same request again, with the same idempotency key, may work. |
error.details | A list of problems with the request, each pointing at a field. |
request_id | Include this when you contact support. |
Codes
| Code | HTTP | What to do |
|---|---|---|
invalid_request | 400 | The request is malformed or has an unknown field or query parameter. error.details names it. |
invalid_input | 400 | The model input doesn't match its schema. error.details names the field. |
idempotency_key_required | 400 | Send exactly one Idempotency-Key header. |
spend_limit_required | 400 | Send max_charge_amount (needed unless the key has a per-request spend limit). |
unauthorized | 401 | The API key is missing, wrong, revoked or expired. |
insufficient_funds | 402 | Add funds to your wallet. |
account_in_debt | 402 | Pay the outstanding balance in the console. |
price_limit_exceeded | 402 | Raise max_charge_amount or change the input. If the key has a per-request spend limit, that caps it too. |
key_budget_exceeded | 402 | The key reached its monthly spend cap. Use another key. |
account_restricted | 403 | The account can't use the API. Contact support. |
scope_denied | 403 | Use a key with the scope this endpoint needs. |
model_not_available | 403 | The model isn't sold, or this key is limited to other models. |
not_found | 404 | Check the ID. A resource that belongs to another account looks the same. |
feature_not_found | 404 | The API isn't enabled for this account yet. |
idempotency_key_conflict | 409 | The key was already used for a different request. Use a new key. |
quote_already_used | 409 | Get a new quote. |
quote_mismatch | 409 | The job's model or input differs from the quote's. Send the quoted input or get a new quote. |
job_not_cancelable | 409 | The job already finished. |
file_limit_reached | 409 | Too many uploads that no job has used yet. Use them or wait for them to expire. |
quote_expired | 410 | Get a new quote. |
payload_too_large | 413 | The request body is over 64 KB. Upload media as a file instead of inlining it. |
unsupported_media_type | 415 | Send Content-Type: application/json. |
queue_full | 429 | Wait for Retry-After, then retry with the same Idempotency-Key. |
rate_limited | 429 | Too many requests. Wait for Retry-After, then retry. |
ledger_busy | 503 | Retry after Retry-After. |
service_unavailable | 503 | Retry with the same Idempotency-Key. The job may already exist. |
Codes marked retryable: true are queue_full, rate_limited, ledger_busy and service_unavailable. A timeout or dropped connection has no body at all: treat it like a 503.
Field details
For 400 errors, each item in details has a field (a dotted path such as input.duration) and a reason. Model input errors also have a message, and some have a limit that shows what is allowed.
{
"field": "input.duration",
"reason": "unpriced_value",
"message": "This duration is not available for this model.",
"limit": {
"allowed": [
5,
10
]
}
}Common reasons:
| reason | Meaning |
|---|---|
required | A required field is missing. |
unknown_field | The model doesn't accept this field. |
invalid_type | Wrong JSON type, such as a string where a number goes. |
invalid_value | Not one of the allowed values. See limit.allowed. |
out_of_range | Number outside limit.min and limit.max. |
length | Text is too long or too short. A list with too many or too few items is out_of_range. |
invalid_url | Not a public https URL. |
unpriced_value | This value is valid for the model but isn't sold. |
unpriced_field | This field would add a cost we don't support yet. |
must_be_decimal_string | Money must be a string like "1.000000". |
file_not_uploaded | The file_id exists but its bytes were never uploaded. |
file_expired | The file is too close to its 7-day deletion to use. Upload it again. |
Job errors
When a job fails, GET /v1/jobs/{id} returns it with status: "failed" and an error. Failed jobs are never charged.
| error.code | Meaning | Try again? |
|---|---|---|
invalid_input | The provider rejected the input. | Fix the input first. |
content_policy | The prompt or input broke the provider's content rules. | Not with the same input. |
timeout | The provider took too long. | Yes, as a new job. |
generation_failed | The model ran but produced nothing usable. | Usually, as a new job. |
internal_error | Something went wrong on our side. | Yes, as a new job. |
queue_expired | The job waited 15 minutes in your account queue without starting. | Yes, when fewer jobs are running. |
On a job error, retryable means a new job with the same input may succeed. It never means the old job will be retried. Starting the new job is up to you and is charged separately.
Errors in the clients
The clients raise typed errors that derive from AstorieError. Errors for an HTTP response also carry the fields above plus status, requestId and idempotencyKey. In Python the same fields are request_id and idempotency_key.
| Error | When |
|---|---|
InvalidRequestError | 400, 413, 415, 422 |
AuthenticationError | 401 |
PaymentRequiredError | 402, with InsufficientFundsError as a subclass |
PermissionDeniedError | 403 |
NotFoundError | 404 |
ConflictError | 409, with IdempotencyKeyConflictError and JobNotCancelableError |
GoneError | 410 |
RateLimitError | 429 |
ServerError | 5xx |
APIConnectionError | Network failure. APITimeoutError for timeouts. |
WaitTimeoutError | wait() ran out of time. The job is still running. |
UploadError | Storage refused a file upload. |
DownloadError | downloadAsset() couldn't fetch a result, for example because it no longer exists. |