Skip to content

fix(ai): read provider error messages from common body layouts - #52014

Merged
rekram1-node merged 1 commit into
v2from
provider-error-messages
Sep 29, 2026
Merged

rekram1-node merged 1 commit into
v2from
provider-error-messages

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Problem

The executor only read a provider's error message from error.message or a top-level message. Other common layouts fell through to the raw-body fallback added in #51978, so users saw JSON instead of the message:

Provider Body Shown before Shown now
xAI, Baseten {"error":"Incorrect API key provided..."} raw body Incorrect API key provided...
Mistral, NVIDIA {"detail":"Invalid API Key"} raw body Invalid API Key
Cloudflare {"errors":[{"code":10000,"message":"Authentication error"}]} raw body Authentication error
Bedrock (some 403s) {"Message":"Invalid API Key format..."} raw body Invalid API Key format...

Fix

  • packages/ai/src/provider-error.ts exports providerErrorMessage(body): a schema union of the common layouts, in priority order: error.message, error as 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.ts uses 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

  • Live, through the executor: xAI, Mistral, Baseten, NVIDIA, Cloudflare and Groq all show the provider's message (table above).
  • New tests cover each layout, priority of error.message over message, and blank, non-string and non-JSON bodies.
  • bun test in packages/ai and bun run check pass.

@rekram1-node
rekram1-node merged commit 2aaa265 into v2 Sep 29, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the provider-error-messages branch September 29, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant