Repository navigation
fix(ai): read provider error messages from common body layouts - #52014
Merged
Merged
Conversation
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.
Problem
The executor only read a provider's error message from
error.messageor a top-levelmessage. Other common layouts fell through to the raw-body fallback added in #51978, so users saw JSON instead of the message:{"error":"Incorrect API key provided..."}Incorrect API key provided...{"detail":"Invalid API Key"}Invalid API Key{"errors":[{"code":10000,"message":"Authentication error"}]}Authentication error{"Message":"Invalid API Key format..."}Invalid API Key format...Fix
packages/ai/src/provider-error.tsexportsproviderErrorMessage(body): a schema union of the common layouts, in priority order:error.message,erroras a string,message,Message(AWS),detail(RFC 9457 problem details),errors[0].message. Blank or non-string values don't match.packages/ai/src/route/executor.tsuses it instead of its own two-field decode. The empty/HTML/raw-body fallback is unchanged.Truly provider-specific layouts (e.g. Mistral's nested 422 validation
message.detail[].msg) are left to the raw-body fallback, or to the provider's protocol if we want them later. Classification and retries are unchanged.Verification
error.messageovermessage, and blank, non-string and non-JSON bodies.bun testinpackages/aiandbun run checkpass.