useChat and useCompletion - that handle streaming text responses, message history, and loading states out of the box. There is no dedicated Vibes framework class for this integration. The pattern is straightforward: run your Vibes agent with agent.stream(), pipe the output through toDataStreamResponse() from the ai package, and the Vercel AI hooks connect to it automatically.
How streaming works
toDataStreamResponse() converts a textStream into the Vercel AI data stream protocol. The useChat and useCompletion hooks on the frontend understand this protocol natively.
API route
Next.js App Router
messages array follows Vercel AI SDK’s message format (each message has role and content fields). agent.stream() accepts a prompt string and optional messageHistory to continue multi-turn conversations.
Deno server
For non-Next.js setups or Deno-native deployments:The
ai package (v6) is already a dependency in deno.json - no separate install is needed for Deno projects. For Next.js, install with npm install ai.React frontend
useChat
useChat manages multi-turn conversations. It maintains the full message history and sends it with each request so your API route can pass it as messageHistory.
useCompletion
useCompletion is simpler - designed for single-turn completions without conversation history. Use this for standalone prompts like document summarization or code generation forms.
useCompletion is similar - just use a prompt field instead of messages:
Structured output
If your agent usesoutputSchema (structured JSON output), use result.partialOutput instead of result.textStream. The partialOutput stream emits incremental JSON chunks as the schema is filled in.