AI SDK by Vercel

6.0.168 · active · verified Sat Apr 18

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.

Common errors

Warnings

Install

Imports

Quickstart

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);

view raw JSON →