Skip to main content
Every API and network failure raises one exception: SquareCloudAPIError. Examples use the client from Creating the client. app_id is the id of one of your apps: client.account.me() lists them.

SquareCloudAPIError

SquareCloudAPIError is a subclass of Exception. str(error) is <METHOD> <path>: HTTP <status> <CODE>: <message>, without HTTP <status> when the status is 0 and without : <message> when the message is empty. Two failures are not wrapped:
  • An empty or whitespace-only API key raises a ValueError in the client constructor.
  • Local file problems raise an OSError: an upload path that cannot be opened, a file that becomes unreadable mid-upload, or a download_snapshot destination that cannot be written.

SDK codes

Codes are strings

code is a plain str: the SDK has no enum of codes. The docstring of SquareCloudAPIError lists every known API code. RATE_LIMIT and RATE_LIMIT_EXCEEDED are still listed there, marked deprecated: the API now answers RATE_LIMITED for both. The list of API codes grows. Handle an unknown code by its HTTP status:

API error codes

Every other code comes from the API. The API error reference lists each one with its HTTP status, meaning and fix, and each SDK page lists the codes its methods return most often. Any call can also answer 401 ACCESS_DENIED (a bad key), 403 MISSING_SCOPE or RESOURCE_NOT_ALLOWED (the limits of the key), 429 (see Rate limits) or 503 DATABASE_UNAVAILABLE. ai.chat() errors use lowercase OpenAI codes instead (access_denied, rate_limit_exceeded, server_overloaded, …). See AI.

Retries

The SDK only retries what is safe to repeat, up to max_retries times (default 2, so up to 3 attempts): It never retries:
  • TIMEOUT;
  • any 429: RATE_LIMITED can be a block of about 30 minutes, and KEEP_CALM is not retried either;
  • other 5xx;
  • AI errors.
503 DATABASE_UNAVAILABLE can arrive after a mutation was already applied, so the SDK does not retry it outside GET. Retry your own idempotent mutations if you need to. The wait before retry n (starting at 0) is min(8 s, 500 ms · 2^n) · U(0.5, 1): exponential backoff with 50% to 100% jitter. Set max_retries=0 to turn retries off.

Timeouts

timeout (30 s) applies per socket operation (the connect and each read or write), not to the whole request. See Timeouts for the calls with a 120 s floor and the calls with no timeout. A timeout raises TIMEOUT with status 0 and is never retried.

Rate limits

Every account has a limit of requests per 60 seconds, set by its plan (values), and some routes have their own:
  • 429 RATE_LIMITED: the account or API key went over its request budget and is blocked for about 30 minutes, or an IP that keeps sending invalid keys is blocked for a short period. Also the limit of the network endpoints and account.snapshots.
  • 429 KEEP_CALM: too many calls to one route in a short time.
The SDK never retries a 429. Slow down, and wait before trying again.

Next steps

API error reference

Every error code, with its meaning and fix.

Limits and restrictions

The request limits of each plan.