AI SDK 4.0 removes the 2.x streaming architecture. Every per-provider stream helper, AIStream and its supporting exports, StreamingTextResponse and streamToResponse are gone from the package. Anything that built a route on a helper wrapping a raw provider response has to move to streamText and the method its result exposes for the same job.

What changed

Before and after

A 2.x route wrapping a provider response and returning it:

import { OpenAIStream, StreamingTextResponse } from 'ai';
export async function openaiRoute(response: Response): Promise<Response> {
const stream = OpenAIStream(response);
return new StreamingTextResponse(stream);
}

The 4.0 shape moves the provider call inside streamText and returns its own response:

import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
export async function route(prompt: string): Promise<Response> {
const result = streamText({ model: openai('gpt-4o'), prompt });
return result.toDataStreamResponse();
}

The Node server case follows the same shape, with pipeDataStreamToResponse() taking the ServerResponse that streamToResponse used to:

import { AIStream, streamToResponse } from 'ai';
export function nodeRoute(response: Response, serverResponse: ServerResponse): void {
const stream = AIStream(response);
streamToResponse(stream, serverResponse);
}

becomes

import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
export function nodeRoute(prompt: string, serverResponse: ServerResponse): void {
const result = streamText({ model: openai('gpt-4o'), prompt });
result.pipeDataStreamToResponse(serverResponse);
}

Migration guidance and its limits

All four changes need a model provider named on the command line or in emendant.json. None has a deterministic patch, because each one restructures the call rather than renaming it: the helper took a raw provider response, and streamText makes the provider call itself, so an edit at the import site alone cannot produce the new shape.

Where a route imports both a provider helper and StreamingTextResponse, the two findings describe one migration rather than two. Move the provider call into streamText first, and the response wrapper falls away with it.

A clean scan proves only that none of the four removed names is imported from ai in the files it walked. It does not prove the route still streams correctly after the rewrite, or that a callback passed to a removed helper’s options was carried over to streamText’s onFinish or onChunk. Typecheck and test the result, as the entry asks.

The next major release reshapes messages, tools and streams. After this migration, read what breaks when you upgrade ai from 4.x to 5.0.

What Emendant detects, fixes and verifies

4 changes in ai 4.0.0. 0 automatic fixes, 4 fixes requiring a model provider you choose, 0 report only. Each patch states which checks passed. Understand patch evidence.

ChangeSeverityDetectsFixVerified by
The 2.x provider stream helpers were removed
ai-npm-4.0.0-legacy-provider-streams-removed
error TS2305: Module '"ai"' has no exported member 'OpenAIStream'.
error TS2305: Module '"ai"' has no exported member 'AnthropicStream'.
Breaking
  • OpenAIStream imported from ai
  • AnthropicStream imported from ai
  • MistralStream imported from ai
  • GoogleGenerativeAIStream imported from ai
  • HuggingFaceStream imported from ai
  • CohereStream imported from ai
  • LangChainStream imported from ai
  • ReplicateStream imported from ai
  • InkeepStream imported from ai
  • AWSBedrockStream imported from ai
  • AWSBedrockAnthropicStream imported from ai
  • AWSBedrockAnthropicMessagesStream imported from ai
  • AWSBedrockCohereStream imported from ai
  • AWSBedrockLlama2Stream imported from ai
Patch, only when you name a model providerYour typecheck and tests
AIStream and its related exports were removed
ai-npm-4.0.0-aistream-removed
error TS2305: Module '"ai"' has no exported member 'AIStream'.
Breaking
  • AIStream imported from ai
  • createCallbacksTransformer imported from ai
  • createEventStreamTransformer imported from ai
  • trimStartOfStreamHelper imported from ai
  • readableFromAsyncIterable imported from ai
Patch, only when you name a model providerYour typecheck and tests
StreamingTextResponse was removed
ai-npm-4.0.0-streamingtextresponse-removed
error TS2305: Module '"ai"' has no exported member 'StreamingTextResponse'.
Breaking
  • StreamingTextResponse imported from ai
Patch, only when you name a model providerYour typecheck and tests
streamToResponse was removed
ai-npm-4.0.0-streamtoresponse-removed
error TS2305: Module '"ai"' has no exported member 'streamToResponse'.
Breaking
  • streamToResponse imported from ai
Patch, only when you name a model providerYour typecheck and tests

emendant explain <change-id> prints any row's entry, guidance and sources at the terminal.

The error TS lines are what TypeScript 5.9.3 printed when code that compiled against ai 3.4.33 was compiled against 4.0.0. A row without one is a change the compiler does not report, such as a deprecation or a change in behaviour.

Coverage

Requires emendant@0.1.0 or later. Run emendant feed update to get the latest coverage.

Coverage details
Snapshot
2026-08-28.1, sequence 11, signed 28 August 2026
Feed entry
feed/npm/ai/4.0.0.json

emendant feed status shows the snapshot your machine holds.

Primary sources

Scan your repository

Find affected code without editing your files.

npx emendant scan

Then npx emendant fix writes the patches the table says exist. The getting started guide covers the flags and the patch grades.

The AI SDK migration guide lists every release page and says which to read for your upgrade.