liveBook · Manning

simulateReadableStream

As explained in Build AI-Enhanced Web Apps

A Vercel AI SDK testing helper that produces a controlled readable stream containing simulated response chunks.

simulateReadableStream is a Vercel AI SDK testing helper for producing controlled readable streams from predefined response chunks. It lets tests exercise streaming behavior without making live provider API calls. section 8.4.3

Use it inside a MockLanguageModelV1 doStream implementation passed to streamText. Define text-delta chunks in sequence, then add a finish chunk with its reason and token usage. section 8.4.3

Simulate a streamed response

const result = streamText({ model: new MockLanguageModelV1({ doStream: async () => ({ stream: simulateReadableStream({ chunks: [ { type: 'text-delta', textDelta: 'This is ' }, { type: 'text-delta', textDelta: 'a test ' }, { type: 'text-delta', textDelta: 'of streaming.' }, { type: 'finish', finishReason: 'stop', logprobs: undefined, usage: { completionTokens: 15, promptTokens: 5 } } ] }), rawCall: { rawPrompt: null, rawSettings: {} } }) }), prompt: 'Start streaming!' });

How Build AI-Enhanced Web Apps covers it

How deep it goes
Defines ordered text-delta and finish chunks inside doStream, but does not describe the helper’s internal stream implementation.
Examples
Uses three text-delta chunks followed by a stop finish chunk carrying prompt and completion token counts.
What it assumes
Assumes familiarity with streamText and MockLanguageModelV1 while supplying predefined chunks rather than requiring a live model.
What you can do after
Apply it via the Vercel AI SDK to test streaming responses deterministically without calling an actual provider.
How it connects
Connects MockLanguageModelV1 with streamText and simulated streaming responses.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.