Skip to content

fix(core): read provider errors from plain AI SDK stream errors - #51194

Merged
rekram1-node merged 1 commit into
v2from
aisdk-error-message
Sep 24, 2026
Merged

rekram1-node merged 1 commit into
v2from
aisdk-error-message

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

N/A. Found while testing default output limits for #51021.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Provider errors that the AI SDK streams as plain objects now keep their message and classification. Before, they showed up as "[object Object]" and were retried as unknown errors.

The Vercel AI Gateway streams upstream rejections as plain objects, not Error instances. Two shapes came up live:

{ "name": "AI_TypeValidationError", "cause": { ... },
  "value": { "error": { "code": "invalid_parameter_error", "type": "invalid_request_error",
    "message": "<400> InternalError.Algo.InvalidParameter: Range of max_tokens should be [1, 32768]" } } }

{ "code": "invalid_request", "message": "Unable to submit request because This model does not support system instructions.." }

unknownErrorMessage called String(error) on these, and the fallback always built an UnknownProviderError, which the runner retries.

  • Message: it is read from the object's message or error.message, including under value. When there is none, it falls back to "Provider request failed".
  • Classification: the fallback goes through RequestExecutor.httpFailure, the same classifier as HTTP failures, using the object (or its value) as the error data. The first shape carries invalid_request_error, which already classifies as an invalid request.
  • invalid_request: added to the invalid-request codes. It is the gateway's code for an upstream rejection.

How did you verify your code works?

  • Unit test: both gateway shapes keep their message and classify as invalid requests. The packages/core AI SDK suites and the full packages/ai suite pass.

  • Live through the Vercel AI Gateway, with feat(core): fit output limits to the context window #51021 applied:

    Model Before After
    alibaba/qwen3-max-thinking max "[object Object]", 11 attempts "Range of max_tokens should be [1, 32768]", 1 attempt
    google/gemini-omni-flash-preview "[object Object]", 11 attempts "This model does not support system instructions", 1 attempt

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@rekram1-node
rekram1-node merged commit e796f2f into v2 Sep 24, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the aisdk-error-message branch September 24, 2026 18:52
@e-ivkov e-ivkov mentioned this pull request Sep 29, 2026
1 task done
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