Open docs
SDK Guide

Errors, timeouts, and retries

Handle errors by kind, choose time limits, and retry requests safely.

These examples use the latest stable release of the Python SDK.

Every API failure raises a FlashdriveError or one of its subclasses. Invalid arguments are caught before anything is sent and raise ValueError.

Inspect an error

from flashdrive import Flashdrive, FlashdriveError

with Flashdrive(drive_id="DRIVE_UUID") as client:
    try:
        client.files.edit_text(
            "DOCUMENT_UUID",
            [("draft", "final")],
            revision="7",
            idempotency_key="finalize-1",
        )
    except FlashdriveError as exc:
        print(exc.status, exc.code, exc.request_id, exc.details)
        print(exc.error_type, exc.retryable, exc.retry_key, exc.retry_after)

Every error has:

AttributeMeaning
statusThe HTTP status, or None for a failure inside the SDK.
codeA stable code such as stale_version or drive_limit_exceeded. Decide on this, not on the message, whose wording can change.
request_idQuote it when you contact support.
detailsMore about the failure, such as the field or the index of a failed edit.
retry_afterSeconds to wait before retrying, when the service says.
error_typeThe kind of problem, an ErrorType.
retryableA Retryable: never, after_backoff, after_retry_after or after_change.
retry_keyA RetryKey: same to retry with the same idempotency key, new for a new one.

Three properties sum these up: is_retryable (sending the request again can ever succeed), retry_unchanged (the same request can simply be sent again after a wait) and retry_with_same_key. The advice comes from the service's answer, then from the SDK's own list of codes, then from the HTTP status, so even a code newer than your SDK carries advice. Values the SDK does not know stay as the strings the service sent. See the error reference for codes and messages.

Handle a kind of problem

Each kind of error has its own class, so you can handle a kind of problem without knowing every code:

Classerror_typeTypical cause
AuthenticationErrorauthA missing, wrong or revoked key (invalid_credentials).
PermissionDeniedErrorpermissionThe key or token may not do this.
NotFoundErrornot_foundThe drive, folder or file does not exist, or is outside your access.
InvalidRequestErrorinvalidA value the service refused.
ConflictErrorconflictA name taken, an edit that does not apply, or work still in progress.
PreconditionFailedErrorpreconditionThe file changed since you read it (stale_version).
RateLimitErrorrate_limitToo many requests, or the drive's upload capacity is full.
PaymentRequiredErrorpayment_requiredThe workspace's plan or balance needs attention.
QuotaExceededErrorquotaA drive or storage limit (drive_limit_exceeded, storage_capacity_exceeded).
RequestTooLargeErrortoo_largeA file or request over its size limit.
ServiceUnavailableErrorunavailableThe service is busy or briefly unavailable.
UpgradeRequiredErrorupgradeThis SDK version or API version is not supported.
import time
from flashdrive import ConflictError, PreconditionFailedError, RateLimitError

try:
    client.files.write_bytes(document_id, data, revision=revision, offset=0)
except PreconditionFailedError:
    ...  # the file changed: read it again, then decide
except ConflictError as exc:
    ...  # look at exc.code
except RateLimitError as exc:
    time.sleep(exc.retry_after or 1)

A throttled request raises RateLimitError with the message Too many requests. Try again after HH:MM UTC.

Other errors the SDK raises itself:

ErrorWhen
SDKTimeoutError (code sdk_timeout)A call ran out of its timeout.
UploadErrorAn upload failed after the service accepted it; receipt holds what to resume.
UploadTimeoutError (code upload_timeout)An upload's local wait ran out; it is both an UploadError and an SDKTimeoutError.
UploadBatchError (code upload_batch_failed)Some files of an upload failed; see upload recovery.
FileEditErrorA files.write_bytes() call stopped. idempotency_key, drive_id, document_id, base_revision and receipt say how to resume: send the same data, options and revision with that key. A pending receipt does not prove the edit was saved.
FileEditTimeoutErrorA files.write_bytes() time limit ran out and the outcome is unknown; it is both a FileEditError and an SDKTimeoutError. Resume as above.
BulkImportErrorA bulk import stopped. import_id, drive_id and journal say how to resume, and import_status holds the last status, if known.
SDKCompatibilityErrorThis SDK cannot work with the service's API.

Keep the SDK up to date

Two errors ask you to change your installed client or your code:

ErrorHTTP status and codeWhat to do
ClientUpgradeRequiredError426 client_upgrade_requiredThis SDK version is below the oldest one the service supports. Check the available matching release in SDK setup before upgrading. exc.minimum_version and exc.latest_version name the oldest supported and newest releases. It is an SDKCompatibilityError.
APIVersionRetiredError410 api_version_retiredThe endpoint was retired on exc.sunset_at. Switch to exc.replacement, which can be None, and read the guide at exc.docs_url.

Before that happens, the SDK warns you once per notice and process: SDKUpgradeWarning when a newer release is available and SDKDeprecationWarning when something you use is deprecated, with the replacement, retirement date and upgrade command. Control them with Python's warning filters, or pass version_warnings=False to the client. The notices stay available in client.notices. The SDK never upgrades itself.

Choose a time budget

Every call takes timeout, in seconds, for the whole call including retries:

CallDefault timeout
Most calls30
upload()600 for the transfers, plus processing_timeout 600 for processing
documents.replace_file(), uploads.resume(), recursive folders.delete()600
files.edit_text()120
files.write_bytes()120 per request, processing_timeout 3600 overall
files.download()120 for each range request
files.read_bytes()60
folders.ensure()60

Use wait=False on upload() and replace_file() to return once the service has accepted the work. Closing network connections can take a moment longer than the time limit. After a local timeout, use the original key or upload receipt to recover the result: work the service accepted continues.

Automatic retries

The SDK retries a request only when repeating it is safe: reads, and changes that carry an idempotency key. It makes up to three attempts within the call's timeout for HTTP 429, 502, 503 and 504, for request_in_progress, and for dropped connections, waiting at least the Retry-After the service sends. If the wait a 429 asks for would outlast the deadline, the SDK raises the RateLimitError at once. After the last attempt, a dropped connection raises an error with code transport_error.

Calls that change files make their own idempotency key when you do not pass one, so the SDK's retries never apply a change twice. Pass your own idempotency_key when you want to retry the same change yourself, for example after your process restarts. A key is 1 to 128 visible ASCII characters.

Wait for upload capacity

When a drive's upload capacity is full, the service answers 429 upload_limit or 409 request_in_progress. For uploads, the SDK waits and retries with the same key until the transfer deadline, following Retry-After and adding a small random delay to spread out clients. These waits do not use up the three attempts. Files waiting for capacity do not stop the rest of a batch.

For storage_capacity_exceeded, free space or increase your workspace's storage before retrying; see storage and upgrades.

Decide whether to reuse the key

OutcomeNext step
The connection dropped before a reply arrivedRetry the unchanged request with the same key to get the original result.
The request is still running (request_in_progress)Wait, then retry with the same key.
Rate limitedWait for retry_after and retry with the same key.
The file changed (stale_version)Read it again, redo the change if it still applies, and use a new key.
The service refused the inputCorrect it and use a new key for the changed request.
The key was used with different details (idempotency_conflict)Send the original details, or use a new key.

exc.retry_key gives the same advice for any error: same or new.

Copyright © 2026