Skip to content

fix(provider/xai): surface full xai error detail in APICallError.message#15338

Merged
dancer merged 2 commits into
mainfrom
josh/fix-xai-error-detail
May 16, 2026
Merged

fix(provider/xai): surface full xai error detail in APICallError.message#15338
dancer merged 2 commits into
mainfrom
josh/fix-xai-error-detail

Conversation

@dancer
Copy link
Copy Markdown
Collaborator

@dancer dancer commented May 15, 2026

background

xai 4xx errors surfaced as opaque APICallError.message = "Bad Request" regardless of what xai actually returned. the real detail was always in responseBody but never in message, making errors hard to diagnose at a glance.

summary

the error schema in packages/xai/src/xai-error.ts only matched the OpenAI-style shape {error: {message, type, ...}}. xai's Responses API (and Chat Completions, per live testing) returns {code, error: string}, which fails schema validation and causes createJsonErrorResponseHandler to fall back to HTTP statusText.

fix: schema is now a union of both shapes, and errorToMessage extracts the appropriate field per variant.

follow-ups

  • backport to release-v6.0 and release-v5.0

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

TypeScript compilation error: accessing .error.message on XaiErrorData fails because .error can now be a string after the schema was changed to a union type.

Fix on Vercel

@dancer dancer enabled auto-merge (squash) May 16, 2026 06:15
dancer added a commit that referenced this pull request May 16, 2026
dancer added a commit that referenced this pull request May 16, 2026
@dancer dancer merged commit 1293885 into main May 16, 2026
19 checks passed
@dancer dancer deleted the josh/fix-xai-error-detail branch May 16, 2026 06:19
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.0-canary.142 github npm
@ai-sdk/angular 3.0.0-canary.142 github npm
@ai-sdk/langchain 3.0.0-canary.142 github npm
@ai-sdk/llamaindex 3.0.0-canary.142 github npm
@ai-sdk/otel 1.0.0-canary.88 github npm
@ai-sdk/react 4.0.0-canary.143 github npm
@ai-sdk/rsc 3.0.0-canary.143 github npm
@ai-sdk/svelte 5.0.0-canary.142 github npm
@ai-sdk/vue 4.0.0-canary.142 github npm
@ai-sdk/workflow 1.0.0-canary.59 github npm
@ai-sdk/xai 4.0.0-canary.64 github npm

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.

2 participants