API 参考异常

基础异常

typesafe_sdk.TypeSafeError

基类:Exception

SDK 失败的基础异常。

HTTP 错误

typesafe_sdk.TypeSafeAPIError

基类:TypeSafeError

一次不成功的 HTTP 响应,附带其正文和请求元数据。

status

instance-attribute

python
status = status

HTTP 响应状态码。

body

instance-attribute

python
body = body

服务器的 JSON 错误正文或纯文本响应内容;主体为空时为 None。

headers

instance-attribute

python
headers = headers

HTTP 响应头。

endpoint

instance-attribute

python
endpoint = endpoint

请求方法和 URL,不含凭据、查询参数或片段(在可用时提供)。

request_id

property

request_id: str | None

x-typesafe-request-id 响应头;如果缺失则为 None。

typesafe_sdk.TypeSafeBadRequestError

基类:TypeSafeAPIError

请求无效(400)。

typesafe_sdk.TypeSafeAuthenticationError

基类:TypeSafeAPIError

认证失败(401)。

typesafe_sdk.TypeSafePermissionDeniedError

基类:TypeSafeAPIError

访问被拒绝(403)。

typesafe_sdk.TypeSafeNotFoundError

基类:TypeSafeAPIError

资源未找到(404)。

typesafe_sdk.TypeSafeUnprocessableEntityError

基类:TypeSafeAPIError

请求未通过服务器端验证(422)。

typesafe_sdk.TypeSafeRateLimitError

基类:TypeSafeAPIError

超出速率限制(429)。

retry_after_ms

instance-attribute

python
retry_after_ms = parse_retry_after(headers)

服务器要求的等待时间(毫秒);如果不可用则为 None。

typesafe_sdk.TypeSafeInternalServerError

基类:TypeSafeAPIError

服务器未能处理该请求(5xx)。

连接错误

typesafe_sdk.TypeSafeAPIConnectionError

基类:TypeSafeError, ConnectionError

请求失败且未收到 HTTP 响应。

typesafe_sdk.TypeSafeAPITimeoutError

基类:TypeSafeAPIConnectionError, TimeoutError

请求超出了其配置的超时时间。

timeout

instance-attribute

python
timeout = timeout

该请求使用的超时设置,以秒为单位,或为 httpx2.Timeout。

响应验证

typesafe_sdk.TypeSafeAPIResponseValidationError

基类:TypeSafeAPIError

一次成功的 HTTP 响应,但其正文缺少必需数据,或必需数据在结构上无效。

field_path

instance-attribute

python
field_path = field_path

指向问题字段的点分路径,例如 answers.tone.confidence。

args

instance-attribute

python
args = (
    status,
    body,
    headers,
    field_path,
    endpoint,
)