Das Vercel AI SDK ist die Standardbibliothek für AI-Anwendungen in Next.js — ein TypeScript-first Framework, das die Komplexität von LLM-Integration abstrahiert und Streaming, Tool Calling und Multi-Provider-Support out-of-the-box bietet.
Ohne das SDK müssen Sie für jede AI-Integration:
Das Vercel AI SDK löst all das mit einer einheitlichen API:
import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
const { text } = await generateText({
model: openai('gpt-4.1'),
prompt: 'Erkläre Kubernetes in einem Satz.',
})
| Modul | Import | Zweck |
|---|---|---|
| AI SDK Core | ai | Server-seitig: generateText, generateObject, streamText |
| AI SDK UI | ai/react | Client-seitig: useChat, useCompletion, useObject |
| AI SDK Providers | @ai-sdk/* | Provider-Abstraktionen für OpenAI, Anthropic, Google, etc. |
Das SDK abstrahiert Provider-Unterschiede hinter einer einheitlichen API:
import { openai } from '@ai-sdk/openai'
import { anthropic } from '@ai-sdk/anthropic'
import { google } from '@ai-sdk/google'
// Gleiches Interface — verschiedene Provider
const model1 = openai('gpt-4.1')
const model2 = anthropic('claude-sonnet-4-20250514')
const model3 = google('gemini-2.5-pro')
Unterstützte Provider (2026):
Durch die Abstraktionsschicht können Sie Provider wechseln, ohne Anwendungscode zu ändern:
// config.ts
const MODEL = process.env.AI_PROVIDER === 'anthropic'
? anthropic('claude-sonnet-4-20250514')
: openai('gpt-4.1')
// Überall im Code
const result = await generateText({ model: MODEL, prompt })
Ohne Streaming wartet der Nutzer 3–30 Sekunden auf eine vollständige Antwort. Mit Streaming sieht er Tokens in Echtzeit — die gefühlte Latenz sinkt auf unter 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()
}
Der wichtigste Hook für 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}>Senden</button>
</form>
</div>
)
}
Für Single-Turn-Completions (kein Chat-Verlauf):
Warum Vercel AI SDK für Next.js? Es ist das einzige SDK, das Server Components, Route Handlers, Server Actions und Client Components nahtlos verbindet. Die Integration mit dem Next.js-Ökosystem (Edge Runtime, Streaming, ISR) ist einzigartig.
Welches sind die drei Hauptmodule des Vercel AI SDK?