← Back to Pull requests

Add `retry_after` and class-level retry flags to provider errors #381

Open
anbuzin opened this pull request with 442 lines diff across 4 files
View on GitHub
anbuzin anbuzin commented on Dec 01, 2026 17:53 UTC
Author

Wire retry information into provider errors.

# before
except ai.ProviderInternalServerError: ...     # Anthropic 503 and 504 don't land here
except ai.ProviderAPIError as exc:             # they land here
    delay = float(exc.http_context.response.headers["retry-after"])
ai.ProviderRateLimitError("x").is_retryable    # False

# after
except ai.ProviderInternalServerError as exc:  # 503 and 504 land here
    delay = exc.retry_after                    # 12.0
ai.ProviderRateLimitError("x").is_retryable    # True

Breaking: 503 and 504 are now caught by an except ai.ProviderInternalServerError.

Where this fits

  AIError                                         any failure the SDK raises
  ├─ ConfigurationError                           configuration is missing or invalid
  │  └─ InstallationError                         an optional dependency isn't installed
  ├─ UnsupportedProviderError                     the SDK doesn't know this provider
  ├─ DownloadError                                a URL download failed
  ├─ IntegrityError                               a message history has issues (still a ValueError too)
  ├─ GatewayError                                 an error from the direct AI Gateway client
  │  ├─ GatewayAuthenticationError                401
  │  ├─ GatewayInvalidRequestError                400
  │  ├─ GatewayRateLimitError                     429
  │  ├─ GatewayModelNotFoundError                 404
  │  ├─ GatewayInternalServerError                500
  │  ├─ GatewayResponseError                      the response can't be read
  │  └─ GatewayTimeoutError                       the request timed out
  ├─ ExternalHarnessError                         an external harness (a CLI agent) failed
  │  ├─ UnsupportedError                          the CLI doesn't support the operation
  │  ├─ ExecutableMissingError                    the CLI isn't installed or doesn't run
  │  ├─ NotAuthenticatedError                     the CLI has no usable credentials
  │  ├─ TranscriptMismatchError                   the session can't take these messages
  │  ├─ JsonRpcError                              the harness answered with a JSON-RPC error
  │  └─ _CommandError                             the pi harness refused a command (private)
* └─ ProviderError                                a model provider failed; carries is_retryable and retry_after
     ├─ ProviderNotConfiguredError                no credentials or configuration; nothing was sent
*    └─ ProviderAPIError                          a request to the provider failed
*       ├─ ProviderConnectionError                couldn't connect, or the connection dropped (retryable)
        │  └─ ProviderTimeoutError                the client timed out (retryable)
        ├─ ProviderResponseError                  the response can't be read, e.g. a malformed stream frame
*       │  └─ ProviderIncompleteResponseError     the stream stopped before its end (retryable)
        └─ ProviderStatusError                    an HTTP error status with no class of its own
*          ├─ ProviderBadRequestError             400, or an invalid request reported in a stream
*          ├─ ProviderAuthenticationError         401, or bad credentials reported in a stream
*          ├─ ProviderPermissionDeniedError       403
*          ├─ ProviderNotFoundError               404
           │  └─ ProviderModelNotFoundError       404 for a model ID
*          ├─ ProviderConflictError               409 (retryable)
*          ├─ ProviderRequestTooLargeError        413
*          ├─ ProviderUnprocessableEntityError    422
*          ├─ ProviderRateLimitError              429, or a rate limit reported in a stream (retryable)
*          └─ ProviderInternalServerError         5xx, or the provider failed in a way we can't name (retryable)
*             ├─ ProviderServiceUnavailableError  503 (retryable)
*             ├─ ProviderDeadlineExceededError    504 (retryable)
              └─ ProviderOverloadedError          529 (retryable)

  HookDeferredException                           not a failure: a hook deferred a tool call (stays outside AIError)

Diff: 442 lines (+429 / -13) across 4 files Reviewer: msullivan Review duration: 3475m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.44) × (1 − Review Confidence (0.63)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.44 · 442 lines diff across 4 files
0.44
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.36 · 1 substantive comment(s)
0.36
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
63%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.365
Real PR Conversation Timeline
3 items
vercel[bot] vercel[bot] commented on Dec 01, 2026 17:53 UTC
Bot

[vc]: #y7sjHZfknGCC/V1KTCkYW67ct4lLEQ5kJoNvoyP9VSs=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJhaS1weXRob24iLCJwcm9qZWN0SWQiOiJwcmpfRDg5bUY1TUlndnVuR0UyeVFuZWdQUlM3VnBlMCIsInJvb3REaXJlY3RvcnkiOiJkb2NzL2FpLXB5dGhvbiIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS92ZXJjZWwtbGFicy9haS1weXRob24vSDZqRGpRREJLRlZtcVNxQlMxNHdrRE1rWTFBaCIsInByZXZpZXdVcmwiOiJhaS1weXRob24tZ2l0LXByb3ZpZGVyLWVycm9yLXJldHJ5LmxhYnMudmVyY2VsLmRldiIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsImxpdmVGZWVkYmFjayI6eyJyZXNvbHZlZCI6MCwidW5yZXNvbHZlZCI6MCwidG90YWwiOjAsImxpbmsiOiJhaS1weXRob24tZ2l0LXByb3ZpZGVyLWVycm9yLXJldHJ5LmxhYnMudmVyY2VsLmRldiJ9fV19
The latest updates on your projects. Learn more about Vercel for GitHub.

| Project | Deployment | Actions | Updated |
| :--- | :----- | :------ | :------ |
| <a href="https://vercel.com/vercel-labs/ai-python"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_D89mF5MIgvunGE2yQnegPRS7Vpe0&teamId=team_nO2mCG4W8IxPIeKoSsqwAxxB&s=32" width="16" height="16" align="middle" alt="" /></sup></a> ai-python | !Ready Ready | Preview, v0 | <relative-time datetime="2026-12-01T17:53:58.092Z">Dec 1, 2026 5:53pm UTC</relative-time> |

msullivan msullivan approved these changes on Dec 03, 2026 01:00 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
anbuzin anbuzin
Labels
risk: low confidence: 63% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 43.8% (MEDIUM) · Higher = larger blast radius
43.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 63% · Lower = rushed or shallow review
63%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.2% · Safe to merge
16.2%