Guide
Errors
Every error from your API has a fixed code and says what to do about it.
What an error looks like
Every error answer has the same JSON shape. error is a short text, code is a fixed name to use in your code, and message (when present) says what to do. Validation errors add details, one entry per field.
GET /api/v1/Products
X-API-Key: cfa_…
HTTP/1.1 404 Not Found
X-Request-Id: 9b1c…
{
"error": "Entity not found",
"code": "ENTITY_NOT_FOUND",
"message": "This project has no entity named \"Products\". Names are case-sensitive; GET / lists the entities you can call.",
"requestId": "9b1c…"
}Quote the request id
requestId is also in the X-Request-Id header. If you contact support about a failed request, include it and we can find exactly what happened.Handling errors in code
Check code, not the error text: codes never change, texts can get clearer over time (see our API stability promise). Rate limit answers also carry Retry-After and the X-RateLimit-* headers.
const res = await fetch(`${API}/orders`, { method: 'POST', headers, body: JSON.stringify(order) });
if (!res.ok) {
const err = await res.json();
switch (err.code) {
case 'VALIDATION_FAILED':
showFieldErrors(err.details); // [{ field, message }]
break;
case 'INVALID_TOKEN':
await refreshToken(); // POST /auth/refresh, then retry
break;
case 'RATE_LIMITED':
await wait(Number(res.headers.get('Retry-After')) * 1000);
break;
default:
console.error(err.code, err.message, err.requestId);
}
}Building with an AI tool? Copy for AI includes this error format, so the code it writes can react to each case.
Retrying safely
When a request times out you can't tell whether it was saved. Retrying a POST could create the record twice. Send an Idempotency-Key header (any unique text, up to 255 characters) and reuse it for the retries of that request: the API answers a retry with the first answer, marked Idempotent-Replayed: true, and creates nothing new.
// One key per order the user places; the same key on every retry of it
const idempotencyKey = crypto.randomUUID();
const send = () =>
fetch(`${API}/orders`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json', 'Idempotency-Key': idempotencyKey },
body: JSON.stringify(order),
});
let res = await send().catch(() => null);
if (!res || res.status >= 500) res = await send(); // never creates the order twice- Successful answers are kept for 24 hours. After an error the key is free again, so the retry runs for real.
- Keys belong to your project. The same key with a different body, path or signed-in user is refused (
IDEMPOTENCY_KEY_REUSED). - Works for JSON
POSTrequests: creating records, bulk creates and custom endpoints.
Changing a record others edit too
If two people edit the same record, the second save normally overwrites the first. To prevent that, send the record's updatedAt (as you read it) in an If-Match header with PUT, PATCH or DELETE. If the record changed since, nothing is saved and the API answers 412 VERSION_MISMATCH with the current currentUpdatedAt.
const { data: task } = await (await fetch(`${API}/tasks/${id}`, { headers })).json();
const res = await fetch(`${API}/tasks/${id}`, {
method: 'PATCH',
headers: { ...headers, 'Content-Type': 'application/json', 'If-Match': task.updatedAt },
body: JSON.stringify({ title: newTitle }),
});
if (res.status === 412) {
// Someone changed the task since we read it: reload it and let the user decide
}Without If-Match updates work as before. If-Match: * only requires that the record still exists.
API key
| Code | Status | Meaning | What to do |
|---|---|---|---|
API_KEY_REQUIRED | 401 | No X-API-Key header was sent. | Send your key in the X-API-Key header. Your keys are on the API Keys page. |
INVALID_API_KEY | 401 | The key does not exist or is turned off. | Copy the key again from the API Keys page, and check that it is active. |
ORIGIN_REQUIRED | 403 | The key only works from a browser, and the request had no Origin header. | Call it from your web app, or use a key without origin restrictions on your server. |
INVALID_ORIGIN | 403 | The Origin header is not a valid URL. | Let the browser set the Origin header; don't set it by hand. |
ORIGIN_NOT_ALLOWED | 403 | The key is restricted to other websites. | Add this site to the key's allowed origins on the API Keys page. |
KEY_SCOPE | 403 | A publishable key was used for something its permissions don't include. | Change the key's permissions, or make this call from your server with a secret key. |
Signed-in users
| Code | Status | Meaning | What to do |
|---|---|---|---|
AUTH_REQUIRED | 401 | The entity's access rules need a signed-in user, and no token was sent. | Send the token from POST /auth/login as Authorization: Bearer <token>. |
INVALID_TOKEN | 401 | The access or refresh token is wrong or expired. | Get a new access token with POST /auth/refresh, or sign in again. |
INVALID_CREDENTIALS | 401 | Wrong email or password. | Ask the user to try again, or to reset their password. |
ROLE_REQUIRED | 403 | Only users with the admin role may do this. | Sign in as an admin, or change the entity's access rules. |
EMAIL_NOT_VERIFIED | 403 | The project requires a confirmed email, and this user hasn't confirmed theirs. | The user opens the link in the email; POST /auth/resend-verification sends a new one. |
USER_EXISTS | 400 | An account with this email already exists. | Sign in instead, or use POST /auth/forgot-password. |
Project and plan
| Code | Status | Meaning | What to do |
|---|---|---|---|
OWNER_EMAIL_NOT_VERIFIED | 403 | The project owner hasn't confirmed their email address, so the API is paused. | Sign in to the dashboard and confirm your email. |
PROJECT_READ_ONLY | 403 | The account has more projects than its plan includes, so this one only allows reads. | Upgrade, or delete a project. |
DEMO_READ_ONLY | 403 | The demo playground can't be changed. | Create your own project. |
RATE_LIMITED | 429 | Too many requests in a short time. | Wait for the seconds in the Retry-After header, then retry. Cache reads where you can. |
QUOTA_EXCEEDED | 429 | The account used its monthly requests. | Upgrade, or wait until the date in resetTime. |
STORAGE_LIMIT | 403 | The upload would go over the plan's file storage. | Delete files you no longer need, or upgrade. |
Entities and records
| Code | Status | Meaning | What to do |
|---|---|---|---|
ENTITY_NOT_FOUND | 404 | No entity with this name. Names are case-sensitive. | Check the spelling. GET /api/v1/ lists the entities you can call. |
RECORD_NOT_FOUND | 404 | No record with this id, or it belongs to another user under an "owner" access rule. | Check the id, and which user is signed in. |
METHOD_DISABLED | 403 | This method is switched off for the entity. | Turn it on in the dashboard: Entities → <name> → Endpoint Configuration. |
FIELD_PROTECTED | 403 | Only an admin may change role or password_hash on a user. | Use POST /auth/change-password for passwords; sign in as an admin to change roles. |
USERS_VIA_AUTH | 403 | Users can't be created through the users entity. | Use POST /auth/register. |
Input
| Code | Status | Meaning | What to do |
|---|---|---|---|
INVALID_JSON | 400 | The body isn't valid JSON. | Check the body, and send Content-Type: application/json. |
INVALID_QUERY | 400 | A filter, sort or field in the query string doesn't exist or has the wrong type. | The message names the problem and lists the fields you can use. |
VALIDATION_FAILED | 400 | A field is missing or has the wrong type. | details lists each field and what is wrong with it. |
DUPLICATE_VALUE | 409 | A unique field already has this value in another record. | Use another value, or update the existing record. |
VERSION_MISMATCH | 412 | The record changed since you read it (your If-Match is an older updatedAt). | Read the record again, apply your change, and send the new updatedAt in If-Match. currentUpdatedAt has it. |
IDEMPOTENCY_KEY_REUSED | 422 | This Idempotency-Key was used before for a different request. | Use a new key for each new request; reuse one only to retry the same request. |
IDEMPOTENCY_IN_PROGRESS | 409 | The first request with this Idempotency-Key is still running. | Wait a moment and retry with the same key. |
INVALID_FILE | 400 | The file type isn't allowed, or the upload is broken. | The message names the field and the reason. |
FILE_TOO_LARGE | 413 | A file is over 5MB. | Make the file smaller. |
TOO_MANY_FILES | 400 | More than 10 files in one request. | Send them in several requests. |
General
| Code | Status | Meaning | What to do |
|---|---|---|---|
BAD_REQUEST | 400 | The request is wrong in a way the error text describes. | Read error and message. |
UNAUTHORIZED | 401 | The request isn't authenticated. | Read error and message. |
FORBIDDEN | 403 | The request isn't allowed. Custom endpoints use this for their own checks. | Read error and message. |
NOT_FOUND | 404 | Nothing at this path. | Check the URL. |
CONFLICT | 409 | The request conflicts with the current state. | Read the record again and retry. |
PAYLOAD_TOO_LARGE | 413 | The JSON body is over 2MB. | Send less data per request, or use the bulk endpoint in parts. |
INTERNAL | 500 | Something failed on our side. | Retry. If it keeps happening, contact support with the requestId. |
UPLOAD_FAILED | 500 | A file could not be stored. | Retry. If it keeps happening, contact support with the requestId. |
UPSTREAM_FAILED | 502 | A custom endpoint called another service, and it failed. | Check that service; the endpoint's test run shows its answer. |
UNAVAILABLE | 503 | The service is briefly unavailable. | Retry after a few seconds. |