A simple vanilla JavaScript chat interface using @tanstack/ai-client and the Python FastAPI server.
- ✅ Pure vanilla JavaScript (no frameworks)
- ✅ Uses
@tanstack/ai-clientfor chat functionality - ✅ Connects to API servers on port 8000
- ✅ Real-time streaming messages
- ✅ Beautiful, responsive UI :)
- Install dependencies:
cd examples/vanilla-chat
npm install
# or
pnpm install- Make sure the FastAPI server is running:
cd ../python-fastapi
python main.pyThe FastAPI server should be running on http://localhost:8080
- Start the Vite dev server:
npm run dev
# or
pnpm devThe app will be available at http://localhost:3001
- Open
http://localhost:3001in your browser - Type a message and press Enter (or click Send)
- Watch the AI response stream in real-time!
vanilla-chat/
├── index.html # Main HTML file
├── src/
│ ├── main.js # Chat client logic
│ └── style.css # Styles
├── package.json # Dependencies
└── vite.config.ts # Vite configuration
The app uses ChatClient from @tanstack/ai-client with the fetchServerSentEvents connection adapter to connect to the FastAPI server:
import { ChatClient, fetchServerSentEvents } from '@tanstack/ai-client'
const client = new ChatClient({
connection: fetchServerSentEvents('http://localhost:8080/chat'),
onMessagesChange: (messages) => {
// Update UI when messages change
},
onLoadingChange: (isLoading) => {
// Update loading state
},
})The FastAPI server streams responses in Server-Sent Events (SSE) format, which the client automatically parses and displays.