> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cimento.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors and rate limits

> The shape of an Analytics API error, what each code means and what to do about it, and how fast a service account can call.

## The shape of an error

Every error from a route under `/v1` has the same shape:

```json 400 Bad Request theme={null}
{
  "error": {
    "code": "invalid_request",
    "message": "colour is not a parameter of this route"
  }
}
```

| Field | Description |
| - | - |
| `code` | Which error it is. It does not change: branch on this. |
| `message` | What went wrong, for a developer to read. The wording can change, so don't match on it. |

The [token URL](https://docs.cimento.ai/api/authentication.md#when-the-token-url-refuses) answers errors in a different shape.

## Error codes

| Status | `code` | What it means | What to do |
| - | - | - | - |
| `400` | `invalid_request` | A parameter is unknown, given twice, empty or not a value the route takes. The message names it. | Fix the request. Trying again unchanged gets the same answer. |
| `401` | `invalid_token` | No access token was sent, or it has expired or is not valid. | [Get a new access token](https://docs.cimento.ai/api/authentication.md#get-an-access-token) and try again. |
| `403` | `insufficient_scope` | The token lacks a scope the route needs, or the service account may not read what was asked for. | Check the [scopes](https://docs.cimento.ai/api/scopes.md). If a scope was added to the service account, [rotate its secret](https://docs.cimento.ai/api/rotating-secrets.md#adding-a-scope). |
| `404` | `not_found` | Nothing has that ID, there is no such route, or your organization does not have the feature the route belongs to. | Check the ID and the path. |
| `429` | `rate_limited` | The service account is calling too quickly. | Wait the seconds the `Retry-After` header gives, then try again. |
| `503` | `unavailable` | Cimento could not answer just now. | Try again shortly, waiting longer each time. |

Treat a code you don't recognize by its status alone.

### Examples

A token without the scope a route needs:

```json 403 Forbidden theme={null}
{
  "error": {
    "code": "insufficient_scope",
    "message": "this token is not granted \"phishing_analytics:view\", which this route requires"
  }
}
```

A missing or expired access token, which also carries a `WWW-Authenticate: Bearer error="invalid_token"` header:

```json 401 Unauthorized theme={null}
{
  "error": {
    "code": "invalid_token",
    "message": "a valid access token is required: get one from the token endpoint and send it as a Bearer token"
  }
}
```

An ID that nothing has:

```json 404 Not Found theme={null}
{
  "error": {
    "code": "not_found",
    "message": "there is nothing here by that ID, or nothing this token can read"
  }
}
```

## Rate limits

Each service account can make a short burst of requests, then about one a second: 60 a minute, sustained. The limit is for each service account, so one busy system does not slow another.

Past the limit, a request answers `429` with a `Retry-After` header giving the seconds to wait:

```json 429 Too Many Requests theme={null}
{
  "error": {
    "code": "rate_limited",
    "message": "this service account is making requests too quickly: wait the number of seconds in the Retry-After header, then try again"
  }
}
```

To stay inside it:

* **Honor `Retry-After`.** Wait at least that long before the next request. Don't retry at once.
* **Send requests one after another**, not many at a time.
* **Ask for bigger pages.** `limit=100` reads a list in a fifth of the requests the default takes.
* **Reuse your access token.** The token URL has a limit of its own, and one token works for an hour.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.