Open Source Other TypeScriptReactNext.jsStreamingVercelSDK

Vercel AI SDK

Official TypeScript/JavaScript SDK for streaming text, structured data, and tool calls from any LLM. First-class React/Next.js hooks for real-time streaming UIs.

vercel/ai 15.0k stars 2.4k forks Apache-2.0

Install

$npm install ai @ai-sdk/anthropic

About

The Vercel AI SDK provides a consistent API surface for text generation, structured output, and tool use regardless of the underlying model provider. Switching from GPT-4o to Claude is a one-line change.

The React integration is the standout feature — useChat manages message state, streaming tokens, loading/error states, and input handling, so a complete streaming chat UI is around 30 lines of code.

Getting Started

npm install ai @ai-sdk/anthropic

import { anthropic } from '@ai-sdk/anthropic';
import { streamText } from 'ai';

const result = await streamText({
  model: anthropic('claude-sonnet-4-5'),
  prompt: 'Write a haiku about TypeScript',
});

for await (const delta of result.textStream) {
  process.stdout.write(delta);
}

Features

generateText and streamText — unified API for all providers
generateObject and streamObject — structured output with Zod schema validation
Tool calling with automatic multi-step execution
useChat and useCompletion React hooks — streaming chat state management
Provider SDKs: Anthropic, OpenAI, Google, Mistral, Groq, AWS Bedrock, Ollama
Middleware — intercept, log, and transform LLM calls
embeddings and cosineSimilarity utilities
Server-sent events and ReadableStream for edge-compatible streaming

References & Links

Free Open Source · MIT
View on GitHub Visit Homepage

Project Info

Language TypeScript
License Apache-2.0
Stars 15.0k ★
Forks 2.4k
Category Other

Topics

TypeScriptReactNext.jsStreamingVercelSDK

Ready to try Vercel AI SDK?

Free and open source. Install in one command, works with Claude Code, Cursor, Windsurf, and more.

$npm install ai @ai-sdk/anthropic
← Back to Marketplace