Registry / llm-agents / ai
library0.2.0jsnpmunverified

The AI SDK by Vercel provides a unified interface for building AI applications, supporting various models like ChatGPT, Claude, and Gemini, either directly or via the Vercel AI Gateway. It simplifies interactions with providers such as OpenAI, Anthropic, and Google, offering features like tool-calling, structured output, and agentic capabilities. The current stable version is 6.0.168, with frequent patch releases and major version updates as new features and providers are integrated.

npm install ai
INSTALL
IMPORT
SIG · AI
A
ai
llm-agentsjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
import { generate } from 'ai';
const { generate } = require('ai');
The AI SDK is primarily designed for ES Modules (ESM) and Node.js >=18.

Demonstrates how to generate text using the AI SDK with an OpenAI model, requiring an API key configured as an environment variable.

import { generate, openai } from 'ai'; async function main() { // Ensure OPENAI_API_KEY is set in your environment variables const result = await generate({ model: openai('gpt-4o-mini'), prompt: 'Tell me a short, funny story about a robot.', maxTokens: 100, }); console.log('Generated text:', result.text); } main().catch(console.error);
Debug
Known issues
breakingVersion 6 of the AI SDK introduced significant API changes and a modular provider architecture. Direct usage of the `ai` package's core functions might require updates to adapt to the new API surface and separate provider packages.
fix
Refer to the official migration guide for Vercel AI SDK v6 to update your application logic. Ensure you import specific provider functions (e.g., `openai` from `ai`) and adjust `generate` options accordingly.
affects: >=6.0.0
gotchaThe AI SDK requires `zod` as a peer dependency, especially for features like structured output and tool definitions. It must be installed separately in your project.
fix
Install `zod` in your project: `npm install zod` or `yarn add zod`.
affects: >=3.0.0
gotchaThe AI SDK requires Node.js version 18 or higher due to its use of modern JavaScript features and API compatibility.
fix
Update your Node.js environment to version 18 or newer. We recommend using a Node.js version manager like `nvm` or `volta`.
affects: <6.0.0
gotchaAPI keys for AI providers (e.g., OpenAI, Anthropic, Google) are typically expected as environment variables (e.g., `OPENAI_API_KEY`). Not setting them will result in authentication errors.
fix
Set the appropriate `_API_KEY` environment variable for your chosen provider in your development environment (`.env` file) and deployment pipeline.
affects: *
Errors
Common errors & fixes
Error: Missing OpenAI API key. Please set the OPENAI_API_KEY environment variable.
The required API key for the chosen AI provider is not set in the environment variables.
fix
Set the `OPENAI_API_KEY` environment variable with your actual OpenAI API key (or equivalent for other providers) before running your application.
SyntaxError: Cannot use import statement outside a module
You are attempting to use ES Module (ESM) `import` syntax in a CommonJS (CJS) environment.
fix
Ensure your project is configured for ESM. For Node.js, add `"type": "module"` to your `package.json` file, or save your file with a `.mjs` extension.
Error: Zod is a peer dependency of @ai-sdk/core. Please install it with 'npm install zod'.
The `zod` package, a required peer dependency for structured output and other features, is not installed in your project.
fix
Install Zod: `npm install zod` or `yarn add zod`.
Error: The engine "node" is incompatible with this module. Expected version ">=18". Got "16.14.0".
Your current Node.js version is older than the minimum required version (18) for the AI SDK.
fix
Upgrade your Node.js installation to version 18 or higher. Use a version manager like `nvm use 18` or `volta install node@18`.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
55 hits · last 30 days
node
50
Resources
ai — npm install ai · libregistry