# Errors and status codes

> What every Hollow model API failure means and which to retry, with the OpenAI and Anthropic error bodies, and how a spend cap differs from a rate limit.

The API uses ordinary HTTP status codes, and the body of an error has the shape the protocol you called uses, so the OpenAI and Anthropic SDKs raise their usual error types.

## Error bodies

**An error body, shown for a rate limit**

**OpenAI-compatible**

```json
{
  "error": {
    "message": "Rate limit exceeded: 60 requests per minute per key.",
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded"
  }
}
```

**Anthropic-compatible**

```json
{
  "type": "error",
  "error": {
    "type": "rate_limit_error",
    "message": "Rate limit exceeded: 60 requests per minute per key."
  }
}
```

- The OpenAI-compatible body is `{ "error": { "message", "type", "code" } }`. A 402 also carries `top_up_url`.
- The Anthropic-compatible body is `{ "type": "error", "error": { "type", "message" } }`.
- Branch on the HTTP status and on `type`. Treat `message` as text for a person: it can change.
- A new error type or code can appear at any time. Handle one you do not know as a failure that is not worth retrying.

## What to do

**What to do about a failure**

| What happened | What to do |
| --- | --- |
| A rate limit or a provider failure (HTTP 429 rate limit, 502, 503, 504) | Retry later, with backoff. |
| The key is wrong or not allowed (HTTP 401, 403) | Fix the key: check it, its scope and its expiry. Retrying will not help. |
| A spend cap you set is reached (HTTP 429 cap) | Raise the cap, or wait for the month to reset. Stop sending until then. |
| Your prepaid credit is used up or not enough (HTTP 402) | Add credit on [Billing](https://platform.projecthollow.com/billing/). Stop sending until then. |

## Status codes

**HTTP status codes and what to do**

| HTTP status | Error type | Meaning | Retry? | Status in the API |
| --- | --- | --- | --- | --- |
| 400 | `invalid_request_error` | The request is wrong: no `model`, a model Hollow does not serve (`model_not_available`), a bad `messages` list, or a `max_tokens` that is not a positive whole number of at most 1,000,000. | No. Fix the request. | Implemented |
| 401 | `authentication_error` | The key is missing, malformed, unknown, expired, disabled or suspended. See [Authentication](https://platform.projecthollow.com/docs/authentication.md). | No. Fix the key. | Implemented |
| 402 | `insufficient_quota` (OpenAI-compatible) or `billing_error` (Anthropic-compatible) | Your prepaid credit is used up or not enough for this request (`credit_exhausted`). Every model request is paid from prepaid credit, so a request with no credit is refused before any model is called. | No. Add credit. | Implemented |
| 403 | `permission_error` | The key lacks the `models:*` scope, or the account is not approved. | No. | Implemented |
| 404 | `invalid_request_error` | The path is not one the API serves. | No. | Implemented |
| 429 | `rate_limit_error` or `insufficient_quota` | Either a rate limit or a spend cap you set. They need opposite responses: see below. | Rate limit: yes. Spend cap: no. | Implemented |
| 502 | `api_error` | The model provider failed. The message is fixed and never carries the provider's own text. | Yes, with backoff. | Implemented |
| 503 | `api_error` | Pricing for the model is unavailable, or the key lookup timed out. | Yes, with backoff. | Implemented |
| 504 | `api_error` (`upstream_timeout`) | The model provider did not respond in time, or the model call ran past its time limit (`UPSTREAM_TIMEOUT`). The message is fixed and never carries the provider's own text. | Yes, with backoff. | Implemented |

## No credit (HTTP 402)

Every model request, from an API key or from the Playground, is paid from prepaid credit. When there is none, or not enough for the request, the API answers HTTP 402 with the code `credit_exhausted` before any model is called. Nothing runs and nothing is charged. Add credit on [Billing](https://platform.projecthollow.com/billing/), then send the request again.

**The 402 body when credit has run out**

**OpenAI-compatible**

```json
{
  "error": {
    "message": "Your API credit has run out, or is not enough for this request. Add credit at https://platform.projecthollow.com/billing/ and try again.",
    "type": "insufficient_quota",
    "code": "credit_exhausted",
    "top_up_url": "https://platform.projecthollow.com/billing/"
  }
}
```

**Anthropic-compatible**

```json
{
  "type": "error",
  "error": {
    "type": "billing_error",
    "message": "Your API credit has run out, or is not enough for this request. Add credit at https://platform.projecthollow.com/billing/ and try again.",
    "code": "credit_exhausted",
    "top_up_url": "https://platform.projecthollow.com/billing/"
  }
}
```

Branch on the HTTP status 402 or on `code` being `credit_exhausted`. The `top_up_url` field is where to add credit. For a Business organisation member who cannot buy credit, the message asks them to ask an owner or admin of the organisation to add it.

## A monthly cap is not a rate limit

A spend cap is optional: you can set one on a project or a key, and your credit is the real limit whether you do or not. When a cap is set and reached, it arrives as HTTP 429 like a rate limit, and the two need opposite responses. A rate limit clears in seconds, so wait and retry. A monthly cap does not clear until the month turns over or someone raises the cap, so retrying only adds load. A cap is never a rate limit: it does not slow requests, it stops spend at a ceiling. Platform names them SPEND_CAP_REACHED and RATE_LIMITED on the [Playground](https://platform.projecthollow.com/playground/) and [Limits](https://platform.projecthollow.com/limits/) pages. Those are Platform's names for the two cases, not text in the response.

**Telling the two 429 errors apart**

| Aspect | Monthly cap reached | Rate limited |
| --- | --- | --- |
| Cause | The month's spend, plus the worst case for this request, would pass a spend cap you set on the project or key. | More than 60 requests in a minute on one key (Seed plan), or more than the lower rate set on that key. |
| OpenAI-compatible body | `type` is `insufficient_quota` and `code` is `project_spend_exceeded` or `key_spend_exceeded`. | `type` is `rate_limit_error` and `code` is `rate_limit_exceeded` (a key) or `project_rate_limited` (a project). |
| Anthropic-compatible body | `type` is `rate_limit_error` and `code` is `PROJECT_SPEND_EXCEEDED` or `KEY_SPEND_EXCEEDED`. | `type` is `rate_limit_error`, with `code` `PROJECT_RATE_LIMITED` for a project. |
| Does waiting help? | Not until the month resets. The message says when. | Yes, within a minute. The response carries `Retry-After`. |
| What to do | Stop sending. Raise the cap on [Limits](https://platform.projecthollow.com/limits/) or wait for the reset. | Wait, then retry with backoff. |

Tell the two apart by `code`. A cap error never carries `Retry-After`; a rate limit always does. A cap error names the cap in pounds, the same unit you set it in. Spend caps are amounts in pounds everywhere, and the API field is `monthlySpendLimitGbp`: see [Limits](https://platform.projecthollow.com/docs/limits.md).

## Request ids

Every model request, whether it succeeds or fails, returns an `X-Request-Id` header. Browsers can read it too. Log it with each failure, and give it to support: it finds the exact request.

**Read the request id of a failed call**

**OpenAI SDK**

```python
from openai import APIStatusError

try:
    raw = client.chat.completions.with_raw_response.create(model="claude-haiku-5-5", messages=messages)
    print(raw.headers["x-request-id"])
except APIStatusError as error:
    print(error.status_code, error.response.headers["x-request-id"])
```

**Anthropic SDK**

```python
from anthropic import APIStatusError

try:
    raw = client.messages.with_raw_response.create(model="claude-haiku-5-5", max_tokens=256, messages=messages)
    print(raw.headers["x-request-id"])
except APIStatusError as error:
    print(error.status_code, error.response.headers["x-request-id"])
```

The Playground response details show the same id.

## Retrying safely

1. Retry only what can succeed on a second try: HTTP 429 for a rate limit, 502, 503 and 504.
2. Never retry 400, 401, 402, 403 or a 429 for a spend cap. The answer will not change.
3. If the response has a `Retry-After` header, wait that many seconds. If it has none, wait one second and double the wait each time, with a little random jitter, up to a limit you choose.
4. Give up after a few attempts and report the failure rather than looping.
5. Send an `Idempotency-Key` header of up to 200 characters so a retry cannot run the request twice. A repeat with the same key returns the stored reply, marked with the header `Idempotent-Replay: true`, without calling the model or spending again.

## Workflow API errors

The workflow API and webhooks are served by the Hollow API gateway, not the model API, so their failures use the gateway format: a JSON body with an `error` object holding `code`, `status` and `message`. Branch on `code`.

**Codes from the workflow API**

| Code | HTTP status | Retry? |
| --- | --- | --- |
| `INPUT_INVALID` | 400 | No. `details.fields` lists the input keys to fix. |
| `INSUFFICIENT_SCOPE` | 403 | No. The key needs the `platform:run` scope. |
| `KEY_NOT_BOUND` | 403 | No. Use a key that belongs to a project. |
| `MODEL_NOT_ALLOWED` | 403 | No. The key may not call a model the workflow uses. |
| `WORKFLOW_NOT_FOUND` | 404 | No. The workflow is not published, or is not in the key's project. |
| `WORKFLOW_PAUSED` | 409 | No. The workflow's automation is paused in Cascade. Resume it there. A paused workflow refuses API and webhook starts. |
| `WORKFLOW_CHANGED` | 409 | No. The published automation was changed in Cascade. Publish the workflow again. |
| `INVALID_REQUEST` | 400 | No. Fix the request or run input the runner refused. |
| `WORKFLOW_ACTION_UNSUPPORTED` | 400 | No. API and webhook starts cannot yet carry key authority through Call automation or Hollow action steps. Start this workflow manually in Platform. |
| `PROJECT_ARCHIVED` | 403 | No. Restore the project before starting a run. |
| `IDEMPOTENCY_KEY_REUSED` | 422 | No. Use a new `Idempotency-Key` for a different input. |
| `CREDIT_EXHAUSTED` | 402 | No. Add credit. |
| `KEY_SPEND_EXCEEDED` or `PROJECT_SPEND_EXCEEDED` | 429 | No. Raise the cap on Limits or wait for the month to reset. |
| `RATE_LIMITED` | 429 | Yes, after the `Retry-After` wait. |
| `QUOTA_EXCEEDED` | 429 | No. Your run quota is used up. |
| `IDEMPOTENCY_IN_PROGRESS` | 409 | Yes, with the same `Idempotency-Key` once the first request has answered. |
| `RUN_MAY_HAVE_STARTED` | 409 | Not blindly. Read `GET /v1/platform/workflows/{workflowId}/runs?requestId=` with your URL-encoded `Idempotency-Key` to find the original run, even after a new publication. Do not start another with a new key while the outcome is unknown. |
| `INVALID_HOOK_SECRET` | 401 | No. Send the current webhook secret. |
| `HOOK_NOT_LISTENING` | 409 | No. Start listening in the editor, then send the test request. |

Every code is explained in [Run workflows over the API](https://platform.projecthollow.com/docs/workflow-api.md#errors). A workflow run that starts and then fails is not an HTTP error: read its `status` instead.

## Streaming requests

A request that is refused (a bad key, a limit, a bad request) gets an ordinary error response before any stream starts, so check the status code before you read the stream. Once a stream has started the status code can no longer change, so handle a stream that ends early.
