# Limits and errors

> Widget API limits, error codes and the error response format.

## Limits

- Maximum message length: 4000 characters.
- Messages (`/message`): 80 requests per minute.
- All endpoints together: 900 requests per 15 minutes.
- The `/message` endpoint requires a `session_id`. If the session does not exist, a new one is created and the response includes its id and history.

## Error codes

| Status | Error | What to do |
|---|---|---|
| 400 | Missing `session_id` or `message`, message too long | Fix the request body |
| 401 | `Widget token is required` | Add the `Authorization: Bearer YOUR_TOKEN` header |
| 401 | `Invalid or expired widget token` | Check the token in the app: **AI Agent** → **Installation** |
| 402 | Plan limit reached | Check your workspace plan and limits |
| 429 | Rate limit exceeded | Wait a moment and retry |
| 500 | Server error | Retry; if it keeps happening, contact us |

## Error format

```json
{
  "error": "Invalid or expired widget token"
}
```

In streaming mode an error arrives as an `error` event with `status`, `code` and `error` fields.