Errors and the fix field
Every error response from PolicyGrain uses one JSON shape designed so both people and coding agents know what went wrong and what to do next. Error messages never echo submitted keys, emails or codes.
The error object
json
{
"code": "missing_scope",
"message": "This key doesn't have the \"evidence:read\" scope.",
"field": "scopes",
"fix": "Use a key with the \"evidence:read\" scope, or create one with POST /v1/keys {\"scopes\": [\"evidence:read\"]} from a key or session that has it."
}- code
- Stable machine-readable snake_case identifier for branching.
- message
- One plain sentence stating what failed.
- field (optional)
- The request field that caused the error, when tied to a specific input.
- fix
- Concrete next step telling the caller or agent how to recover without guessing.
401 responses also include WWW-Authenticate: Bearer realm="policygrain". 429 responses include a Retry-After header in whole seconds.
Built error codes (identity)
| HTTP | code | field | When returned |
|---|---|---|---|
| 400 | invalid_body | — | Body is not a JSON object. |
| 400 | email_with_key | POST /v1/keys received both an Authorization header and an email. | |
| 400 | invalid_email | Email address is missing or malformed. | |
| 400 | invalid_scopes | scopes | Scopes list is empty or contains an unknown scope. |
| 400 | invalid_sign_in_code | — | POST /v1/auth/code did not receive a six-digit string. |
| 400 | sign_in_state_mismatch | — | Callback state cookie is missing, expired (10 min) or mismatched. |
| 400 | sign_in_failed | — | WorkOS did not confirm the sign-in callback. |
| 400 | sign_in_code_rejected | — | Emailed six-digit code is wrong, expired or already used. |
| 401 | auth_required | — | Route requires Authorization: Bearer and none was sent. |
| 401 | invalid_credential | — | Bearer key or session token is malformed or unknown. |
| 401 | key_revoked | — | Presented API key was revoked. |
| 401 | session_expired | — | 15-minute session token expired or was signed out. |
| 401 | refresh_required | — | No valid pg_refresh cookie on POST /v1/auth/refresh (or rotated token reused past grace). |
| 403 | key_suspended | — | Key was created before account claim and awaits POST /v1/keys/{id}/keep. |
| 403 | keep_needs_person | — | An API key tried to call POST /v1/keys/{id}/keep; only a web session may. |
| 403 | missing_scope | scopes | Credential lacks the scope required by the route. |
| 403 | scope_not_held | scopes | Caller tried to mint a key with a scope it does not hold. |
| 403 | account_unverified | — | Unverified account tried to use evidence:read. |
| 403 | email_not_verified | — | WorkOS returned an unverified email. |
| 403 | origin_not_allowed | — | Web-only route (/v1/auth/refresh or /v1/auth/code) called from a disallowed Origin. |
| 404 | key_not_found | — | No key with that id belongs to the caller's account. |
| 404 | link_not_found | — | Link token does not exist. |
| 409 | account_claimed | — | Email is already linked to a different WorkOS user. |
| 409 | refresh_conflict | — | Another tab rotated the same refresh cookie within the last 10 seconds. |
| 410 | link_expired | — | Link token passed its expiry time. |
| 410 | link_revoked | — | Link token was revoked by its owner. |
| 413 | body_too_large | — | Request body exceeded the 8 KB limit on identity routes. |
| 429 | rate_limited | — | Caller hit a rate limit; wait Retry-After seconds. |
| 503 | sign_in_unavailable | — | WorkOS sign-in is not configured on this server. |
| 503 | sign_in_provider_unavailable | — | WorkOS did not answer during code check; the try was refunded. |