Vercel AI SDK Chatbot
VerifiedProduction chatbot with streaming UI, multi-provider support, and serverless deployment on Vercel.
Last verified: 2026-10-29
Orchestration
TypeScript SDK for building AI-powered streaming UIs with React.
React framework with API routes and serverless functions.
Memory
Redis-compatible serverless key-value store for session state.
React hook maintaining conversation state on client.
RAG
Serverless PostgreSQL with vector extension for embeddings.
Provider-agnostic embedding generation API.
MCP / Tools
Define tools as Zod schemas with execute functions.
Type-safe server functions callable from client components.
Integrate any HTTP API as a tool.
Eval / Tracing
Web analytics and performance monitoring.
LLM observability proxy with caching and rate limiting.
Models
Default model for most chatbot use cases.
Alternative with strong writing and analysis.
Ultra-fast inference for simple queries.
Cost & Performance Notes
Cost
Vercel Pro at $20/month. KV and Postgres have usage-based pricing. Model costs vary by provider.
Latency
Time-to-first-token ~200ms with streaming. Full responses stream progressively.
Caveats & Considerations
- Serverless cold starts can add latency
- Complex state management requires external storage
- Tool execution limited by serverless timeout (10-60s)
- Vercel vendor lock-in for optimal DX
External Resources
The Vercel AI SDK provides the fastest path from zero to production chatbot, with excellent streaming UX and seamless Vercel deployment. This stack is ideal for product teams shipping customer-facing chat features.
Architecture
┌─────────────────────────────────────────────────────┐
│ Next.js App │
│ ┌─────────────────────────────────────────────────┐│
│ │ React Chat UI ││
│ │ (useChat hook + streaming) ││
│ └─────────────────────────────────────────────────┘│
│ │ │
│ API Route │
│ ┌─────────────────────────────────────────────────┐│
│ │ streamText / generateText ││
│ │ + ││
│ │ Tool Definitions ││
│ └─────────────────────────────────────────────────┘│
├─────────────────────────────────────────────────────┤
│ AI SDK Core │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ OpenAI │ │Anthropic │ │ Groq │ ... │
│ │ Provider │ │ Provider │ │ Provider │ │
│ └──────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────────────┤
│ Vercel Infrastructure │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ KV │ │Postgres │ │ Blob │ │
│ │(session)│ │ (RAG) │ │ (files) │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────┘
Code Example
// app/api/chat/route.ts
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: openai('gpt-4o'),
messages,
tools: {
getWeather: {
description: 'Get weather for a location',
parameters: z.object({
location: z.string()
}),
execute: async ({ location }) => {
return { temperature: 72, condition: 'sunny' };
}
}
}
});
return result.toDataStreamResponse();
}
// app/page.tsx
'use client';
import { useChat } from 'ai/react';
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat();
return (
<div>
{messages.map(m => (
<div key={m.id}>{m.role}: {m.content}</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
</form>
</div>
);
}
When to Use This Stack
- Product teams shipping chatbots quickly
- Web-first applications with React/Next.js
- Projects requiring streaming responses and great UX
- Teams already on Vercel infrastructure
Something wrong or outdated?
Help us keep this stack accurate.