These examples show you how to use the AI SDK with Next.js and FastAPI.
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-appyarn create next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-apppnpm create next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-appYou will also need Python 3.6+ and virtualenv installed to run the FastAPI server.
To run the example locally you need to:
- Sign up at OpenAI's Developer Platform.
- Go to OpenAI's dashboard and create an API KEY.
- Set the required environment variables as shown in the example env file but in a new file called
.env.local. virtualenv venvto create a python virtual environment.source venv/bin/activateto activate the python virtual environment.pip install -r requirements.txtto install the required python dependencies.pnpm installto install the required dependencies.pnpm devto launch the development server.
To learn more about the AI SDK, Next.js, and FastAPI take a look at the following resources:
- AI SDK Docs - view documentation and reference for the AI SDK.
- Vercel AI Playground - try different models and choose the best one for your use case.
- Next.js Docs - learn about Next.js features and API.
- FastAPI Docs - learn about FastAPI features and API.