# Errors

> The error shape, every error type, and what to do about each.

Every error has the same shape. This sends an invalid horizon:

```bash
curl -s https://api.yhatlabs.com/v1/series/forecast \
  -H "Authorization: Bearer $YHAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"horizon": 0, "series": [{"id": "a", "values": [1, 2, 3]}]}'
```

Output:

```
{"error":{"type":"invalid_request_error","message":"'horizon' must be a positive integer.","request_id":"eea9b5ec-b5ed-463d-a6b8-3d4296491787"}}
```

Every error body carries `request_id`, the same value as the `X-Request-Id` header. Quote it when you contact us.

| Status | `type` | Meaning | What to do |
|---|---|---|---|
| 400 | `invalid_request_error` | the request is malformed | fix it; the message says how |
| 401 | `authentication_error` | missing, invalid, revoked or expired key | check `YHAT_API_KEY` |
| 402 | `no_credits` | the organization's credits ran out | owners request more on the Credits page |
| 403 | `model_not_allowed` | the key was limited to other models | use one of the models the message lists, or change the key |
| 403 | `organization_suspended` | the organization is suspended | write to us |
| 404 | `model_not_found` | no such model for this key's organization | see `GET /v1/models` |
| 410 | `model_retired` | the model was retired | pick another from `GET /v1/models` |
| 404 | `fit_not_found` | the fit expired, was deleted, or belongs to another project | fit again |
| 404 | `job_not_found` | no such job in this project | check the id |
| 413 | `async_required` | a direct table call past its preset's direct size ([Limits](https://yhatlabs.com/models/docs/resources/limits)) | send it again with `"async": true` ([Async jobs](https://yhatlabs.com/models/docs/api/jobs)); the Python library does this for you |
| 413 | `request_too_large` | over a hard size limit (200,000 rows, 2,000 columns, 50,000,000 cells as a job) | sample or split the input ([Limits](https://yhatlabs.com/models/docs/resources/limits)) |
| 409 | `request_in_progress` | a call with the same `Idempotency-Key` is still running | retry after `Retry-After` |
| 422 | `invalid_request_error` | the model could not use this data; the message says why when it is about your input (one class, too few rows, a missing column, an invalid parquet file) | fix the input |
| 403 | `forbidden` | only whoever made a fit (or a project admin) may rename or delete it | ask them |
| 429 | `quota_exceeded` | a key's or project's cap is used up; `period`, `limit` and `used` are included | wait for the next period, or raise the cap |
| 502 | `upstream_error` | the model failed on this request: a bug on our side, not your data | retrying rarely helps; send us the request id |
| 503 | `model_unavailable` | the model is starting or temporarily down; a `Retry-After` header says when to retry | retry after the wait |

Retry 408, 409, 429 (except `quota_exceeded`) and 5xx with backoff; the Python library does this for you. For calls that
switched to a streamed `200` response, an error arrives in the body ([Overview](https://yhatlabs.com/models/docs/api/overview#conventions)).
