AI SDK Fixes xAI Streaming Response Truncation Issue with Large Images

AI SDK fixes xAI/OpenAI image generation streams erroring due to event size limits after delivery completes.
Vercel AI SDK released the @ai-sdk/xai@5.0.52 patch, fixing a subtle streaming defect: in the Responses protocol, the response.completed event repeatedly carries all output items including base64 images, so with multiple large images the event size balloons exponentially, breaking the event source handler's default single-event limit and causing the stream to throw an error only after all images have been delivered. The fix adds a maxEventSize option to createEventSourceResponseHandler, with OpenAI and xAI Responses models raising it to 512 MiB, and updates @ai-sdk/provider-utils@5.0.85 in sync. The change is patch-level with no breaking changes, but memory-constrained deployments need to re-evaluate peak usage and explicitly set a smaller limit if necessary.

Vercel's AI SDK has released the @ai-sdk/xai@5.0.52 patch version. The version number itself is unremarkable, but the issue it fixes is worth noting for all developers integrating with the xAI or OpenAI Responses API: when image generation results are large, the streaming response fails only after all images have already been delivered.
What's the Problem: Repetitive Bloat in response.completed
The patch notes pinpoint the root cause. In the Responses streaming protocol, the response.completed event repeats every output item, including base64-encoded image generation results. When generating multiple large images in a single session, this completion event's size grows exponentially and can easily exceed the default single-event size limit of the underlying event source handler.
The symptom is quite deceptive: the images have actually all been delivered, everything looks normal on the user side, and then the stream throws an error. For AI applications that render generation results directly to users, this is a classic "post-delivery failure"—the error occurs at the worst possible moment, and troubleshooting can easily misdiagnose it as a network or authentication issue. According to the commit record for this patch, streams with multiple large generated images did indeed exceed the default limit during processing, causing failure after all images were delivered.
SSE (Server-Sent Events) and Event Source Handlers
The streaming transport underlying the Responses API is generally based on the SSE protocol: the server continuously pushes data: lines over a long-lived HTTP connection, with each event separated by a blank line, and the client parses them one by one. createEventSourceResponseHandler in the AI SDK is a wrapper around this format; it maintains a buffer to accumulate event text that hasn't been fully received, and sets a single-event size limit to prevent abnormal or malicious traffic from blowing up memory.
Understanding this limit is key: base64 encoding inflates raw bytes by about 33%, so a few-MB image becomes over ten MB of text when encoded, and when that's fully repeated in response.completed, a single event easily reaches tens of MB. The default limit is typically designed for ordinary text token streams, which are orders of magnitude smaller, hence the mismatch of "content delivered, but event exceeded limit."
Differences Between the OpenAI Responses API and Chat Completions
The Responses API is OpenAI's newer interface form, distinct from the well-known Chat Completions. It organizes results as "output items," where messages, tool calls, image generations, etc. are each independent items, streamed with semantic events like response.created, response.output_item.added, and response.completed. As the terminal event, response.completed carries a complete snapshot of the response to facilitate final validation and state alignment on the client side.
This "incremental push + final snapshot" design works well for plain text, but once items contain large binary artifacts (such as images), the snapshot degenerates into a second transmission of all artifacts. xAI's Responses-compatible interface follows the same protocol conventions, so both vendors' SDK implementations need to handle this issue in sync.
The Fix: Configurable maxEventSize, Upper Limit Raised to 512 MiB
The core change is concentrated in createEventSourceResponseHandler: a new maxEventSize option allows callers to set the size limit for a single stream event themselves. Both the OpenAI and xAI Responses language models enable this option, raising the threshold to 512 MiB to accommodate completion events that repeatedly carry image data.
This is a pragmatic solution. Compared to deduplicating or compressing completion events at the protocol layer, simply raising the limit has the lowest implementation cost and doesn't change existing event parsing logic. The trade-off is that the memory ceiling for a single event rises accordingly—for services deployed on edge runtimes or memory-constrained containers, this number is worth incorporating into resource planning. This version also updates the dependency to @ai-sdk/provider-utils@5.0.85, with both changes coming from the same commit.
Real-World Constraints of Edge Runtimes and Memory Limits
Edge runtimes like Vercel Edge Functions and Cloudflare Workers typically have only around 128 MB of memory quota, with hard limits on execution duration and memory peaks per request. A 512 MiB single-event limit is theoretically unreachable in these environments—if an event approaching that magnitude were actually received, the process would be terminated by OOM before throwing a catchable parsing error.
Therefore, explicitly setting maxEventSize is not just about "saving memory" but also a fail-fast strategy: setting the limit close to the actual possible artifact size for your business (e.g., tens of MB) allows overages to surface as clear errors at the parsing stage rather than dragging on until a runtime crash. For self-hosted Node services, container memory requests/limits should also match the configured limit to avoid a single stream event bringing down the entire Pod.
Practical Impact for Developers
Projects using the AI SDK to call xAI or OpenAI's Responses interfaces with image generation enabled are advised to upgrade directly. If you've previously encountered the bizarre phenomenon of "image generation succeeds but the stream errors," this patch is very likely the answer.
It should be noted that this is a patch-level change with no breaking API changes, so upgrade risk is low. However, if your service has a strict memory budget, you should re-evaluate peak memory on the stream processing path after upgrading, and if necessary, explicitly set a maxEventSize on createEventSourceResponseHandler that better fits your business, rather than blindly adopting the generous 512 MiB limit.
Summary
A seemingly trivial dependency version update reflects a real contradiction in multimodal streaming protocols: completion events repeatedly carry complete artifacts, and their size grows linearly with artifact size. The AI SDK chooses to absorb this contradiction with a configurable limit, leaving the trade-off to the caller. For teams building image generation applications, this is an underlying fix worth following up on.
One-line Summary
AI SDK fixes the issue where xAI/OpenAI image generation streams error out due to event size limits after delivery completes.
Paragraph Summary
Vercel AI SDK released the @ai-sdk/xai@5.0.52 patch, fixing a subtle streaming defect: in the Responses protocol, the response.completed event repeatedly carries all output items including base64 images, so with multiple large images the event size balloons exponentially, breaking the event source handler's default single-event limit and causing the stream to throw an error only after all images have been delivered. The fix adds a maxEventSize option to createEventSourceResponseHandler, with OpenAI and xAI Responses models raising it to 512 MiB, and updates @ai-sdk/provider-utils@5.0.85 in sync. The change is patch-level with no breaking changes, but memory-constrained deployments need to re-evaluate peak usage and explicitly set a smaller limit if necessary.
Related articles

Nothing CMF Buds 2A Drops to $17.89 on Black Friday: A New Low for ANC Earbuds
Nothing CMF Buds 2A wireless earbuds Black Friday deal: just $17.89 on Amazon, about $11 off retail and a record low. ANC earbuds at an entry-level price.

When AI Creation Gets Accused of "Spitting": Hacker News Heats Up Over the Glaude Controversy
A Hacker News post, "Spitting in the Face of Glaude," sparks debate on AI creation transparency and attribution ethics. This analysis examines the blurred creator identity behind the controversy and offers practical advice for AI content production.

Akai Embraces Custom Firmware: MPC Sample 1.4 Lets Users AI-Program Their Sampler
Akai embraces the modding community with MPC Sample 1.4 firmware, supporting vibe-coded custom firmware and effects. We analyze the impact of this open strategy on music hardware and AI-assisted programming.