Scripts2026年3月29日·1 分钟阅读

Vercel AI SDK — Build AI Apps in TypeScript

TypeScript toolkit for building AI-powered applications. Unified API for OpenAI, Anthropic, Google, and more. Streaming, tool calling, structured output, and React hooks.

TO
TokRepo精选 · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

npm install ai @ai-sdk/openai

介绍

The Vercel AI SDK provides a unified TypeScript API for building AI applications. Stream text, generate structured data, call tools, and build conversational UIs — with a single API that works across all major LLM providers.

Best for: Full-stack AI apps, chatbots, AI-powered features in Next.js/React Works with: OpenAI, Anthropic, Google, Mistral, Ollama, AWS Bedrock


Core Features

Unified API

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const { text } = await generateText({
  model: openai('gpt-4o'),
  prompt: 'Explain quantum computing',
});

Streaming

const result = streamText({
  model: anthropic('claude-sonnet-4-20250514'),
  prompt: 'Write a poem',
});
for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Tool Calling & Structured Output

const { object } = await generateObject({
  model: openai('gpt-4o'),
  schema: z.object({ name: z.string(), age: z.number() }),
  prompt: 'Generate a user profile',
});

React Hooks

const { messages, input, handleSubmit } = useChat();

🙏

来源与感谢

Created by Vercel. Licensed under Apache 2.0. vercel/ai — 12K+ GitHub stars

相关资产