Errors and retries in the Python SDK

The error classes, what the SDK retries, and how to send a write again without running it twice.

Errors

Every error the SDK raises is a ByteRoverError. An error response from the API is an APIStatusError, with:

FieldMeaning
statusThe HTTP status.
codeThe API's error code, such as NOT_FOUND. Always a string. See Errors and retries.
messageA sentence that says what went wrong; also str(error).
trace_idThe request's trace ID. Quote it when you contact support.
body, headers, responseThe parsed body, the headers and the httpx.Response.
from_gatewayOn a 5xx, True when a proxy in front of ByteRover answered, not ByteRover. Whether the request ran is unknown.

Each status has its own class:

ClassStatus
BadRequestError400
AuthenticationError401
InsufficientBalanceError402
PermissionDeniedError403
NotFoundError404
ConflictError409. code says which conflict, such as VERSION_MISMATCH or UPLOAD_CLOSED.
RateLimitError429
InternalServerError500 and any other 5xx
ServiceUnavailableError503 and 504

Any other error status is a plain APIStatusError. A 2xx whose body isn't JSON, such as a sign-in page from a captive portal, is an APIStatusError with the code INVALID_RESPONSE.

When no response came at all, the error is an APIConnectionError, or an APITimeoutError when the timeout ran out. Its sent is "no" when the connection failed before the request went out, so nothing ran, and "unknown" when the request may have reached the server.

from byterover import APIConnectionError, ByteRover, ConflictError, NotFoundError

client = ByteRover()

try:
    client.documents.update("doc_7n4p1s8v2x5z9b3d6f0h", tags=["policy"], expected_version=4)
except ConflictError as error:
    if error.code != "VERSION_MISMATCH":
        raise
    print("Changed since you read it.")
except NotFoundError as error:
    print("No such document, trace", error.trace_id)
except APIConnectionError as error:
    print("No response; sent:", error.sent)

A redirect is refused, not followed, so the key is only ever sent to base_url.

Some errors come from the SDK's own work: OperationFailedError and WaitTimeoutError from operations.wait, UploadWaitError when an upload completed but waiting for it failed, and UploadIncompleteError when an upload couldn't be finished. See Upload files.

What the SDK retries

A call is retried, up to max_retries times (2 by default), only when that is safe:

  • any call, when the connection failed before the request went out, and on a 429 from ByteRover;
  • a read, also after a timeout, a lost connection, a 5xx or a 429 from a proxy in front of ByteRover;
  • never a write or a search whose outcome is unknown: a timeout, a lost connection or a 5xx. The write may have run, and the search may have been charged.

Between attempts the SDK waits a random time that grows with each attempt, up to 8 seconds, or the time the API asks for with Retry-After. When the API asks for more than a minute, you get the error at once. Set max_retries=0, on the client or on one call, to retry nothing.

operations.wait retries its polls itself until its timeout, so its polls don't use the client's max_retries. See Wait for the work a write started.

Send a write again

Every write sends an Idempotency-Key: a new one for each call, kept across that call's retries. A search sends one only when you pass idempotency_key. The API keeps the reply to a key only if the write succeeded. A copy sent while the first is still running waits on the server for its reply, for up to 150 seconds. The SDK's default timeouts end sooner (60 seconds for a write, 105 or 135 seconds for a search), so such a copy usually ends with an APITimeoutError whose sent is "unknown"; send it again with the same idempotency_key. You get a ConflictError (CONFLICT) only when the call's timeout is longer than that wait.

So after an unknown outcome, send the write again with the same idempotency_key you passed: if the first try succeeded you get its reply, if it is still running the copy waits for it, and the write runs again only if it failed. If you didn't pass a key, the SDK's key is gone, so check the state first, with documents.retrieve, documents.list or operations.retrieve, and only then send the write again, with a key of your own:

drive_id = "drv_4h7k2m9q8r1t5v6w3x0y"
text = "# Standup\n\nShipped the refund page."

client.documents.put_text(drive_id, path="/notes/2026-11-15.md", text=text, idempotency_key="notes-2026-11-15")

A key the SDK made is lost if your process stops. Pass your own when a write must survive a crash. The API keeps keys for 24 hours. See Idempotency.

On this page