Streaming AI Chat with the Vercel AI SDK and Nuxt

A Nuxt chat app that streams Vercel AI SDK responses and renders each Markdown message part live with Comark.
chat.post.ts
import { convertToModelMessages, streamText } from 'ai'

export default defineEventHandler(async (event) => {
  const { messages } = await readBody(event)

  const result = streamText({
    model: 'anthropic/claude-sonnet-4.6',
    system: `You are a helpful Comark assistant. Always respond using Comark syntax.
Call fetchComarkSkill to learn the syntax and fetchComponents to discover available UI components.`,
    messages: await convertToModelMessages(messages),
    stopWhen: stepCountIs(4),
  })

  return result.toUIMessageStreamResponse()
})

This example streams AI chat responses in Nuxt with the Vercel AI SDK (@ai-sdk/vue) and renders each text part incrementally as tokens arrive.

How it works

  • Server route (server/api/chat.post.ts): calls streamText() to stream a Markdown response from the model.
  • Client chat UI (app/pages/index.vue): pairs Chat from @ai-sdk/vue with <Markdown :streaming="isPartStreaming(part)" :effects="effects"> with a caret() effect from comark/stream, so unterminated syntax auto-closes while a part is active and settles once that part finishes.

Setup

cp .env.example .env
# Set AI_GATEWAY_API_KEY in .env

pnpm install
pnpm dev
© 2026 Vercel, Inc.