Full-Stack Web

Vercel AI SDK 4.0: streamText, toDataStreamResponse & Real-Time UI Hooks

Connect Next.js 15 Route Handlers to Google Gemini and Anthropic Claude using Vercel AI SDK 4.0 streamText and useChat hooks.

3 min

Standardizing Route Handlers with streamText

Vercel AI SDK v4 streamlines LLM responses into standard streaming protocols with minimal boilerplate.

api/chat/route.ts
import { streamText } from "ai";
import { google } from "@ai-sdk/google";

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: google("gemini-3.7-flash"),
    messages,
  });

  return result.toDataStreamResponse();
}