This example demonstrates how to use the AI SDK with Next.js and the streamText function to automatically handle multi-step generations. It provides a Next.js chatbot that leverages the AI SDK's streamText function, specifically utilizing maxSteps and a reasoning tool to process and respond to complex user queries. This allows for more sophisticated AI interactions where the model can break down problems into multiple reasoning steps before providing a final answer.
To deploy your own version of this application, you can use the provided Vercel deploy button or clone the repository directly.
How to Use:
To get started with this example, you can bootstrap the project using create-next-app with your preferred package manager:
npx create-next-app --example https://github.com/vercel-labs/ai-sdk-preview-steps-reasoning ai-sdk-preview-steps-reasoning-example
# or
yarn create next-app --example https://github.com/vercel-labs/ai-sdk-preview-steps-reasoning ai-sdk-preview-steps-reasoning-example
# or
pnpm create next-app --example https://github.com/vercel-labs/ai-sdk-preview-steps-reasoning ai-sdk-preview-steps-reasoning-exampleRunning Locally:
To run the example locally, follow these steps:
- Sign up for accounts with the AI providers you intend to use (e.g., OpenAI, Anthropic).
- Obtain the necessary API keys for each provider.
- Set these API keys as environment variables in a new
.envfile, mirroring the structure of the.env.examplefile. - Install the project dependencies by running
npm install. - Launch the development server with
npm run dev.
Key Features:
- Multi-Step Generations: Utilizes the AI SDK's
streamTextfunction withmaxStepsto enable the AI to perform complex reasoning over multiple steps. - Reasoning Tool Integration: Incorporates a reasoning tool to enhance the chatbot's ability to understand and respond to intricate user queries.
- Next.js Framework: Built on Next.js, offering a robust and scalable foundation for web applications.
- Vercel AI SDK: Leverages the Vercel AI SDK for seamless integration with various AI models.
Learn More:
For further details, refer to these resources:




