ScriptsApr 7, 2026·2 min read

Vercel AI SDK — Build AI Apps in TypeScript

Official TypeScript SDK for building AI-powered applications. Unified API for Claude, GPT-4, Gemini with streaming, tool use, structured output, and React hooks. By Vercel. 12,000+ stars.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

npm install ai @ai-sdk/anthropic
import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const { text } = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  prompt: "Explain quantum computing in 3 sentences",
});
console.log(text);

Streaming in Next.js:

import { streamText } from "ai";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({
    model: anthropic("claude-sonnet-4-20250514"),
    messages,
  });
  return result.toDataStreamResponse();
}

Intro

Vercel AI SDK is the official TypeScript SDK for building AI-powered applications with 12,000+ GitHub stars. It provides a unified API across Claude, GPT-4, Gemini, and 20+ providers with streaming, tool use, structured output (JSON schema), and React hooks for chat UIs. Used by Next.js AI Chatbot, v0, and thousands of production apps. Best for TypeScript/React developers building AI features into web applications. Works with: Next.js, React, Svelte, Vue, Node.js. Setup time: under 2 minutes.


Core Functions

generateText — Simple Completion

const { text } = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  prompt: "Write a haiku about coding",
});

streamText — Streaming Response

const result = streamText({
  model: anthropic("claude-sonnet-4-20250514"),
  messages: [{ role: "user", content: "Tell me a story" }],
});

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

generateObject — Structured Output

import { z } from "zod";

const { object } = await generateObject({
  model: anthropic("claude-sonnet-4-20250514"),
  schema: z.object({
    recipe: z.string(),
    ingredients: z.array(z.string()),
    steps: z.array(z.string()),
  }),
  prompt: "Generate a recipe for chocolate cake",
});
// object.recipe, object.ingredients, object.steps — fully typed!

Tool Use

const result = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  tools: {
    getWeather: {
      description: "Get weather for a location",
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ temp: 22, condition: "sunny" }),
    },
  },
  prompt: "What is the weather in Tokyo?",
});

React Hooks (useChat)

"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>
  );
}

Provider Adapters

Provider Package
Anthropic @ai-sdk/anthropic
OpenAI @ai-sdk/openai
Google @ai-sdk/google
Mistral @ai-sdk/mistral
Cohere @ai-sdk/cohere
Amazon Bedrock @ai-sdk/amazon-bedrock

Key Stats

  • 12,000+ GitHub stars
  • By Vercel
  • 20+ provider adapters
  • Streaming, tools, structured output
  • React/Svelte/Vue hooks

FAQ

Q: What is Vercel AI SDK? A: A TypeScript SDK providing a unified API for building AI features with streaming, tool use, and structured output across 20+ model providers.

Q: Is it free? A: Yes, open-source under Apache 2.0. You provide your own API keys.

Q: Do I need Next.js? A: No, the core SDK works with any Node.js project. The React hooks work with any React app.


🙏

Source & Thanks

Created by Vercel. Licensed under Apache 2.0.

ai — stars 12,000+

Thanks to Vercel for standardizing AI development in TypeScript.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets