new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Core · all subjects

ai sdk overview

62 notes in this subject, read out of this brain and free to use. This is page 1 of 2.

AI SDK is a TypeScript toolkit for AI applications

The AI SDK is the TypeScript toolkit designed to help developers build AI-powered applications and agents with React, Next.js, Vue, Svelte, Node.js, and more.

AI SDK supports multiple model providers

The AI SDK supports multiple model providers through a unified interface.

AI SDK standardizes model integration across providers

The AI SDK standardizes integrating artificial intelligence (AI) models across supported providers. This enables developers to focus on building great AI applications rather than spending time on technical details.

Generative artificial intelligence definition

Generative artificial intelligence refers to models that predict and generate various types of outputs such as text, images, or audio based on what is statistically likely, drawing from patterns learned during training. Examples include: generating a caption from a photo, generating a transcription from audio, and generating an image from a text description.

LLM training and domain-specific knowledge

LLMs learn by training on massive collections of written text, which means they are better suited to some use cases than others. For example, a model trained on GitHub data would understand the probabilities of sequences in source code particularly well.

LLM hallucination limitation

When asked about less known or absent information, such as the birthday of a personal relative, LLMs might hallucinate or make up information. It is essential to consider how well-represented the information you need is in the model's training data.

Embedding model definition and purpose

An embedding model is used to convert complex data like words or images into a dense vector representation, known as an embedding. Unlike generative models, embedding models do not generate new text or data. Instead, they provide representations of semantic and syntactic relationships between entities that can be used as input for other models or natural language processing tasks.

Streaming UI vs blocking UI benefits

Streaming UIs display parts of the response as they become available, while blocking UIs wait for the entire response to be generated before displaying anything. Streaming interfaces significantly improve user experience by reducing perceived latency, especially important for conversational applications where users might otherwise wait 5-40 seconds for a full LLM response with a loading spinner.

When to use streaming vs blocking

Streaming is beneficial for larger language models to improve user experience, but it is not always necessary. If you can achieve desired functionality using a smaller, faster model without streaming, this route can lead to simpler and more manageable development processes.

AI SDK Foundations documentation structure

The AI SDK Foundations section covers seven main topics: Overview (foundational concepts around AI and LLMs), Providers and Models (available providers and models), Prompts (how prompts are used and defined), Tools (tools in the AI SDK), Provider Options (provider-specific options for reasoning and caching), Streaming (why streaming is used for AI applications), and Agents (building agents with the AI SDK).

AI SDK three main parts

The AI SDK consists of three main parts: AI SDK Core (unified, provider agnostic API for generating text, structured objects, and tool calls with LLMs), AI SDK UI (framework-agnostic hooks for building chat and generative user interfaces), and AI SDK RSC (stream generative user interfaces with React Server Components, currently experimental).

Environment compatibility matrix

AI SDK Core is compatible with None/Node.js/Deno, Vue/Nuxt, Svelte/SvelteKit, Next.js Pages Router, and Next.js App Router. AI SDK UI is compatible with Vue/Nuxt, Svelte/SvelteKit, Next.js Pages Router, and Next.js App Router. AI SDK RSC is compatible only with Next.js App Router.

AI SDK has Core and UI surfaces

The AI SDK is divided into two main surfaces: AI SDK Core and AI SDK UI. These can be used with various backend frameworks.

Backend frameworks supported with AI SDK

AI SDK Core and AI SDK UI can be used with Node.js HTTP Server, Express, Hono, Fastify, and Nest.js backend frameworks.

Advanced section covers LLM paradigms and advanced AI SDK functionality

The Advanced section of the AI SDK documentation covers advanced topics and concepts for the AI SDK and RSC API. It is designed to help developers understand different mental models for working with LLMs compared to traditional software development, and provides guidance on how to use the SDK to build AI applications effectively.

Versioning format: MAJOR.MINOR.PATCH

Each version number follows the format MAJOR.MINOR.PATCH. Major releases include breaking API updates that require code changes. Minor releases aggregate new features and improvements into a public release that highlights benefits. Patch releases include new features and bug fixes.

Stable APIs have no special prefix

All APIs without special prefixes are considered stable and ready for production use. The SDK maintains backward compatibility for stable features and only introduces breaking changes in major releases.

Experimental APIs use experimental_ or Experimental_ prefix

APIs prefixed with experimental_ or Experimental_ (for example experimental_generateImage()) are in development and can change in any releases. To use experimental APIs safely: test them first in development, not production; review release notes before upgrading; prepare for potential code updates. When using experimental APIs, pin the AI SDK version number exactly to prevent unexpected breaking changes, avoiding ^ or ~ version ranges.

Deprecated APIs marked with deprecated prefix

APIs marked as deprecated will be removed in future major releases. You can wait until the major release to update your code. To handle deprecations: switch to the recommended alternative API; follow the migration guide released alongside major releases. The SDK provides automated codemods where possible to help migrate code to new versions.

AI SDK 4.2 stable APIs - experimental prefix removal

The following APIs have been moved to stable in AI SDK 4.2 and no longer have the experimental_ prefix: customProvider, providerOptions (renamed from providerMetadata for provider-specific inputs), providerMetadata (for provider-specific outputs), and toolCallStreaming option for streamText.

AI SDK 4.2 zod dependency requirement

AI SDK 4.2 requires zod as a non-optional dependency with version ^3.23.8.

AI SDK 7.0 requires Node.js 22 or later

AI SDK 7.0 requires Node.js 22 or later. The SDK is tested on Node.js 22, 24, and 26. Node.js 18 and 20 are no longer supported. Node.js 22 reached end-of-maintenance on April 30, 2026; for production workloads, prefer Node.js 24 (LTS) or Node.js 26.

AI SDK 7 is ESM-only, CommonJS no longer supported

All AI SDK packages in version 7.0 are ESM-only. The require() function is no longer supported. Projects using CommonJS must switch to ESM import syntax. If package.json does not include 'type': 'module', add it or rename files to use the .mjs extension.

Codemods available for v6 to v7 migration

AI SDK 7 provides Codemod transformations to help upgrade codebases automatically. Run all v7 codemods with: npx @ai-sdk/codemod v7. Individual codemods can be run with: npx @ai-sdk/codemod <codemod-name> <path>. Codemods are intended as tools and may not cover all changes; manual adjustments may still be needed.

Recommended migration process for AI SDK 7

The recommended process for upgrading to AI SDK 7 is: (1) Backup your project and commit all previous versions to version control, (2) Upgrade to AI SDK 7, (3) Follow the breaking changes guide, (4) Verify your project works as expected, (5) Commit your changes. An example upgrade command is: pnpm install ai @ai-sdk/react @ai-sdk/openai @ai-sdk/otel

AI SDK 3.1 major features

AI SDK 3.1 introduces two major features: AI SDK Core, a unified API for interacting with large language models (LLMs), and streamUI, a new abstraction built upon AI SDK Core functions that simplifies building streaming UIs.

AI SDK migration guide versions available

Migration guides exist for upgrading between the following AI SDK versions: 6.x to 7.0, 5.x to 6.0, 4.x to 5.0, 4.1 to 4.2, 4.0 to 4.1, 3.4 to 4.0, 3.3 to 3.4, 3.2 to 3.3, 3.1 to 3.2, and 3.0 to 3.1. There is also a separate data migration guide for AI SDK 5.0.

Error pattern using AISDKError

Errors extend AISDKError from '@ai-sdk/provider' and use a marker pattern. The marker is created as Symbol.for('vercel.ai.error.<ErrorName>') and stored as a private readonly symbol property. The static isInstance method checks if an error has the marker using AISDKError.hasMarker(error, markerString).

Repository structure - key directories

The Vercel AI SDK monorepo uses pnpm workspaces. Key directories: packages/ai (main SDK package 'ai' on npm), packages/provider (provider interface specifications '@ai-sdk/provider'), packages/provider-utils (shared utilities '@ai-sdk/provider-utils'), packages/<provider> (implementations like openai, anthropic, google, azure, amazon-bedrock), packages/<framework> (UI integrations for react, vue, svelte, angular, rsc), packages/codemod (automated migrations), examples/ (example applications), content/ (documentation source MDX), contributing/ (contributor guides), tools/ (internal tooling).

Development requirements and setup

Node.js version v22, v24, or v26 is required (v22 recommended for development). pnpm v10 or higher is required. Initial setup: run 'pnpm install' to install dependencies and 'pnpm build' to build all packages.

Root-level development commands

pnpm install (install dependencies), pnpm build (build all packages), pnpm test (run all tests excluding examples), pnpm check (run linting with oxlint and formatting with oxfmt checks), pnpm fix (fix linting and formatting issues), pnpm type-check:full (TypeScript type checking including examples), pnpm changeset (add a changeset for your PR), pnpm update-references (update tsconfig.json references after adding package dependencies).

Package-level development commands

Run from within a package directory: pnpm build (build the package), pnpm build:watch (build with watch mode), pnpm test (run all tests for node and edge), pnpm test:node (run Node.js tests only), pnpm test:edge (run Edge runtime tests only), pnpm test:watch (run tests in watch mode).

AI Functions example layout

Examples are placed under examples/ai-functions/src/<function>/<provider>/. Use basic.ts as the provider entry example file. Place all other examples in the same provider folder using descriptive kebab-case file names. Do not create flat top-level provider files like src/stream-text/openai.ts.

File naming conventions

Source files use kebab-case.ts. Test files use kebab-case.test.ts. Type test files use kebab-case.test-d.ts. React/UI components use kebab-case.tsx.

JSON parsing security requirement

Never use JSON.parse directly in production code to prevent security risks. Instead use parseJSON or safeParseJSON from '@ai-sdk/provider-utils'.

Zod version compatibility

The SDK supports both Zod 3 and Zod 4. For Zod 3 (compatibility code only), import as 'import * as z3 from "zod/v3"'. For Zod 4, import as 'import * as z4 from "zod/v4"' and use z4.core.$ZodType for type references.

Type checking requirement

Always run 'pnpm type-check:full' from the workspace root after making code changes. This ensures changes don't introduce type errors across the codebase, including examples.

Provider development - options schemas

User-facing provider option schemas should use .optional() unless null is meaningful. Be as restrictive as possible for future flexibility.

Provider development - response schemas

API response schemas should use .nullish() instead of .optional(). Keep minimal - only include properties you need. Allow flexibility for provider API changes.

URL validation in provider responses

Every getFromApi call must set validateUrl explicitly. Use validateUrl: true when the URL comes from a provider response body (image/audio/video download or polling URL). Use validateUrl: false only for URLs built from a configured baseURL. Pass credentialedOrigin when a response URL may legitimately carry the API key on its first hop. The ai-sdk/require-validate-url oxlint rule enforces this.

Changesets are required for production code changes

Every PR modifying production code needs a changeset. The default is patch for non-breaking changes. Run 'pnpm changeset' from the workspace root. Do not select example packages in changesets as they are not published.

Contributing guides available

Contributing guides are located at: contributing/add-new-provider.md (for adding new providers), contributing/add-new-model.md (for adding new models), contributing/testing.md (for testing and fixtures), contributing/provider-architecture.md (for provider architecture), contributing/building-new-features.md (for building new features), contributing/codemods.md (for codemods).

Architecture Decision Records location

Architecture Decision Records (ADRs) are stored in contributing/decisions/. Read contributing/decisions/README.md for the index of decisions. Check relevant ADRs before making architecture changes (new dependencies, new patterns, API design, infrastructure). If work contradicts an existing accepted ADR, discuss with the human before proceeding.

Task completion guidelines - bug fixes

A complete bug fix typically includes: a reproduction example in examples/ demonstrating the bug before fixing, unit tests that would fail without the fix (regression tests), the bug fix implementation, manual verification by running the reproduction example, and a changeset describing what was broken and how it's fixed.

Task completion guidelines - new features

A complete new feature typically includes: implementation of the feature, usage examples in examples/ demonstrating the feature, comprehensive unit tests, documentation updates in content/ for public APIs, and a changeset describing the feature for release notes.

Task completion guidelines - refactoring

Refactoring and internal changes should include unit tests for any changed behavior. Documentation is not needed for internal-only changes. Changesets are only needed if it affects published packages.

Prohibited practices in development

Do not: add minor/major changesets (use patch), change public APIs without updating documentation, use require() for imports, add new dependencies without running pnpm update-references, or modify content/docs/08-migration-guides or packages/codemod as part of broader codebase changes.

Provider pattern architecture layers

The SDK uses a layered provider architecture: Specifications layer (@ai-sdk/provider) defines interfaces like LanguageModelV4. Utilities layer (@ai-sdk/provider-utils) provides shared code for implementing providers. Providers layer (@ai-sdk/<provider>) provides concrete implementations for each AI service. Core layer (ai) provides high-level functions like generateText, streamText, generateObject.

AI SDK provider architecture overview

AI SDK Core offers a standardized approach to interacting with LLMs through a language model specification that abstracts differences between providers. This unified interface allows switching between providers with ease while using the same API for all providers.

Official AI SDK providers list

The AI SDK comes with the following official providers: xAI Grok (@ai-sdk/xai), OpenAI (@ai-sdk/openai), Azure OpenAI (@ai-sdk/azure), Anthropic (@ai-sdk/anthropic), Amazon Bedrock (@ai-sdk/amazon-bedrock), Google (@ai-sdk/google), Google Vertex (@ai-sdk/google-vertex), Mistral (@ai-sdk/mistral), Together.ai (@ai-sdk/togetherai), Cohere (@ai-sdk/cohere), Fireworks (@ai-sdk/fireworks), DeepInfra (@ai-sdk/deepinfra), DeepSeek (@ai-sdk/deepseek), Cerebras (@ai-sdk/cerebras), Groq (@ai-sdk/groq), Perplexity (@ai-sdk/perplexity), ElevenLabs (@ai-sdk/elevenlabs), LMNT (@ai-sdk/lmnt), Hume (@ai-sdk/hume), Rev.ai (@ai-sdk/revai), Deepgram (@ai-sdk/deepgram), Gladia (@ai-sdk/gladia), AssemblyAI (@ai-sdk/assemblyai), and Baseten (@ai-sdk/baseten).

OpenAI-compatible providers

The AI SDK can use the OpenAI Compatible provider with OpenAI-compatible APIs. Two examples are LM Studio and Heroku.

Community providers for AI SDK

The open-source community has created providers for AI SDK including: Ollama (ollama-ai-provider), FriendliAI (@friendliai/ai-provider), Portkey (@portkey-ai/vercel-provider), Cloudflare Workers AI (workers-ai-provider), OpenRouter (@openrouter/ai-sdk-provider), Apertis (@apertis/ai-sdk-provider), Aihubmix (@aihubmix/ai-sdk-provider), Requesty (@requesty/ai-sdk), Crosshatch (@crosshatch/ai-provider), Mixedbread (mixedbread-ai-provider), Voyage AI (voyage-ai-provider), Mem0 (@mem0/vercel-ai-provider), Letta (@letta-ai/vercel-ai-sdk-provider), Hindsight (@vectorize-io/hindsight-ai-sdk), Supermemory (@supermemory/tools), Spark (spark-ai-provider), AnthropicVertex (anthropic-vertex-ai), LangDB (@langdb/vercel-provider), Dify (dify-ai-provider), Sarvam (sarvam-ai-provider), Claude Code (ai-sdk-provider-claude-code), Browser AI (browser-ai), Gemini CLI (ai-sdk-provider-gemini-cli), A2A (a2a-ai-provider), SAP AI Core (@jerome-benoit/sap-ai-provider), AI/ML API (@ai-ml.api/aimlapi-vercel-ai), MCP Sampling (@mcpc-tech/mcp-sampling-ai-provider), ACP (@mcpc-tech/acp-ai-provider), OpenCode (ai-sdk-provider-opencode-sdk), Codex CLI (ai-sdk-provider-codex-cli), Soniox (@soniox/vercel-ai-sdk-provider), Zhipu Z.AI (zhipu-ai-provider), OLLM (@ofoundation/ollm), ZeroEntropy (zeroentropy-ai-provider), Crusoe (crusoe-ai-provider), and Neon AI Gateway (@neon/ai-sdk-provider).

Self-hosted models with AI SDK

Self-hosted models can be accessed with the following providers: Ollama, LM Studio, Baseten, and Browser AI. Additionally, any self-hosted provider that supports the OpenAI specification can be used with the OpenAI Compatible Provider.

Model capabilities matrix - xAI Grok models

xAI Grok models and their capabilities: grok-4.5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), grok-4 (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), grok-3 (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), grok-3-mini (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Model capabilities matrix - Vercel models

Vercel model v0-1.0-md has the following capabilities: Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes.

Model capabilities matrix - OpenAI models

OpenAI models and their capabilities: gpt-5.6 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.6-luna (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.6-sol (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.6-terra (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.4-pro (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.4 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.4-mini (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.4-nano (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.3-chat-latest (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.2-pro (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.2-chat-latest (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.2 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5-mini (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5-nano (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.1-chat-latest (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.1-codex-mini (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.1-codex (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5.1 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5-codex (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), gpt-5-chat-latest (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Model capabilities matrix - Anthropic Claude models

Anthropic Claude models and their capabilities: claude-sonnet-5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-fable-5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-8 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-7 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-6 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-sonnet-4-6 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-5 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-1 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-opus-4-0 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), claude-sonnet-4-0 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Model capabilities matrix - Mistral models

Mistral models and their capabilities: pixtral-large-latest (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-large-latest (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-medium-latest (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-medium-3 (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-medium-2505 (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-medium-3.5 (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), mistral-small-latest (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), pixtral-12b-2409 (Image Input: yes, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Model capabilities matrix - DeepSeek models

DeepSeek models and their capabilities: deepseek-chat (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), deepseek-reasoner (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Model capabilities matrix - Cerebras models

Cerebras models and their capabilities: llama3.1-8b (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), llama3.1-70b (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes), llama3.3-70b (Image Input: no, Object Generation: yes, Tool Usage: yes, Tool Streaming: yes).

Give your agent this brain