Errors and limits
What failed calls return, the reasons you'll meet, and how to retry safely.
A failed call returns a standard gRPC status code and a message. Most also carry Caret's own reason, a short code in the x-caret-reason response metadata, so your code can tell causes apart. The Python SDK puts it in error.reason.
The errors you'll meet
| Code | Reason | What it means | What to do |
|---|---|---|---|
UNAUTHENTICATED |
(message TOKEN_INVALID) |
The key is missing, mistyped, revoked or expired, or its person was deactivated | Check the header is authorization: Bearer cpk_…. Make a new key if it expired |
PERMISSION_DENIED |
SCOPE_MISSING |
The key doesn't have the scope this needs. The message names it | Make a key with that scope |
PERMISSION_DENIED |
NOT_IN_API |
This method isn't available to API keys | See what the API doesn't do |
PERMISSION_DENIED |
WRONG_WORKSPACE |
The key belongs to another workspace | Leave workspace_id empty, or use a key from that workspace |
PERMISSION_DENIED |
ADMIN_REQUIRED, ROLE |
The key's person isn't allowed to do this in the app either | Ask an admin, or use an admin's key |
PERMISSION_DENIED |
NOT_IN_SPACE, NOT_MEMBER |
The person can't see that space or thread | Have them added |
NOT_FOUND |
No such thread, space, bot or approval, or the person can't see it | Check the id | |
INVALID_ARGUMENT |
VALIDATION and others |
A field is missing or wrong. The message says which | Fix the request |
FAILED_PRECONDITION |
e.g. THREAD_DONE, BOT_PAUSED |
Can't be done right now | Reopen the thread, resume the bot, and so on |
ALREADY_EXISTS |
e.g. HANDLE_TAKEN |
Something with that name exists | Pick another |
RESOURCE_EXHAUSTED |
Rate limit: more than 1,200 requests a minute | Back off and retry | |
UNAVAILABLE |
The server couldn't be reached or is restarting | Retry with backoff |
Reasons are stable codes you can match on. Messages are for people and may change.
Retrying safely
- Reads are always safe to retry.
- Commands (
CommandService/Execute) are safe to retry if you reuse the sameidempotency_key. The server recognises it and doesn't run the command twice (replayed: true). - Retry on
UNAVAILABLE,RESOURCE_EXHAUSTEDandDEADLINE_EXCEEDED, with exponential backoff: 0.5 s, 1 s, 2 s, and so on. Don't retryPERMISSION_DENIED,INVALID_ARGUMENTorNOT_FOUND. They'll fail again.
The Python SDK does all of this for you.
Limits
| Limit | Value |
|---|---|
| Requests per key | 1,200 per minute |
| Request or response size | 16 MiB |
| Items per page | 50 by default, 500 at most |
Upload size (POST /v1/files) |
2 GB |
| Key lifetime | 90 days by default, 365 at most |