AI › AI Tools

Streaming a release-note summary with Vercel AI SDK

Stream a Jekyll summary from Next.js to React with Vercel AI SDK. See the live OpenRouter log and check how the app handles a mock error and cancellation.

Streaming a release-note summary with Vercel AI SDK

The browser can display a Jekyll 4.4.0 release summary as text arrives. A Next.js route calls OpenRouter, and Vercel AI SDK 7 streams the response into a React component.

I used Node.js 22.23.3, Next.js 16.4.6, ai 7.0.185, @ai-sdk/react 4.0.190, and @openrouter/ai-sdk-provider 3.1.0. I reran the code below in a local browser with mock OpenRouter replies. The screenshots are from the December 1 run with a real free-model request.

Move the release-note summary into the browser

I reused the Jekyll 4.4.0 excerpt from the OpenRouter request and usage example. The browser posts the text to /api/chat. The Next.js route calls OpenRouter and sends UI message events back to the client. The summary grows as those events arrive.

What the screen needsWhere I’d start
One result after generation completesA regular HTTP response
Visible progress and text while generation is runningAn AI SDK UI message stream with useChat

This screen displays a text summary. For a program that needs specific fields and types, the structured output example shows how to validate a generated result before using it.

Use a temporary key for the free router

I created a test key in the Keys section of my OpenRouter workspace and set it to expire after an hour. I kept the key on the Next.js server. The browser sent the release notes to the server route, and the server authenticated the request to OpenRouter. This puts the upstream credential in one place and keeps it out of the UI message stream. Create an OpenRouter key

I requested openrouter/free, which selects an available free model that supports the request. The model can vary between runs, and free usage is subject to request limits. I kept the requested ID visible above the text area so I could compare it with the model recorded in OpenRouter’s log after the run. Free models router

Return UI message events from the server

The route accepts one user message with a non-empty text part of up to 12,000 characters. The text area applies the same limit. This snippet goes inside the POST handler in app/api/chat/route.ts after input validation. message is the validated UI message, and openrouter comes from calling createOpenRouter with the server’s API key. Import the other four functions from ai.

1
2
3
4
5
6
7
8
9
10
11
const result = streamText({
  model: openrouter.chat('openrouter/free'),
  instructions: 'Summarize the release notes in three bullets using only the input.',
  messages: await convertToModelMessages([message]),
  abortSignal: request.signal,
  maxOutputTokens: 600,
});

return createUIMessageStreamResponse({
  stream: toUIMessageStream({ stream: result.stream }),
});

The model stream and the browser’s UI stream are two parts of the request. On the server I used toUIMessageStream to turn the model output into UI message events, then createUIMessageStreamResponse to send those events over HTTP. The React client consumed the SDK’s UI message protocol over server-sent events. The two helpers are standalone functions in AI SDK 7. Stream protocol · AI SDK 7 migration guide

Render arriving text and handle stop

A new run cleared the previous summary and sent only the current input. As events arrived, React’s useChat updated the messages. The output panel joined the text parts in the latest assistant message and kept the line breaks. That let me see the start of a bullet before the rest of its sentence arrived. AI SDK chatbot guide

Here is the part of the client component that joins the text from the latest assistant message. Import useChat from @ai-sdk/react and DefaultChatTransport from ai.

1
2
3
4
5
6
7
8
const { messages, status, sendMessage, setMessages, stop, error } = useChat({
  transport: new DefaultChatTransport({ api: '/api/chat' }),
});
const reply = messages.findLast(message => message.role === 'assistant');
const summary = reply?.parts
  .filter(part => part.type === 'text')
  .map(part => part.text)
  .join('') ?? '';

Submitting the form calls setMessages([]) and then sendMessage({ text }) with the current input. I used an independent type="button" control for stop(). An earlier version could submit the form again when the stop button changed back into a submit button.

Check a real request from start to finish

I submitted the prefilled notes in the local browser at 00:12 KST on December 1, 2026. During 응답 수신 중 (Receiving response), Jekyll’s version and the start of the first bullet appeared in the output panel.

Local summary demo showing the Jekyll version and an unfinished first bullet while the response streams Figure 1. The first bullet is visible while the rest of the response is still arriving.

When the stream ended, the status changed to 요약 완료 (Summary complete). The response kept all three changes from the input. It included the Ruby 2.7 minimum, the Liquid feature for selecting lines to highlight, and the addition of three runtime gem dependencies.

Local summary demo showing all three Jekyll 4.4.0 changes and the completed status Figure 2. The completed run shows one bullet for each change in the notes.

The app showed openrouter/free as the requested ID. The OpenRouter request log recorded Particle-1 (free) from Particle AI. The 196 input tokens, 190 output tokens, and US$0.00 cost are from that single run.

OpenRouter request log showing Particle-1 from Particle AI with a cost of US$0.00 Figure 3. OpenRouter’s log identifies the model and provider that served the request.

Test cancellation and error recovery locally

These checks ran in Next.js and a real browser with fixed upstream replies. The route returned 503 for a missing server key, and 400 for blank text, oversized input, or a message with the wrong role. For a mock upstream 429, the browser received HTTP 200 with an error event in the SSE body. The UI displayed the error and the next summary finished. Stopping a partially received response kept its text on screen without submitting another request.

  • In the Network panel, check that /api/chat returns Content-Type: text/event-stream and x-vercel-ai-ui-message-stream: v1. If text-delta events arrive before finish but the page updates all at once, check where React reads the text parts.
  • The completion status identified when the browser had finished receiving the response. The OpenRouter log identified the model and provider that served it, along with its cost. OpenRouter error handling
This post is licensed under CC BY 4.0 by the author.