# Errors & Rate Limits

## Error shape

Every `/api/v1` endpoint returns errors in the same shape:

```json
{ "error": { "code": "not_found", "message": "Resource not found." } }
```

| Status | `code`                | When                                                                                                                             |
| ------ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `401`  | `unauthenticated`     | Missing, invalid, or revoked token, or its owner has left the team.                                                              |
| `403`  | `forbidden`           | Token doesn't have the required ability, or the token owner's role or plan does not allow the write.                             |
| `404`  | `not_found`           | Source doesn't exist, its id is not one Tailcove issued, belongs to another team, or is outside the token owner's client groups. |
| `422`  | `validation_failed`   | Bad query parameter (see `error.details` for field-level messages).                                                              |
| `409`  | `request_in_progress` | A request with the same `Idempotency-Key` is still being processed (see [Writing](https://tailcove.dev/docs/api/writing)).                           |
| `429`  | `rate_limited`        | Over the per-token rate limit below.                                                                                             |
| `429`  | `limit_reached`       | A daily cap on creating something was reached (deploys per source); `Retry-After` says when the next one fits.                   |

`422` responses additionally include an `error.details` object, keyed by
field, matching Laravel's standard validation error shape:

```json
{
    "error": {
        "code": "validation_failed",
        "message": "The cursor is invalid or has expired.",
        "details": { "cursor": ["The cursor is invalid or has expired."] }
    }
}
```

For the [Logs](https://tailcove.dev/docs/api/logs) endpoint a `422` means one of: a date that
does not parse, is outside 1900-01-01 to 2299-12-31, or has `from` after `to`; a
range longer than 31 days (the default); `q` longer than 2000 characters, not valid
UTF-8 or not valid in the [query language](https://tailcove.dev/docs/query-language); a `limit` outside 1 to 500; or a `cursor` that is malformed, too
long, or past the end of what a cursor can express (see
[Logs: Cursors](https://tailcove.dev/docs/api/logs#cursors)).

This is a distinct shape from the [ingest endpoint's](https://tailcove.dev/docs/sending-logs/http-api)
plain `{ "message": "..." }` errors; the ingest endpoint isn't
token-authenticated the same way and predates this API.

## Rate limits

Each token is limited to **60 requests/minute**, and to **30 writes/minute** (`POST`, `PUT`, `DELETE`) within that, independent of other
tokens from the same IP. All the tokens of one team together are also limited to
**300 requests/minute**, so making more tokens does not buy more requests. Exceeding
either returns `429`:

```json
{ "error": { "code": "rate_limited", "message": "Too many requests." } }
```

The response includes the standard throttle headers:

```
Retry-After: 42
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
```

Back off until `Retry-After` elapses before retrying.
