React/Next.js Setup
React/Next.js Setup
React/Next.js Setup
This guide walks you through setting up BAML with React/Next.js, leveraging Server Actions and React Server Components for optimal performance.
Requirements: This integration requires Next.js 15 or higher.
BAML automatically generates a server action and React hook for your BAML functions, with built-in support for both streaming and non-streaming modes. For details on the generated hooks, see Generated Hooks.
Follow the step-by-step instructions below to set up BAML in a new or existing Next.js project.
First, create a new Next.js project with the App Router:
When prompted, make sure to:
Create a new BAML project in your Next.js application:
This will create a baml_src directory with starter code.
Setup provider specific API Keys.
To enable observability with BAML, you’ll first need to sign up for a Boundary Studio account.
Update the baml_src/generators.baml file to use the React/Next.js generator.
If you need baml_client to be ‘ESM’ compatible, you can add the following generator configuration to your .baml file:
For complete API documentation of the React/Next.js integration, see: