Exceptions#

class saia_python.SAIAError(message: object, *, status_code: int | None = None, response_body: str | None = None)[source]#

Base exception for all SAIA API errors.

Parameters:
  • message – Human-readable error message.

  • status_code – The upstream HTTP status, when the error came from a response (None for client-side errors).

  • response_body – The raw upstream body, preserved so a caller can surface exactly what the server sent.

class saia_python.AuthenticationError(message: object, *, status_code: int | None = None, response_body: str | None = None)[source]#

Raised on 401/403 responses — invalid or missing API key.

class saia_python.RateLimitError(message: object, rate_limits: object = None, *, status_code: int | None = None, response_body: str | None = None)[source]#

Raised on 429 responses — rate limit exceeded.

Carries rate_limits (the parsed RateLimitInfo) and, when raised by raise_for_status(), an informative message built by format_rate_limit_error().

class saia_python.APIError(message: object, status_code: int | None = None, response_body: str | None = None)[source]#

Raised on unexpected HTTP errors.

class saia_python.StructuredOutputError(message: object, *, response: dict, finish_reason: str | None = None)[source]#

Raised when a chat response holds no answer that validates against the requested structured-output model.

The HTTP call itself succeeded, so status_code is None; the message says why the answer is unusable. The response stays attached, so a caller can still read usage (the tokens were spent) or inspect the raw content.

Variables:
  • response – The chat response dict the answer was read from.

  • finish_reason – The first choice’s finish_reason — "length" means the token budget ran out — or None when there was no choice.