Repository navigation
fix(ai): classify gateway account limits as quota and keep 4xx non-retryable - #49195
Merged
Merged
Conversation
rekram1-node
force-pushed
the
zen-errors
branch
2 times, most recently
from
September 16, 2026 02:53
edbb75c to
03cdf8a
Compare
rekram1-node
force-pushed
the
zen-errors
branch
from
September 16, 2026 03:24
03cdf8a to
7f3a08a
Compare
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QuotaExceededGoUsageLimitError,FreeUsageLimitError,CreditLimitExceeded) toQUOTA_CODESbudget exceededandusage limitSERVER_CODES/exhausted/unavailablecodes classify a 4xx response as retryableProviderInternal; they still decide when there is no HTTP status (stream error events) or the status is <400 (xAI JSON errors on HTTP 200)Why
OpenCode Zen (
inference-next) emits its own account and routing errors througherrorResponse. Errors with a configured publictypekeep it; every other one is wrapped as{"error":{"type":"server_error",...}}(OpenAI skins) orapi_error(Anthropic skin) regardless of status. Its adapters do the same substitution for upstream codes outside their allow-lists. Fed throughclassifyProviderFailureonv2:GoUsageLimitErrorRateLimitFreeUsageLimitError(daily cap,retry-afterup to 24h)RateLimitCreditLimitExceededInvalidRequestInsufficientFunds/ invoice overdue asserver_errorProviderInternalLimitExceeded"Account budget exceeded" asserver_errorRateLimitRegionUnavailable,ModelNotFoundasserver_errorProviderInternalAll now classify as
QuotaExceededorInvalidRequestand are not retried. This mirrors the status-first rule the OpenAI and Anthropic SDKs already apply: a 4xx is a rejection of this request whatever label a gateway attached.Behavior change worth reviewing
executor.test.tspreviously asserted that{"code":"resource_exhausted"}on HTTP 400 classifies asProviderInternal. That case was ported from V1 commit91db82c138, where the xAI check lived in the branch for errors without an HTTP status; the 400 was the port's assumption, not observed provider behavior. The status-less and HTTP-200 shapes remain covered inprovider-error.test.ts; the executor test now asserts the inverse.core/test/aisdk.test.tshad the same 400 +api_errorpairing to prove data-only codes are read; it now usesrate_limit_error, which is honored regardless of status, so the assertion still depends on the code being read. Bedrock's genuine throttling-on-400 is in the rate-limit branch and is unchanged.Verification
bun testinpackages/ai: 1,392 pass / 28 skip; new tests cover each Zen shape above plus the no-status and HTTP-200 server-code casesbun run check