Basic Chat Interface
Basic Chat Interface
Chat interface with streaming responses and message history. Includes typing indicators and message status tracking.
Problems solved
- Stream chat responses with message history in the UI
- Switch between a user-selected model and Perplexity Sonar for web search
- Enable source and reasoning parts in the UI message stream
Use cases
- Basic AI chat products
- Model-picker chat experiences
- Search-backed assistant demos
- AI Elements conversation shells
Setup
Requirements, wiring steps, and what this pattern adds to your project.
Getting started
Pick how you want to pull this pattern in. Then wire env vars and routes the same way.
- 1
Download → Next.js app
Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).
- 2
Extract the zip and install dependencies
Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.
- 3
Fill .env.local
The download includes .env.local placeholders when needed. Add real values for: OPENAI_API_KEY.
- 4
Customize the agent and tool files
Adapt prompts, tools, and stop conditions in the generated project for your product.
- 5
Run the app and open the pattern route
Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route and verify responses.
Environment variables
OPENAI_API_KEYGet key
Capabilities
AI SDK APIs
streamTextconvertToModelMessagesProviders
Files added
4 filesapp/page.tsxapp/layout.tsxcomponents/chat-form.tsxapp/api/chat/route.ts
Dependencies
6 totalnpm packages
4
Registry components
Critical files
chat/route.tsAPI route showing the pattern for model switching (user-selected model vs perplexity/sonar for web search) and enabling sendSources/sendReasoning in toUIMessageStreamResponse.
Requirements
- Complexity
- Beginner
- Setup time
- ~10 minutes
- Node
- 24+
- Memory
- 512MB









