Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Next.js starter streaming AI chat completions from a FastAPI Python backend using Vercel's Data Stream Protocol.
The AI SDK Python Streaming template is a Next.js starter that demonstrates streaming AI chat completions from a FastAPI Python backend using Vercel's Data Stream Protocol and the AI SDK's useChat hook.
This template, published by Vercel Labs, shows how to stream chat completions from a Python endpoint built with FastAPI and render them in a Next.js application using the useChat hook from the AI SDK. It takes API keys for AI providers as environment variables and produces a chat interface where user messages are streamed token-by-token from the backend. The repository is available on GitHub under vercel-labs/ai-sdk-preview-python-streaming.
The example relies on a Next.js route that communicates with the Python FastAPI server. After you enter API keys in environment variables, the useChat hook sends user messages to the FastAPI endpoint, which streams back chat completions using the Data Stream Protocol. The frontend decodes that stream and renders message content incrementally.
The README names OpenAI and Anthropic as examples. To use a provider, you need an account and an API key, which you store in a .env file based on the provided .env.example.
Yes. The frontend uses pnpm (or npm/Yarn) to install Node dependencies, and the backend requires a Python virtual environment with dependencies installed via pip from requirements.txt.
Yes. The project includes a "Deploy with Vercel" button that clones the repository into a new Vercel project; environment variables still need to be configured in the Vercel dashboard.
