# Errors and limits

> Error envelopes, machine error codes, timeout billing rules, retry guidance, rate limits, and live service status.

Every error returned by an inference endpoint or `GET /v1/key` includes `x-request-id`. Errors on `POST /v1/messages` also mirror that identifier in both the `request-id` header and the `request_id` body field. Include it whenever you ask support to trace a call.

Any call HeyEly dispatched upstream shows up in [Credit and usage](https://heyely.si/docs/concepts/credit-and-activation#usage) under that request ID, even when the upstream provider failed it.

Calls rejected inside the gateway before dispatch (gateway `400`, `401`, `402`, `404`, `413`, `429`, or `503` responses) are not recorded in Credit and usage.

Note that `GET /v1/models/{id}` answers unknown model IDs with a `404` carrying no request ID.

## OpenAI envelope

Chat Completions, legacy Completions, Responses, Embeddings, Images, Models, and Key return OpenAI's error shape:

```json
{
  "error": {
    "message": "This account has no credit left. Add credit in the dashboard to continue.",
    "type": "insufficient_credit",
    "code": "insufficient_credit",
    "param": null
  }
}
```

## Anthropic envelope

`POST /v1/messages` returns Anthropic's error shape so Claude Code and Anthropic SDKs parse it natively:

```json
{
  "type": "error",
  "error": {
    "type": "billing_error",
    "message": "This account has no credit left. Add credit in the dashboard to continue."
  },
  "request_id": "req_01K7Z4F2XQ"
}
```

## Status and type

The table below maps HTTP statuses for errors generated directly by HeyEly (upstream provider errors follow the rules further down).

| Status | OpenAI `type`           | Anthropic `type`        |
| ------ | ----------------------- | ----------------------- |
| 400    | `invalid_request_error` | `invalid_request_error` |
| 401    | `authentication_error`  | `authentication_error`  |
| 402    | `insufficient_credit`   | `billing_error`         |
| 403    | `permission_error`      | `permission_error`      |
| 404    | `invalid_request_error` | `not_found_error`       |
| 409    | `api_error`             | `conflict_error`        |
| 413    | `invalid_request_error` | `request_too_large`     |
| 410    | `api_error`             | `api_error`             |
| 429    | `rate_limit_error`      | `rate_limit_error`      |
| 502    | `api_error`             | `api_error`             |
| 503    | `api_error`             | `overloaded_error`      |
| 504    | `api_error`             | `timeout_error`         |

## Codes

Machine codes populate `error.code` in the OpenAI envelope; Anthropic's envelope exposes `error.type` only.

| Status | Code                           | Cause                                                                                                                                                                                                                                                                                                                                                                                                            | Fix                                                                                                                                                                                                 |
| ------ | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400    | `invalid_json`                 | Request body could not be parsed as JSON                                                                                                                                                                                                                                                                                                                                                                         | Send a valid JSON object                                                                                                                                                                            |
| 400    | `missing_model`                | Payload omitted `model`                                                                                                                                                                                                                                                                                                                                                                                          | Include a catalog model ID                                                                                                                                                                          |
| 400    | `missing_prompt`               | Legacy Completions payload omitted `prompt`                                                                                                                                                                                                                                                                                                                                                                      | Include a `prompt` string or array                                                                                                                                                                  |
| 400    | `invalid_parameter`            | Images `n` is not an integer from 1 to 10                                                                                                                                                                                                                                                                                                                                                                        | Pass an integer between 1 and 10                                                                                                                                                                    |
| 400    | `output_cap_required`          | Model publishes no max output and no output cap was supplied                                                                                                                                                                                                                                                                                                                                                     | Set `max_tokens` on Messages or `max_output_tokens` on Responses                                                                                                                                    |
| 400    | `unsupported_parameter`        | Payload includes `models`, `fallbacks`, `route`, or `provider`; a `plugins` entry outside the free allowlist (`response-healing`, `file-parser` on `cloudflare-ai` or `native`, `context-compression` with `enabled: false`); an unsupported tool type (outside `function`, `custom`, and supported web search); X search; audio input; or a file sent to a model without native file support and no free parser | Pick one model and drop disallowed fields; Chat Completions auto-attaches `cloudflare-ai` for files, whereas Messages, Responses, Embeddings, Images, and Completions require setting it explicitly |
| 400    | `unsupported_model`            | Model bills per search (such as `perplexity/sonar-deep-research`)                                                                                                                                                                                                                                                                                                                                                | Switch to another model                                                                                                                                                                             |
| 401    | `missing_api_key`              | No credential header supplied                                                                                                                                                                                                                                                                                                                                                                                    | Send `Authorization: Bearer sk-df-...` or `x-api-key`                                                                                                                                               |
| 401    | `invalid_api_key`              | Key does not match any active secret                                                                                                                                                                                                                                                                                                                                                                             | Re-check your saved key or mint a replacement                                                                                                                                                       |
| 401    | `api_key_disabled`             | Key is paused                                                                                                                                                                                                                                                                                                                                                                                                    | Re-enable it in [Developers](https://heyely.si/keys) or use another key                                                                                                                                              |
| 401    | `api_key_expired`              | Key passed its expiry timestamp                                                                                                                                                                                                                                                                                                                                                                                  | Mint a new key                                                                                                                                                                                      |
| 402    | `insufficient_credit`          | Spendable balance is zero or smaller than the call's hold (files and URL-referenced images/videos reserve the larger of the text estimate and the model's context window, or 1,000,000 tokens if unknown)                                                                                                                                                                                                        | Add credit, lower `max_tokens`, or reduce file/URL inputs                                                                                                                                           |
| 402    | `key_limit_reached`            | Key reached its dollar cap or lacks headroom for this hold                                                                                                                                                                                                                                                                                                                                                       | Raise the key cap, lower `max_tokens`, or switch keys                                                                                                                                               |
| 402    | `free_credit_not_eligible`     | Only free credit remains and the model or payload does not qualify                                                                                                                                                                                                                                                                                                                                               | Use an open-weight text model, lower `max_tokens`, or add paid credit                                                                                                                               |
| 402    | `payment_required`             | Neither API key nor x402 payment was provided while x402 is enabled; read the hold from `PAYMENT-REQUIRED`                                                                                                                                                                                                                                                                                                       | Authenticate with a key or sign and retry with `PAYMENT-SIGNATURE`. See [x402](https://heyely.si/docs/concepts/credit-and-activation#pay-per-request-with-x402)                                                      |
| 400    | `payment_invalid`              | Malformed `PAYMENT-SIGNATURE`, mismatched payment terms, or keyed call paid by a wallet outside the key's account                                                                                                                                                                                                                                                                                                | Inspect the message and re-sign the challenge                                                                                                                                                       |
| 402    | `payment_invalid`              | Signature did not recover to `from`, wallet lacks bridged USDC, or nonce was already spent (reason in `PAYMENT-RESPONSE`)                                                                                                                                                                                                                                                                                        | Fund the wallet on Elysium or sign with a fresh nonce                                                                                                                                               |
| 402    | `payment_failed`               | Elysium settlement reverted or exceeded the 30-second confirmation window (`PAYMENT-RESPONSE` carries reason and transaction hash)                                                                                                                                                                                                                                                                               | Retry using a fresh nonce; nothing was credited                                                                                                                                                     |
| 404    | `model_not_found`              | Model ID does not exist in the active catalog                                                                                                                                                                                                                                                                                                                                                                    | Query `GET /v1/models` and pick a live ID                                                                                                                                                           |
| 413    | `request_too_large`            | Body exceeds 32 MB (or 64 MB on Images)                                                                                                                                                                                                                                                                                                                                                                          | Trim the payload size                                                                                                                                                                               |
| 429    | `rate_limited`                 | Exceeded 300 RPM on this key, or 20 RPM across keys on an account that has never added paid credit                                                                                                                                                                                                                                                                                                               | Wait `retry-after` seconds; adding paid credit removes the 20-RPM cap                                                                                                                               |
| 429    | `too_many_concurrent_requests` | Key already has 8 requests executing concurrently                                                                                                                                                                                                                                                                                                                                                                | Wait for an active request to complete and retry                                                                                                                                                    |
| 502    | `upstream_error`               | Provider failed or refused connection before accepting the call                                                                                                                                                                                                                                                                                                                                                  | Retry safely; zero cost charged                                                                                                                                                                     |
| 502    | `upstream_error`               | Non-streamed response dropped after the provider accepted it                                                                                                                                                                                                                                                                                                                                                     | Retry; nothing is billed yet and the hold stays reserved                                                                                                                                            |
| 503    | `service_unavailable`          | Inference gateway is temporarily unavailable                                                                                                                                                                                                                                                                                                                                                                     | Retry after a brief backoff                                                                                                                                                                         |
| 503    | `model_prices_stale`           | Catalog pricing for this model is over an hour stale, preventing safe billing                                                                                                                                                                                                                                                                                                                                    | Retry later or choose another model                                                                                                                                                                 |
| 504    | `upstream_timeout`             | Provider missed the deadline: 120 seconds on Images, 15 minutes on other non-streamed calls, or 5 minutes for missing response headers / stalled body                                                                                                                                                                                                                                                            | Retry; nothing is billed yet and the hold stays reserved                                                                                                                                            |

`free_credit_not_eligible` includes a self-contained message detailing eligibility rules and suggesting `max_tokens`. See [Free credit](https://heyely.si/docs/concepts/credit-and-activation#free-credit).

The codes above cover inference routes and `GET /v1/key`. Public credit-sale `GET` endpoints return their own codes (`400 invalid_parameter`, `404 not_found`, `502 chain_unavailable`, and `502 quote_unavailable`), while retired endpoints return `410 endpoint_retired`.

A non-streamed timeout charges nothing yet and keeps its hold reserved. A streamed timeout before response headers returns `504` and costs zero. The OpenAI `error.code` is `upstream_timeout`. Messages uses `error.type: timeout_error`. After headers, a timeout interrupts the HTTP `200` stream. A reported cost is charged plus the 5% fee, OpenRouter's platform fee on an open model and the routing fee on a Private one. HeyEly adds no markup. Token counts with a generation id are a provisional estimate. Anything else does not charge the hold.

## Provider errors

Upstream statuses tied to your input (`400`, `403`, `404`, `408`, `409`, `413`, `422`, and `429`) keep their original HTTP code while HeyEly rewrites the body into the endpoint's standard envelope and strips raw upstream metadata.

Provider wording is normalized to safe, approved messages. Detected context-length, content-policy, invalid-parameter, and unsupported-parameter failures explain how to fix the call (preserving the phrase `prompt is too long` on context-length failures so Claude Code detects it cleanly), while unrecognized errors emit a standard message for that status without echoing raw provider diagnostics or internal token counts.

On `POST /v1/messages`, valid Anthropic errors keep their `error.type`; other responses map to HeyEly's status type (using `conflict_error` for non-Anthropic `409`s) and stamp HeyEly's `request_id` in the body and `x-request-id` / `request-id` headers.

Upstream `401` and `402` statuses (indicating a gateway-to-provider issue) translate to `503`; all other upstream failures translate to `502`. Every translated response keeps your request ID without leaking upstream credentials or account details.

## Failures after a stream starts

Once response headers flush with HTTP `200`, any mid-stream failure stays inside the stream: provider error frames relay through, whereas abrupt upstream disconnects close the stream without an error event. Credit and usage marks those calls **Failed**.

A failed request is charged the provider's reported cost plus the 5% fee, OpenRouter's platform fee on an open model and the routing fee on a Private one. HeyEly adds no markup. Token counts with a generation id are a provisional estimate. Anything else does not charge the hold. Read [Streaming events](https://heyely.si/docs/api-reference/chat-completions#streaming).

## Retry

Apply exponential backoff with jitter on `429`, `502`, `503`, and `504`, always honoring `retry-after` (integer seconds) when supplied.

Never blindly retry `400`, `401`, `402`, `404`, or `413` before addressing the underlying cause. See [Rate limits](https://heyely.si/docs/api-reference/errors#rate-limits).

## Rate limits

### Limits

| Limit                                            | Value                                                                                                                                                                                                                               | When exceeded                                                                                                                                        |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| Requests per minute                              | 300 per key                                                                                                                                                                                                                         | `429 rate_limited` with `retry-after` (Messages: `rate_limit_error`)                                                                                 |
| Requests in flight                               | 8 per key                                                                                                                                                                                                                           | `429 too_many_concurrent_requests` with `retry-after: 1` (Messages: `rate_limit_error`)                                                              |
| Requests per minute before credit is first added | 20 per account across all keys                                                                                                                                                                                                      | `429 rate_limited` with `retry-after` (Messages: `rate_limit_error`)                                                                                 |
| Credit                                           | Available account credit must cover the call's hold                                                                                                                                                                                 | `402 insufficient_credit`, or `402 free_credit_not_eligible` when only free credit remains and the call does not qualify (Messages: `billing_error`) |
| Key credit limit                                 | Configured key cap minus active holds on that key                                                                                                                                                                                   | `402 key_limit_reached` (Messages: `billing_error`)                                                                                                  |
| Request body                                     | 32 MB, or 64 MB on Images                                                                                                                                                                                                           | `413 request_too_large` (Messages: `request_too_large`)                                                                                              |
| Time to answer                                   | 120 seconds for Images (including streams); non-streamed text times out at 5 minutes on missing headers or body stalls and 15 minutes total; text streams have no total cap but enforce the same 5-minute header/body stall timeout | Before headers: `504` (`upstream_timeout` on OpenAI endpoints, `timeout_error` on Messages). After headers: the HTTP `200` stream ends               |

Every limit tracks per API key except the 20-RPM pre-credit cap, which spans the entire account. Limits govern every model endpoint; OpenAI routes populate `error.code`, whereas Messages reports `error.type` only.

A non-streamed timeout charges nothing yet and keeps its hold reserved. A streamed timeout before response headers returns `504` and costs zero. The OpenAI `error.code` is `upstream_timeout`. Messages uses `error.type: timeout_error`. After headers, a timeout interrupts the HTTP `200` stream. A reported cost is charged plus the 5% fee, OpenRouter's platform fee on an open model and the routing fee on a Private one. HeyEly adds no markup. Token counts with a generation id are a provisional estimate. Anything else does not charge the hold.

### The 20 per minute limit

Accounts that have never added paid credit share a 20-requests-per-minute ceiling across every key (called out in the error message). Adding credit via bridged USDC or credit tokens, or claiming holder rewards as service credit, lifts this ceiling; buying unactivated credit tokens does not. Per-key limits of 300 RPM remain active. See [Free credit](https://heyely.si/docs/concepts/credit-and-activation#free-credit).

### Retry

Every `429` includes `retry-after` as whole seconds; wait that duration before retrying. On `too_many_concurrent_requests`, your key already has 8 concurrent calls active, so wait for one to finish or throttle client concurrency below 8.

```python
import random
import time

import requests


def post_with_retry(url, headers, body, attempts=5):
    for attempt in range(attempts):
        response = requests.post(url, headers=headers, json=body, timeout=120)
        retryable = response.status_code in (429, 502, 503, 504)
        if not retryable or attempt == attempts - 1:
            return response
        wait = float(response.headers.get("retry-after", 2**attempt))
        time.sleep(wait + random.random())
```

Skip retries on `400`, `401`, `404`, and `413`, and skip retrying `402` when your account or key truly has zero balance. A `402` triggered purely by concurrent in-flight holds can succeed once earlier calls finish and release their holds. See [Errors](https://heyely.si/docs/api-reference/errors).

### Stay under the limits

* Pool HTTP connections and cap per-key concurrency at 8 in-flight calls.
* Issue a dedicated key per tool or background worker so noisy jobs cannot starve interactive editors.
* Pass explicit output caps (`max_tokens` on Chat Completions, Messages, and legacy Completions, or `max_output_tokens` on Responses). On Chat Completions and legacy Completions not paid by free credit, omitting a cap holds the model's maximum output (or 8,192 if unknown), clamped at 32,768 and sent upstream as `max_tokens`; explicit caps above 32,768 hold in full up to the model's maximum. On Messages and Responses, omitting a cap holds the model's full published maximum output (which can exceed 32,768) and returns `400 output_cap_required` if none is published.

Active credit holds clear automatically the moment a request completes. See [Pricing](https://heyely.si/docs/concepts/credit-and-activation#pricing).

## Status

Check `/api/status.json` anytime (public, no API key required) if sign-in, inference, or credit top-ups seem delayed. For usage metrics and Elysium chain totals, see [Network data](https://heyely.si/docs/stats).

```bash
curl https://heyely.si/api/status.json
```

The payload follows Statuspage v2 (`page`, `status`, `components`, and active `incidents`), plus a 90-day `recent_incidents` archive and a `meta` block explaining methodology. `status.indicator` reports `none`, `minor`, `major`, `critical`, or `unknown`, while each component reports `operational`, `degraded_performance`, `major_outage`, or `unknown`. A `503` carrying indicator `unknown` signals that status data could not be loaded. Subscribe to incident updates via the RSS feed at `/api/status/feed.xml`.

### Read each component

Automated probes check live services every 60 seconds and check keeper and upstream balances hourly. Each component inherits the worst state among its underlying probes (a single model outage impacts both Chat and API), and the JSON exposes every underlying probe by name.

Three consecutive probe failures mark a check down, while slowness or partial errors mark it degraded. Stale service probes flip to `unknown` after 3 minutes (3 hours for balance probes), and unknown intervals are excluded from uptime percentages.

| Component | What it covers                                                                           |
| --------- | ---------------------------------------------------------------------------------------- |
| Chat      | Web chat, docs, and the model infrastructure serving them                                |
| API       | Developer API routes (chat, messages, responses, embeddings) and backing models          |
| Credit    | Buying and activating credit and updating balances                                       |
| Sign-in   | New authentication sessions (existing keys, active sessions, and API calls keep working) |

### Follow incidents

Active incidents list impacted services and their current lifecycle phase (`Investigating`, `Identified`, `Monitoring`, or `Resolved`) and can elevate overall severity. Resolved incidents remain visible inside `recent_incidents` for 90 days. Because incident notices are authored by operators, automated probes can mark a component degraded or down ahead of a written post.
