This project demonstrates how to build a real-time, multi-model AI chat application using the AI SDK. It features dynamic switching between multiple language models, seamless streaming of responses, and a modular architecture for future extensibility.
- 🔄 AI Model Switching — Select from a list of powerful LLMs during any conversation.
- 💬 Streaming Responses — Implements
streamTextfor real-time, token-by-token output. - 🧠 Chat State Management — Uses
useChathook to maintain smooth conversation flow. - ⚙️ Custom Provider Architecture — Easily add, remove, or swap models with a unified API.
Choose between multiple LLMs to compare and test performance:
- Anthropic Claude 3.5 Sonnet
- Anthropic Claude 3.7 Sonnet
- Anthropic Claude 3.5 Haiku
- OpenAI o3-mini
- OpenAI GPT-4o Mini
- A dropdown selector in the chat UI allows users to choose a model.
- The selected
modelIdis passed to the API route. - The server validates the model and routes the request to the correct provider.
- The model response is streamed in real time to the client.
- Messages are rendered with appropriate formatting for both user and assistant.
useChathook from the AI SDK handles chat input/output.- The
customProviderfunction defines and organizes all available models. - Server-side validation ensures that only supported models are used.
- Streaming via
streamTextprovides a fast, smooth UX. - Built-in message formatting keeps conversations clean and readable.
git clone https://github.com/haiderali780/Multi-Model-AI-Chat-Switcher.git
cd Multi-Model-AI-Chat-Switchernpm install
# or
yarn install
# or
pnpm installCreate a .env.local file by copying the example:
cp .env.example .env.localAdd your API keys:
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENAI_API_KEY=your_openai_api_keynpm run dev
# or
yarn dev
# or
pnpm devVisit http://localhost:3000 to see the app live.
- 🧪 Side-by-side model output comparison
- 🧾 Token & latency metrics per model
- 🔒 User authentication & usage limits
- 💾 Persistent chat history (optional database support)
- 🎨 Improved UI/UX with theming support
If you like this project, consider giving it a ⭐️!
Contributions are welcome — feel free to open issues or submit pull requests.