AI SDK

Provider-agnostic TypeScript toolkit for building AI apps and agents with any LLM.

Library
npm
v7.0.116
26,955 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
92 /100 Excellent
Development Activity 100
Maintenance 100
Community 76
Maturity 52
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
91 /100 Excellent
Architecture 92
Code Quality 90
Innovation 90
Learning Curve 90

The AI SDK is Vercel’s open-source TypeScript toolkit for building AI-powered applications and agents. It provides a single, unified API for text generation, structured output, image/speech/video generation, embeddings, and reranking across dozens of model providers (OpenAI, Anthropic, Google, xAI, and more), so switching providers or models is a one-line change rather than a rewrite.

Beyond the core generation functions, the SDK ships framework-agnostic UI hooks (@ai-sdk/react, @ai-sdk/vue, @ai-sdk/svelte, @ai-sdk/angular) for building chat and generative interfaces, a ToolLoopAgent abstraction for building tool-using agents, and first-class support for streaming, tool calling, and the Model Context Protocol (MCP). It is maintained by the Next.js/Vercel team and used across a large ecosystem of provider and framework integration packages published under the @ai-sdk/* namespace.

What You Get

  • Unified generateText/streamText/generateObject APIs that work identically across OpenAI, Anthropic, Google, xAI, Groq, Mistral, and dozens of other providers
  • A ToolLoopAgent class for building tool-calling agents with structured tool definitions, approval flows, and streaming UI message output
  • Framework-agnostic UI hooks (@ai-sdk/react, @ai-sdk/vue, @ai-sdk/svelte, @ai-sdk/angular) for wiring chat and generative UI into any frontend
  • Built-in Model Context Protocol (MCP) client support for connecting agents to external tool servers
  • First-class Zod/Valibot schema integration for structured output and typed tool inputs/outputs
  • Access to the Vercel AI Gateway by default, or direct provider SDKs installed independently (@ai-sdk/openai, @ai-sdk/anthropic, etc.)

Common Use Cases

  • Building a chatbot or conversational UI with streaming responses in a Next.js, React, Vue, or Svelte app
  • Generating structured JSON output (e.g. extracting data, generating recipes/forms) validated against a Zod schema
  • Building tool-using agents that call external APIs, run code in a sandbox, or query internal systems
  • Swapping between LLM providers (OpenAI, Anthropic, Google) without rewriting application logic
  • Adding AI image, speech, or video generation to a product using a consistent API across providers

Under The Hood

Architecture: The repo is a pnpm/Turborepo monorepo with the ai core package (packages/ai/src) built around directory-scoped modules — generate-text, generate-object, generate-image, generate-speech, generate-video, embed, rerank, agent, middleware, registry, ui, ui-message-stream, realtime, and telemetry. Every generation function resolves a caller-supplied model string or instance through model/resolve-model.ts into a versioned LanguageModelV3/V4 (or embedding/image/speech/video equivalent) contract defined in the separate @ai-sdk/provider package, then normalizes provider-specific quirks via adapter functions like as-language-model-v4.ts. This adapter-and-versioned-contract layering is what lets generateText({ model: 'openai/gpt-5.4' }) and generateText({ model: anthropic('claude-opus-4-6') }) share identical downstream logic. The agent/tool-loop-agent.ts module builds a stateful tool-calling loop on top of generate-text, and ui-message-stream bridges that loop to framework hooks (@ai-sdk/react’s useChat) over a typed streaming protocol.

Tech Stack: Pure TypeScript (81% of the codebase) built with tsup, type-checked via tsc --build project references, and tested with Vitest across separate Node and edge-runtime configs (vitest.node.config.js / vitest.edge.config.js) to guarantee edge-runtime compatibility. The workspace uses pnpm workspaces plus Turborepo for task orchestration across ~80 packages, Changesets for versioned releases, and oxlint/ultracite for linting. Zod (with Valibot as an alternative) is a peer dependency used throughout for schema validation of structured output and tool I/O.

Code Quality: The ai package alone has 127 *.test.ts/*.test-d.ts files (colocated with source, including type-level tests via test-d.ts and snapshot tests), covering tool execution, streaming, schema resolution, and error paths explicitly — errors are modeled as typed classes under src/error/ rather than thrown generically. Naming is consistent (generate-*, stream-*, as-*-model-v*) and modules are small and single-purpose, which keeps the large surface area navigable despite the monorepo’s size.

API Design: The public API is deliberately minimal at the entry point — a handful of verbs (generateText, streamText, generateObject, embed, tool) cover the majority of use cases, with provider selection reduced to a model string or a one-line import { anthropic } from '@ai-sdk/anthropic'. Getting started requires only npm install ai plus one provider package; the README’s own quickstart is under 10 lines of code. Consistent naming conventions across sibling functions (generateImage/generateSpeech/generateVideo mirroring generateText) minimize the learning curve for anyone who has used one function in the family.

Used by 581 apps in this directory

Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 1 weeks ago
TypeScript
80%
AGPL 3.0

Postiz

Automation · Social Media

36,421

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
91
Repo Health
70
Technical
63
Dependency
Built with
TypeScript 80%
JavaScript 11%
Updated 1 weeks ago
TypeScript
97%
MIT

Promptfoo

AI Development

25,506

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
97%
MIT

Promptfoo

AI Development

25,506

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
60%
AGPL 3.0

Puter

Developer Tools · File Storage

43,605

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
70
Dependency
Built with
TypeScript 60%
JavaScript 36%
Updated 1 weeks ago
TypeScript
60%
AGPL 3.0

Puter

Developer Tools · File Storage

43,605

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
70
Dependency
Built with
TypeScript 60%
JavaScript 36%
Updated 1 weeks ago
TypeScript
95%
AGPL 3.0

Rallly

Scheduling

5,277

Self-hostable group scheduling polls that eliminate back-and-forth emails and find the best meeting time for everyone.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 95%
Updated 1 weeks ago
TypeScript
95%
AGPL 3.0

Rallly

Scheduling

5,277

Self-hostable group scheduling polls that eliminate back-and-forth emails and find the best meeting time for everyone.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 95%
Updated 1 weeks ago
TypeScript
94%
Apache 2.0

reader

Data Engineering · Developer Tools

561

Production-grade open source web scraping engine that turns any URL into clean markdown for AI agents — with built-in anti-bot bypass, proxy rotation, and browser session management.

View details
59
Repo Health
79
Technical
76
Dependency
Built with
TypeScript 94%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers