Errors
Every failed request returns a JSON body with a stable code. This page describes the error format, which errors are safe to retry, and when a failed request can still be charged.
Error format#
Every non-2xx response has the following format:
{ "error": "Insufficient word balance", "code": "insufficient_balance", "words_remaining": { "included": 12, "topup": 0, "total": 12 }}codeidentifies the cause and is stable. Base error handling on this field.erroris a human-readable message. Its wording may change and must not be used for matching.- Two codes include an additional field:
insufficient_balanceincludeswords_remaining, andenhanced_requires_premiumincludesupgrade_url.
A request for a path or method that does not exist returns {"detail": "Not Found"} with no code.
Retry behavior#
Every 429, 503 and 504 response from the API includes a Retry-After header, in whole seconds. The value is typically 2 to 10 seconds for capacity errors, up to 60 seconds for a rate limit, and up to 15 minutes for an authentication lockout.
A 429, 503 or 504 response without the JSON body and code was not generated by the API. It was returned by a load balancer or proxy, and the request may still be in progress. Handle it as a client timeout: check /v1/usage before resending a billable request.
Production best practices includes a reference retry implementation.
Charges on failed requests#
Words are charged only on a 200 response, with one exception. A 500 billing_failed response indicates that the result was produced but the usage record failed partway, so some of the words for the request may already have been deducted. Call /v1/usage to check the balance, and contact support if it is incorrect.
Order of checks#
When a request fails more than one check, the API returns the first failure in the following order:
- The body is not valid JSON, or a field has the wrong type or length (422
invalid_request). This check runs before authentication, so it can be returned even when no key is sent. - The key (401), then re-verification (403), then the plan (402
no_subscription). - Disallowed parameters (422
forbidden_param),enhanced(403),<freeze>tags (422) and the words-per-request limit (422word_limit). - The account balance (402
insufficient_balance), then the rate limit (429rate_limited). - Capacity (429 or 503), then content moderation (422
moderation_blocked), then processing.
Error codes#
Each code has its own anchor and can be linked to directly.
401: authentication failed#
Correct the Authorization header. Retrying the same request returns the same error.
- missing_api_key
- No usable
Authorization: Bearerheader.In the SDKs:AuthenticationError - invalid_api_key
- The key is unknown or revoked.In the SDKs:
AuthenticationError
402: no plan or insufficient balance#
No words are charged. The request succeeds once the account has an active plan and a sufficient balance.
- no_subscription
- The key is valid but the account has no active API subscription.In the SDKs:
NoSubscriptionError - insufficient_balance
- Not enough words left for this request;
words_remainingis included.In the SDKs:InsufficientBalanceError
403: request not permitted#
The request is rejected before processing, and no words are charged. Do not retry automatically.
- reverify_required
- The account must be re-verified by email. The account owner signs in at writehuman.ai to continue; then the account's newest key created after the check began works within about a minute; every other key stays disabled until the check ends, so create a new key.In the SDKs:
ReverifyRequiredError
422: invalid request#
No words are charged. Correct the request before resending it.
- invalid_request
- The body failed validation (missing
text, too short or too long).In the SDKs:InvalidRequestError - forbidden_param
- A parameter that is not available on the public API was sent.In the SDKs:
InvalidRequestError - word_limit
- The input is over the per-request word cap for your plan.In the SDKs:
InvalidRequestError - moderation_blocked
- Content moderation refused the input (
/v1/humanizeonly).In the SDKs:ModerationError - freeze_tag_not_closed
- The
<freeze>tags intextare malformed (accounts with freezing only; see/v1/humanize). Nothing charged.In the SDKs:APIError - freeze_tag_not_opened
- The
<freeze>tags intextare malformed (accounts with freezing only; see/v1/humanize). Nothing charged.In the SDKs:APIError - freeze_tag_empty
- The
<freeze>tags intextare malformed (accounts with freezing only; see/v1/humanize). Nothing charged.In the SDKs:APIError - nothing_to_rewrite
- Almost all of the text is frozen, so there is nothing left to humanize (accounts with freezing only). Nothing charged.In the SDKs:
APIError
429: rate limited#
No words are charged. Wait for the number of seconds given in Retry-After, then resend the same request.
- rate_limited
- Over your plan's requests per minute.
Retry-Afteris the time to the next window.In the SDKs:RateLimitError - auth_locked_out
- Too many failed authentications from this address.
Retry-Afteris the remaining lockout.In the SDKs:RateLimitError - queue_full
- The admission queue is full. Retry after
Retry-After.In the SDKs:RateLimitError - queue_timeout
- The request waited in the admission queue past its deadline. Retry after
Retry-After.In the SDKs:RateLimitError
500: server error#
The SDKs do not retry these errors, because the request may have been processed. Only billing_failed can result in a charge.
- processing_failed
- Generation raised an error.In the SDKs:
ProcessingError - no_results
- Generation finished without a usable result.In the SDKs:
ProcessingError - safety_limit
- Generation produced far more text than the input; discarded.In the SDKs:
ProcessingError - billing_failed
- The result was produced but the usage write failed part-way; included and/or top-up words may already have been charged. Check
/v1/usage.In the SDKs:BillingError
503 and 504: temporarily unavailable#
No words are charged. Wait for the number of seconds given in Retry-After, then resend the same request.
- at_capacity
- Cluster-wide capacity shed. Retry after
Retry-After.In the SDKs:ServiceUnavailableError - timeout
- Generation did not finish within the server deadline (
/v1/humanizeonly). Nothing charged; retry afterRetry-After.In the SDKs:ServerTimeoutError
Errors in the SDKs#
In the official SDKs every failure is a subclass of WriteHumanError carrying code, status and the last Retry-After (retry_after in Python, retryAfter in TypeScript). InsufficientBalanceError adds words_remaining / wordsRemaining, and PlanRequiredError adds upgrade_url / upgradeUrl. A code the installed SDK version does not know becomes APIError with code preserved. A response that is not the API's JSON, no response within the client timeout, or a failed connection becomes ProtocolError, ClientTimeoutError or ConnectionError, with no code.
See SDKs for an example.