API error handling
API error handling uses HTTP status codes and a JSON detail string. A missing API key is 401. A monthly quota miss is 402. A problem on our side is 5xx.
Error response body
{
"detail": "Search query must be at least 2 characters or empty for common foods."
}Status codes
400Bad request from an explicit validation check (e.g. query too short, bad match_mode). detail is a human-readable string. Paging past the first 1,000 results returns detail.code paging_limit.401Unauthorized, missing or invalid API key.402Monthly quota exceeded for your plan.403Forbidden — commercial use not allowed on your plan, the endpoint is not enabled for your plan, or a food-coverage limit was reached.404Not found, unknown food ID or barcode with no match in any source.422Unprocessable entity from schema validation (missing or out-of-range query/body params, e.g. limit=500 or a calc call missing required fields). Here detail is an array of field errors, not a string.423Locked — your account is on a temporary security hold due to unusual activity. Not retryable; contact support to restore access.429Rate limited, per-minute limit exceeded; see X-RateLimit-Reset.500Server error, safe to retry with backoff; report persistent failures.Errors with a code
Some limits return an object in detail with a code and a message instead of a plain string. Check for detail.code before reading detail as text.
Coded error body
{
"detail": {
"code": "end_user_id_required",
"message": "This account must send an anonymous ID for the person using your app in the X-End-User-Id header on every call."
}
}Codes
paging_limit (400)skip plus limit goes past the first 1,000 results. Narrow the query.end_user_id_required (400)Enterprise: the X-End-User-Id header is required and was missing.end_user_id_invalid (400)Enterprise: the X-End-User-Id value breaks the format rules.end_user_blocked (403)Enterprise: this end user is blocked until 00:00 UTC.end_user_rate_limited (429)Enterprise: this end user is over 60 calls a minute.Retry guidance
- 429: retry after the X-RateLimit-Reset time with exponential backoff and jitter.
- 400 and 422: do not retry as-is; fix the request. 422 detail is an array of per-field errors.
- 429 end_user_rate_limited: slow down that one end user and retry after Retry-After. Your other users are not affected.
- 402 and 403: do not retry, these persist until the plan or usage state changes.
- 423: do not retry; the account is on a temporary security hold. Contact [email protected] to restore access.
- 404 on barcode lookup: fall back to food search so users can log the item manually.
- 5xx: retry with backoff; if errors persist, check the status page and contact support.
Frequently asked questions
Should I retry 402 quota errors?
No. 402 persists until your monthly cycle resets or you upgrade. Detect it, surface an upgrade path in your admin tooling, and stop retrying.
How do I distinguish a rate limit from a quota error?
Per-minute rate limiting returns 429 with X-RateLimit-* headers; monthly quota exhaustion returns 402. Handle them separately, 429 is transient, 402 is not.
