The Vercel AI SDK is the standard library for AI applications in Next.js — a TypeScript-first framework that abstracts the complexity of LLM integration and provides streaming, tool calling, and multi-provider support out of the box.
Without the SDK, for every AI integration you need to:
The Vercel AI SDK solves all of this with a unified API:
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
const { text } = await generateText({
model: openai('gpt-4.1'),
prompt: 'Explain Kubernetes in one sentence.',
})
| Module | Import | Purpose |
|---|---|---|
| AI SDK Core | ai | Server-side: generateText, generateObject, streamText |
| AI SDK UI | ai/react | Client-side: useChat, useCompletion, useObject |
| AI SDK Providers | @ai-sdk/* | Provider abstractions for OpenAI, Anthropic, Google, etc. |
The SDK abstracts provider differences behind a unified API:
import { openai } from '@ai-sdk/openai'
import { anthropic } from '@ai-sdk/anthropic'
import { google } from '@ai-sdk/google'
// Same interface — different providers
const model1 = openai('gpt-4.1')
const model2 = anthropic('claude-sonnet-4-20250514')
const model3 = google('gemini-2.5-pro')
Supported providers (2026):
Thanks to the abstraction layer, you can switch providers without changing application code:
// config.ts
const MODEL = process.env.AI_PROVIDER === 'anthropic'
? anthropic('claude-sonnet-4-20250514')
: openai('gpt-4.1')
// Everywhere in code
const result = await generateText({ model: MODEL, prompt })
Without streaming, the user waits 3–30 seconds for a complete response. With streaming, they see tokens in real time — perceived latency drops to under 500 ms.
import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'
export async function POST(req: Request) {
const { messages } = await req.json()
const result = streamText({
model: openai('gpt-4.1'),
messages,
})
return result.toDataStreamResponse()
}
The most important hook for chat interfaces:
'use client'
import { useChat } from 'ai/react'
export function ChatUI() {
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
api: '/api/chat',
})
return (
<div>
{messages.map(m => (
<div key={m.id}>{m.role}: {m.content}</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button disabled={isLoading}>Send</button>
</form>
</div>
)
}
For single-turn completions (no chat history):
Why Vercel AI SDK for Next.js? It's the only SDK that seamlessly connects Server Components, Route Handlers, Server Actions, and Client Components. The integration with the Next.js ecosystem (Edge Runtime, Streaming, ISR) is unique.
Welches sind die drei Hauptmodule des Vercel AI SDK?