{"id":14411,"library":"ai","title":"AI SDK by Vercel","description":"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.","status":"active","version":"6.0.168","language":"javascript","source_language":"en","source_url":"https://github.com/vercel/ai","tags":["javascript","ai","vercel","sdk","llm","mcp","tool-calling","tools","structured-output","typescript"],"install":[{"cmd":"npm install ai","lang":"bash","label":"npm"},{"cmd":"yarn add ai","lang":"bash","label":"yarn"},{"cmd":"pnpm add ai","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The AI SDK is primarily designed for ES Modules (ESM) and Node.js >=18.","wrong":"const { generate } = require('ai');","symbol":"generate","correct":"import { generate } from 'ai';"}],"quickstart":{"code":"import { generate, openai } from 'ai';\n\nasync function main() {\n  // Ensure OPENAI_API_KEY is set in your environment variables\n  const result = await generate({\n    model: openai('gpt-4o-mini'),\n    prompt: 'Tell me a short, funny story about a robot.',\n    maxTokens: 100,\n  });\n\n  console.log('Generated text:', result.text);\n}\n\nmain().catch(console.error);\n","lang":"typescript","description":"Demonstrates how to generate text using the AI SDK with an OpenAI model, requiring an API key configured as an environment variable."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Install `zod` in your project: `npm install zod` or `yarn add zod`.","message":"The 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.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Update your Node.js environment to version 18 or newer. We recommend using a Node.js version manager like `nvm` or `volta`.","message":"The AI SDK requires Node.js version 18 or higher due to its use of modern JavaScript features and API compatibility.","severity":"gotcha","affected_versions":"<6.0.0"},{"fix":"Set the appropriate `_API_KEY` environment variable for your chosen provider in your development environment (`.env` file) and deployment pipeline.","message":"API 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.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Set the `OPENAI_API_KEY` environment variable with your actual OpenAI API key (or equivalent for other providers) before running your application.","cause":"The required API key for the chosen AI provider is not set in the environment variables.","error":"Error: Missing OpenAI API key. Please set the OPENAI_API_KEY environment variable."},{"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.","cause":"You are attempting to use ES Module (ESM) `import` syntax in a CommonJS (CJS) environment.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Install Zod: `npm install zod` or `yarn add zod`.","cause":"The `zod` package, a required peer dependency for structured output and other features, is not installed in your project.","error":"Error: Zod is a peer dependency of @ai-sdk/core. Please install it with 'npm install zod'."},{"fix":"Upgrade your Node.js installation to version 18 or higher. Use a version manager like `nvm use 18` or `volta install node@18`.","cause":"Your current Node.js version is older than the minimum required version (18) for the AI SDK.","error":"Error: The engine \"node\" is incompatible with this module. Expected version \">=18\". Got \"16.14.0\"."}],"ecosystem":"npm"}