Why Vercel AI SDK?
Streaming responses, tool calling, multi-model support — unified TypeScript API for OpenAI, Anthropic, Google, Mistral.
npm install ai @ai-sdk/openai
API route:
import { openai } from "@ai-sdk/openai"
import { streamText } from "ai"
export async function POST(req: Request) {
const { messages } = await req.json()
return streamText({ model: openai("gpt-4o"), messages }).toDataStreamResponse()
}
Chat UI:
"use client"
import { useChat } from "ai/react"
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat()
return (
<form onSubmit={handleSubmit}>
{messages.map(m => <div key={m.id}><b>{m.role}:</b> {m.content}</div>)}
<input value={input} onChange={handleInputChange} />
</form>
)
}
Multi-Model
import { anthropic } from "@ai-sdk/anthropic"
streamText({ model: anthropic("claude-sonnet-4-20250514"), messages })
Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.
Top comments (0)