Image generation enters the AI SDK

The AI SDK, an open-source toolkit for building AI applications with JavaScript and TypeScript, has reached version 4.1. The release focuses on expanding the types of outputs developers can generate and making streaming, persistence, and tool calls more practical for production use.

The headline feature is experimental support for image generation through a new generateImage function. The unified API works across Replicate, OpenAI, Google Vertex, and Fireworks, and lets you control image dimensions via size or aspectRatio, generate multiple images in parallel with n, access results in base64 or uint8Array formats, and set randomness with seed. Provider-specific options pass through the providerOptions parameter.

Switching between providers requires changing only a couple of lines, as prompts and settings remain unchanged. This matters because the model ecosystem is moving fast — Replicate alone supports hundreds of image models, with more added continuously.

More control over server-side streams

Stream transformation tools are another area of focus. The built-in smoothStream transform can normalize chunky or inconsistent provider responses into a more natural flow, with custom chunking options by character, word, or line. Transformations are composable — you can pass an array of them to apply filtering, guardrails, or custom logic such as uppercasing text in sequence.

Streaming is no longer limited to returning the result of a single LLM call. The new createDataStreamResponse function returns immediately and lets you stream data on demand, giving full control over when and what gets streamed. This enables patterns like sending RAG context or search results to the client before the LLM response begins. The streamed data is handled automatically by the useChat hook, so client code can access message content and additional streamed data without extra wiring.

Persistence and structured outputs get simpler

Persistence with useChat required fewer moving parts. The chat ID can now be forwarded from client to server, response message IDs can flow from server to client, and a new appendResponseMessages utility unifies messages for straightforward saving.

Structured output capabilities also expanded. The most requested addition is combining structured outputs with tools via the new experimental_output option in both generateText and streamText. This lets a model interact with external systems and return predictably structured data in a single call, rather than making separate calls for each step. Complex flows with unpredictable inputs or multiple potential tool paths become more efficient and maintainable. Currently, this feature works with OpenAI models only.

Error handling for structured outputs gives you more to work with than a bare failure. The new NoObjectGeneratedError exposes the raw model output, complete request context (response ID, timestamp, model), and token usage and cost analytics. That means you can debug or salvage partial responses instead of simply retrying.

Tool calls get more context and repair options

Tools remain central to production AI apps, and several changes make them more robust. The execute function now receives a second parameter with useful context: toolCallId for tracking specific executions, a messages array with the full conversation history including previous tool calls and results, and an abortSignal for canceling long-running operations.

When tool calls fail, the experimental_toToolCallRepair function can attempt fixes by using a model with structured outputs to regenerate arguments, sending the messages and tool schema to a stronger model, or following more specific instructions based on which tool was called.

Error handling has also become more granular with distinct types: NoSuchToolError for calls to undefined tools, InvalidToolArgumentsError for schema validation failures, ToolExecutionError for runtime issues, and ToolCallRepairError for failures during automatic repair attempts. Each error type includes contextual data to help diagnose and fix the underlying problem.

Provider updates land across the ecosystem

The AI SDK's provider layer sees several additions and refreshes in this release. The Google Vertex AI integration gets a comprehensive update promising better performance, improved error handling, and support for search grounding. The OpenAI provider has been reworked for full compatibility with the latest reasoning models.

A notable structural change is the introduction of a dedicated OpenAI Compatible provider, giving developers a standardized path for connecting to any OpenAI-compatible API. Several platforms that previously lacked first-party integrations now have them:

  • Replicate, for image models
  • Fireworks, covering language and image models
  • Cohere, covering language and embedding models
  • Together AI, for language models
  • DeepInfra, for language models
  • DeepSeek, for language models
  • Cerebras, for language models

Where to go from here

With image generation, non-blocking data streaming, and more capable tool calling now in place, the release targets developers building new applications from scratch. The latest guides in the cookbook cover common recipes, while the Template Gallery demonstrates the SDK in realistic scenarios. Community discussion happens over on GitHub Discussions.

Release credits

AI SDK 4.1 is the work of Vercel's core team — Lars, Jeremy, Walter, and Nico — together with a substantial list of community contributors who had pull requests merged into this release: patelvivekdev, zeke, daviddkkim, klren0312, viktorlarsson, richhuth, dragos-cojocaru, olyaiy, minpeter, nathanwijaya, timconnorz, palmm, Ojansen, ggallon, williamlmao, nasjp, ManuLpz4, aaronccasanova, marcklingen, aaishikasb, michael-hhai, jeremypress, and yoshinorisano.