Core Concepts

Errors & Idempotency

One JSON error body with a stable code, what each status means, when to retry, and the Idempotency-Key header.

Every error the API returns on purpose has the same JSON body. Each endpoint page lists the errors that endpoint can return, with their codes.

The error body

FieldMeaning
codeStable, machine-readable code such as campaign_not_found. Match on it.
statusCodeThe HTTP status of the response.
messageWhat went wrong, written for people. It can change; do not parse it.
_tagThe error's name, such as CampaignNotFound.
Example

Extra fields

A few errors carry more fields to act on:

CodeStatusExtra fields
rate_limited429retryAfterSeconds: how long to wait before trying again.
subscription_required402preview_leads, plus subscribe_method and subscribe_path: the call that subscribes.
credits_exhausted402remaining, plus subscribe_method and subscribe_path.
team_seat_unavailable402granted: how many seats the plan has.
plan_not_found404planId: the plan that does not exist.
workspace_website_unreadable502domain: the website Bavlio could not read.

Invalid requests

A body, path, query or header that does not match the endpoint's schema is answered with 400 invalid_body, and message describes the first problem found. A body that is not valid JSON gets the message Expected a valid JSON body. Saving a sequence answers 400 sequence_invalid instead.

400

Answers without a JSON body

  • A path the API does not have is answered with 404 and an empty body.
  • A request body sent with a content type other than JSON is answered with 415 and a plain-text body.
  • An unexpected failure on Bavlio's side is answered with an empty 500.

Status codes and retry rules

StatusMeaningRetry?
200OKn/a
201Createdn/a
204Done, with nothing to returnn/a
400The request is invalid: fix itno
401The credential is missing or rejectedno (fix the credential)
402The plan does not cover this: subscribe, or add credits or seatsno
403Your role, or an unverified email address, does not allow thisno
404Nothing with this id in the workspace, or no such pathno
409The request conflicts with the current statemaybe (after a read)
415The request body is not JSONno
429Too many of this action for nowyes (after retryAfterSeconds)
500Unexpected failureyes (exponential backoff)
502A service Bavlio relies on failedyes (exponential backoff)
503Bavlio or a service it relies on is unavailable right nowyes (exponential backoff)

A safe default: retry 429 after retryAfterSeconds, retry 5xx with exponential backoff (at most 5 attempts), and surface everything else straight away.

Idempotency

The two endpoints that send a message to a lead accept an Idempotency-Key header: Send a reply and Approve a review. Use a new unique value, such as a UUID, for every send. It can be 1 to 255 characters long and is remembered for 24 hours in the workspace.

You send the same key again and…Answer
the first call finishedThe first call's outcome. Nothing is sent twice.
the first call is still running409 idempotency_key_in_use: wait a moment and try again.
the first call's outcome is unknown409 idempotency_key_in_use: check the conversation, and send again only with a new key.
the body differs from the first call's400 idempotency_key_reused.
the first call failed before sendingThe key is free again: the retry is a fresh attempt.

No other endpoint takes the header. After a network failure on any other write, read the current state first and retry only if the first call did not land.

FAQ

How do I tell if I should retry?

Retry on 429 after the retryAfterSeconds in the body, and on 5xx with exponential backoff. Do not retry other 4xx answers: fix the request and send it once. The code names the exact cause.

What is the error body?

{ _tag, statusCode, code, message }, plus a few extra fields on some errors. Match on code; message is for people.

What is the difference between 401 and 403?

401 means the credential is missing, malformed, revoked or expired: fix it. 403 means the credential is fine but your role in the workspace does not allow the call, or the call needs a verified email address.