Back to all stacks

Vercel AI SDK Chatbot

Verified

Production chatbot with streaming UI, multi-provider support, and serverless deployment on Vercel.

ChatbotServerlessWeb App

Last verified: 2026-10-29

Orchestration

TypeScript SDK for building AI-powered streaming UIs with React.

Next.jsframework

React framework with API routes and serverless functions.

Memory

Vercel KVsession

Redis-compatible serverless key-value store for session state.

useChat Hookclient

React hook maintaining conversation state on client.

RAG

Serverless PostgreSQL with vector extension for embeddings.

AI SDK Embeddingsunified

Provider-agnostic embedding generation API.

MCP / Tools

AI SDK Toolsnative

Define tools as Zod schemas with execute functions.

Server ActionsNext.js

Type-safe server functions callable from client components.

External APIs

Integrate any HTTP API as a tool.

Eval / Tracing

Web analytics and performance monitoring.

HeliconeLLM-specific

LLM observability proxy with caching and rate limiting.

Models

GPT-4oprimary

Default model for most chatbot use cases.

Claude 3.5 Sonnetalternative

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

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.

Suggest an update