Raise `ModelQuotaExceededError` instead of `ModelRateLimitError` for Z.ai balance and plan-limit 429s

Merged
DO
1mo ago
+69-0

ZaiModel raised ModelRateLimitError for every Z.ai 429, including an exhausted balance and plan limits that waiting can't clear, so retry and backoff on ModelRateLimitError kept retrying them.

[!WARNING]
Compatibility impact: Existing code that catches ModelRateLimitError to handle a Z.ai 1113 (insufficient balance) or 1308–1321 (plan and usage limit) error will no longer catch it: it's now a ModelQuotaExceededError, still a ModelHTTPError with status 429.

Why this can ship in a minor release: It fixes a misclassification. OpenAI's insufficient_quota family got the same treatment when the categories were introduced (#9354), and except ModelHTTPError / except ModelAPIError and the default fallback_on are unaffected.

Migration: Catch ModelQuotaExceededError (or ModelRateLimitError | ModelQuotaExceededError) to handle these errors.

Z.ai's error codes tell these errors apart only by the error.code in the body. _model_errors.zai_code_category maps the quota codes to ModelQuotaExceededError, and _status_error applies it only when the provider is zai, because the numeric codes mean nothing from other OpenAI-compatible APIs. 1302 (request rate) and 1305 (overload) keep their status-based categories. The code list matches the one #11041 keeps in the gh-aw shim, and Z.ai's docs (1312 doesn't exist).

The mapping keys on the provider, not the model class, since it's Z.ai's server that sends the codes: OpenAIChatModel on ZaiProvider gets it too, while ZaiModel on a plain OpenAIProvider pointed at Z.ai's URL doesn't.

Tests in tests/models/test_error_categories.py: 1113 and 1310 raise ModelQuotaExceededError (both failed before the fix), 1302 stays a ModelRateLimitError, and the same 1113 code from OpenAIChatModel on OpenAI stays a rate limit.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code