feat: normalize mid-stream provider error events into public typed errors with provider-owned status and retry metadata (#18671)
## Background Official providers can report structured failures after streaming starts, but applications previously received unknown objects or strings and had to inspect provider payloads or match messages to make retry decisions. A stable public error contract is needed independently of automatic stream retry support. ## Summary Adds the exported marker-based StreamProviderError and normalizes well-formed mid-stream failures while preserving messages, provider type or code discriminators, explicit and provider-owned status codes, conservative retryability, raw payloads, existing same- and cross-realm Error instances, and identity across callbacks and consumers. Shared provider-utils metadata transport supplies adapter-owned mappings for Anthropic, OpenAI, DeepSeek, Moonshot AI, Groq, and xAI, including xAI response.failed events. Gateway metadata survives serialization, permanent insufficient_quota failures are non-retryable, numeric HTTP codes do not replace provider types, and provider specification error fields remain unknown for compatibility. ## Testing Runtime and public type coverage includes typed, message-only, nested, explicit-metadata, retryable, non-retryable, malformed, false-positive, numeric-code, existing-error, and cross-realm cases. Actual Anthropic, OpenAI, Gateway, DeepSeek, Moonshot AI, Groq, and xAI adapters are exercised through streamText in Node and Edge, including raw data, metadata, and callback/consumer identity. Added permanent insufficient_quota regressions for OpenAI, DeepSeek, and xAI. Focused suites and the final full repository test suite passed. ## End-to-end Validation - The application-managed retry example classified an overloaded event as retryable with status 529, discarded buffered partial output, retried, and completed. - Live OpenAI, DeepSeek, and xAI streams completed successfully in this iteration. - Earlier branch validation also completed live Anthropic, Groq, and xAI streams successfully. ## Documentation Updates Core error handling, the streamText API reference, AI Gateway documentation, and the error index; adds the AI_StreamProviderError reference page; and documents conservative classification, provider type/code discrimination, partial-output retry considerations, and an application-managed retry example. ## Related Issues Fixes #18669 --------- Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com> Co-authored-by: ai-sdk-factory[bot] <305873210+ai-sdk-factory[bot]@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
A
ai-sdk-factory[bot] committed
35841f5d43e7407e49f3d4c4e005b8334ca20376
Parent: 6e27135
Committed by GitHub <noreply@github.com>
on 8/25/2026, 10:34:10 PM