Integrating VoltAgent with Next.js
This guide walks you through setting up VoltAgent in a Next.js application. We'll build a simple AI calculator example using Server Actions and the Vercel AI SDK.
Quick Start with Example
If you prefer to start directly with the completed example project, you can create it using the following command:
npm create voltagent-app@latest -- --example with-nextjs
This command will scaffold an entire Next.js example for you. You can also peek at the full source code right here: examples/with-nextjs.
Create a New Next.js Project
Start by creating a new Next.js project using the latest version:
npx create-next-app@latest my-voltagent-app
cd my-voltagent-app
Follow the prompts, selecting TypeScript and App Router.
Install VoltAgent Dependencies
Install the necessary VoltAgent packages and dependencies:
npm install @voltagent/core @ai-sdk/react ai zod@^3.25.76
@voltagent/core: The core VoltAgent library.@ai-sdk/react: React hooks for AI SDK integration.ai: Core AI SDK library for streaming and chat functionality.zod: Used when working with structured outputs.
VoltAgent Built-in Server Dependencies (Required for Debugging)
Install the VoltAgent built-in server dependencies (local REST API on http://localhost:3141) so you can
debug and inspect agent runs during development through https://console.voltagent.dev:
npm install @voltagent/server-hono
npm install -D tsx