Errors
The error shape, every code the API can return, and what to retry.
Environment
Every endpoint except the two OAuth endpoints returns errors in one shape:
json
{
"error": {
"type": "invalid_request",
"code": "invalid_parameters",
"message": "name is required when creating a patient.",
"param": "name",
"requestId": "req_ab12Cd34Ef56"
}
}json
{
"error": {
"type": "invalid_request",
"code": "invalid_parameters",
"message": "name is required when creating a patient.",
"param": "name",
"requestId": "req_ab12Cd34Ef56"
}
}typeis the coarse class, and it determines the HTTP status. Branch on it for retry behavior.codeis the specific reason. Branch on it for anything you want to handle individually. New codes can appear within an existingtype— treat an unknown one as itstype.messageis for your logs and for a human reading them. Do not match on it; it can be reworded at any time.paramis present when one request field caused the failure.requestIdis the same value as theTwofold-Request-Idresponse header. Quote it when you ask us about a request.
POST /oauth/token and POST /oauth/revoke return the standard OAuth error body instead — see Authentication. Authentication failures on those routes (missing or wrong credentials, or a Twofold-Client-Id / form client_id disagreement) answer as RFC invalid_client; the Stripe-style code values below are for every other endpoint.
Error types
type | HTTP | Meaning | Retry? |
|---|---|---|---|
invalid_request | 400 | The request is malformed or the state it asks for is impossible. | No — fix the request. |
authentication_error | 401 | The credential is missing, wrong, expired or revoked. | Only after fixing or refreshing the credential. |
permission_error | 403 | The credential is valid but not allowed to do this. | No. |
not_found | 404 | No such route, or no such object. | No. |
rate_limited | 429 | Too many requests — see Rate limits. | Yes, after Retry-After. |
api_error | 500 | Something failed on Twofold's side. | Yes, with backoff. |
Error codes
Partner key authentication
code | type | What happened |
|---|---|---|
missing_client_id | authentication_error | The Twofold-Client-Id header is absent. |
missing_api_key | authentication_error | No Authorization: Bearer twofold_key_… header. |
invalid_api_key | authentication_error | The key does not exist. |
api_key_revoked | authentication_error | The key was revoked in the console. |
wrong_environment_api_key | authentication_error | A staging key sent to production, or the reverse. |
client_id_mismatch | authentication_error | The key is valid but belongs to a different partner than the client id claims. |
partner_not_activated | permission_error | Production access has not been opened for your organization yet. |
User token authentication
code | type | What happened |
|---|---|---|
missing_access_token | authentication_error | No Authorization: Bearer twofold_access_… header. |
invalid_access_token | authentication_error | The token does not exist. |
access_token_expired | authentication_error | The token expired, or was rotated by a refresh. Refresh and retry once. |
wrong_environment_access_token | authentication_error | A staging token sent to production, or the reverse. |
partner_key_on_user_endpoint | authentication_error | A partner API key was sent to a /v2/users/… endpoint, which takes a provider's access token. |
link_revoked | permission_error | The provider's link has ended. Their data is no longer reachable; send them through consent again. |
external_user_id_mismatch | permission_error | The {externalUserId} in the path is not the one this token was issued for. |
Requests and resources
code | type | What happened |
|---|---|---|
invalid_parameters | invalid_request | A path, query or body parameter failed validation. param names the field. |
user_not_found | not_found | No currently-linked provider with that externalUserId in your organization. |
request_body_too_large | invalid_request | The request body is over the endpoint's size limit. Batch patient upserts take up to 20 MB: send fewer patients per request. |
patient_not_found | not_found | No patient with that patientExternalId for this provider. |
note_not_found | not_found | No note with that noteId for this provider — or one the API does not serve, see Concepts & identifiers. |
note_deleted | not_found | The note existed and was deleted by the provider. Distinct from note_not_found on purpose: you may hold its id from a webhook. |
route_not_found | not_found | No such endpoint — usually a typo or a missing /v2 prefix. |
insufficient_seats | invalid_request | Setting FULL_ACCESS needs a free seat and none is available. Add seats with set-seats or on the Seats page, or set another provider to READ_ONLY first. |
template_not_found | invalid_request | A templateIds entry is not one of your organization's base templates (or it is archived). Copy ids from the partner console. |
seats_not_configured | invalid_request | Your organization has no seat subscription yet — start one on the Seats page, then retry. If that page offers no subscription either, seat pricing is missing on our side: contact Twofold. |
cannot_decrease_seats | invalid_request | totalSeats is below your current seat count. Reducing seats changes what you are billed — contact Twofold. |
seat_limit_reached | invalid_request | The requested total passes what your current plan covers. Contact Twofold to add seats beyond it. |
annual_term_active | invalid_request | seat/start with plan: "monthly" for a provider whose paid annual term has not ended. The message carries the term's end date; send plan: "annual" to resume the term at no charge. |
not_available_in_billing_mode | invalid_request | The endpoint belongs to the other billing mode. On usage billing, access-level and set-seats are replaced by the seat endpoints; on a seat subscription, the seat endpoints are not available. The message names the endpoint to use. |
webhook_url_not_configured | invalid_request | The webhook test-fire has no destination: no webhook URL is configured in the console. |
Twofold-side
code | type | What happened |
|---|---|---|
rate_limit_exceeded | rate_limited | Over the limit. Wait for Retry-After seconds — see Rate limits. |
temporarily_unavailable | api_error | The partner API is deliberately paused. Retry with backoff. |
internal_error | api_error | An unexpected failure. Retry with backoff; if it persists, send us the requestId. |
Handling failures well
- Retry only
429andapi_error. Everything else is a decision you have to make, not a condition that clears itself. - Use exponential backoff with jitter, and cap the number of attempts. A retry storm against a limit you are already over is the one way to make it worse.
- Refresh once, then stop. On
access_token_expired, refresh and replay the call a single time. If it happens again, the link needs attention, not another refresh. - Log
requestIdon every failure. It is the only handle that lets us find the request in Twofold's logs.