This example demonstrates how to use the Vercel AI SDK with Next.js and the streamText function to automatically handle multiple tool steps. This template provides a Next.js chatbot that leverages the Vercel AI SDK for advanced AI interactions, specifically focusing on managing complex conversational flows that require multiple tool calls.
Key Features:
- Automatic Tool Call Roundtrips: Seamlessly handles multiple sequential tool calls within a single conversation turn, improving the chatbot's ability to perform multi-step tasks.
- Vercel AI SDK Integration: Built upon the Vercel AI SDK, offering a robust and developer-friendly toolkit for building AI applications with TypeScript.
- Next.js Framework: Utilizes Next.js for a performant and scalable full-stack application, benefiting from features like server-side rendering and API routes.
- Chatbot Functionality: Provides a foundational chatbot structure ready for customization and expansion.
How to Deploy and Use:
Deploy Your Own:
You can deploy this template directly to Vercel by clicking the "Deploy" button on the template page or by cloning the repository. You will need an OpenAI API key.
Local Setup:
To run the example locally, follow these steps:
-
Bootstrap the example using
create-next-appwith your preferred package manager:npx create-next-app --example https://github.com/vercel-labs/ai-sdk-preview-roundtrips ai-sdk-preview-roundtrips-exampleyarn create next-app --example https://github.com/vercel-labs/ai-sdk-preview-roundtrips ai-sdk-preview-roundtrips-examplepnpm create next-app --example https://github.com/vercel-labs/ai-sdk-preview-roundtrips ai-sdk-preview-roundtrips-example
-
Sign up for AI provider accounts (e.g., OpenAI, Anthropic) and obtain their respective API keys.
-
Set environment variables: Create a new file named
.envin the project root and populate it with the required API keys, following the structure of.env.example. For instance,OPENAI_API_KEY=your_openai_api_key_here. -
Install dependencies: Run
npm install(oryarn install,pnpm install) to install all necessary project dependencies. -
Launch development server: Execute
npm run dev(oryarn dev,pnpm dev) to start the local development server.




