Founding churches get 50% off for 12 monthsFounding churches: 50% offApply as a founding churchApply

Errors

An error has an HTTP status that tells you the class of problem and a stable code that tells you which one. Write your handling against the code, never the sentence.

Error shapes#

Most errors come from the route itself and are application/problem+json:

{
  "title": "Not Found",
  "status": 404,
  "detail": "That teaching is not in this church.",
  "code": "not_found"
}

A few checks run before any route: authentication, rate limits, a missing Idempotency-Key. They answer application/json in the shape of the success envelope:

{
  "status": false,
  "message": "That API key is not valid.",
  "code": "invalid_api_key"
}

Both carry code, and every error the API returns is JSON with a code, including unknown routes, unsupported methods and content types, validation failures and server errors. The sentence (detail or message) is written for people and its wording can improve, so show it if you like, but do not match on it.

Validation errors#

When a request body or a parameter does not fit the schema, the code is validation_failed, detail is validation failed, and an errors array lists each problem with the location of the value:

{
  "title": "Unprocessable Entity",
  "status": 422,
  "detail": "validation failed",
  "errors": [
    {
      "message": "expected length >= 2",
      "location": "query.q",
      "value": "a"
    }
  ]
}

Unknown routes#

A path that does not exist answers 404 not_found and a method a route does not support answers 405 method_not_allowed with an Allow header. Both mean your URL or method is wrong.

Handling errors#

  • 400, 403, 404, 409, 422: the request will not succeed as sent. Fix it, or show the person a message. Do not retry the same request.
  • 401: the key is missing, wrong, revoked or expired. Stop and alert someone.
  • 429: rate limits are worth retrying after Retry-After. Spend and teaching caps are not: they clear when the period rolls over or someone raises the cap.
  • 500 and 503: retry with exponential backoff and the same Idempotency-Key.
try {
  await lectern("/teachings/tch_does_not_exist");
} catch (error) {
  if (error instanceof LecternError) {
    console.log(error.status, error.code, error.message, error.requestId);
  } else {
    throw error;
  }
}

Keep the request id (X-Request-Id) in your logs next to the error. See Rate limits for a retry helper that follows these rules.

Codes from checks before the route#

CodeHTTPMeaning and fix
credential_conflict400The request had both an Authorization header and a browser session cookie. Send only the key.
key_in_url400The key was in the query string. Move it to the Authorization header and revoke the leaked key.
invalid_api_key401No key, a malformed key, or a key that is revoked, expired or unknown. The response carries WWW-Authenticate.
ip_not_allowed403The key has an IP allowlist and the request came from another address. Call from an allowed address or edit the list.
idempotency_key_required422A route that starts work needs an Idempotency-Key header. Add one.
rate_limited429This key went over its requests per minute. Wait Retry-After seconds.
org_rate_limited429The church as a whole went over its ceiling across all keys. Wait Retry-After seconds.
Content and key errors

Reusing an Idempotency-Key with a different body answers 422 idempotency_key_reused. A request body that is not JSON answers 415 unsupported_media_type, and one that is too large answers 413 payload_too_large.

Codes from routes#

CodeHTTPMeaning and fix
bad_request400The request could not be read, for example malformed JSON. Fix the body.
invalid_id400An id in the path or body is not a valid Lectern id. Pass ids exactly as returned.
invalid_include400include on a teaching had an unknown value. Use transcript or latest_note.
insufficient_scope403The key lacks the scope the route needs. The detail names it. Create a key with the scope.
forbidden403The key is not allowed to do that.
plan_hours_exhausted403The church has used the hours included in its plan. A person at the church needs to act in Lectern.
not_found404Nothing with that id in this church. A key never sees another church, so a wrong slug is also 404.
note_not_found404The teaching has no note at all.
note_not_approved404A note exists but nobody has approved it yet. Wait for the note.approved event.
duplicate_teaching409That video is already in the church.
transcript_not_ready409The teaching is still being prepared. Wait until status is done.
answer_pending409The last question in this conversation is still being answered. Wait for it, then ask again.
webhook_not_active409The endpoint is paused or disabled. Turn it back on with PATCH.
conflict409The request conflicts with the current state.
precondition_failed412A precondition on the request did not hold.
unsupported_url422Only YouTube video links are accepted by POST /teachings. Upload other recordings.
invalid_question422A question is 2 to 500 characters.
invalid_query422A search is 2 to 300 characters.
webhook_url_not_allowed422Webhooks need a public https address on port 443. Localhost and private networks are refused.
validation_failed422The body or a parameter failed validation, or an upload failed a check. The errors array or the detail says which.
idempotency_key_reused422The Idempotency-Key was already used with a different body. Use a new key.
method_not_allowed405That route does not support the method. See the Allow header.
unsupported_media_type415The body is not JSON. Send Content-Type: application/json.
payload_too_large413The request body is too large.
key_daily_cap_reached429This key reached its daily spend cap.
key_monthly_cap_reached429This key reached its monthly spend cap.
org_api_cap_reached429The church reached its monthly API spend cap.
monthly_teaching_limit_reached429This key reached its monthly limit of submitted teachings.
signing_unavailable503Webhook signing is not available on this server.
unavailable503The service is temporarily unavailable. Retry with backoff.
internal500Something went wrong on our side. Retry with backoff and quote the request id if it persists.

Upload codes#

CodeHTTPMeaning and fix
unsupported_type422The file extension is not accepted. See media_extensions and text_extensions in the policy.
file_too_large422The file is over the limit. Save just the audio, which is much smaller.
recording_too_long422The recording is longer than max_hours.
duration_unknown422The length of the recording could not be read.
size_mismatch422The bytes you sent do not add up to size_bytes.
wrong_file_type422The file’s contents do not match its extension.
empty_transcript422The transcript file has no text.
parts_missing409Not every part has arrived. Read the upload and send the rest.
upload_closed409The upload is finished, cancelled or expired.
still_finishing409A previous call to complete is still running.
upload_quota_reached403The church reached its upload storage quota.
ai_budget_reached403The church reached its AI budget.
too_many_uploads429Too many uploads are in progress. Finish or cancel one.
storage_unavailable502Storage could not be reached. Retry.
uploads_unavailable503Uploads are not set up on this server.
When in doubt, use the status

If your code meets a code it does not know, handle it by HTTP status: 4xx is yours to fix, 5xx is worth a retry.

Next steps