Documentation

Quickstart, connectors, and security. Use the AI SDK for intelligent workflows. See the AI SDK docs for model usage and APIs [AI SDK reference].

We build on the AI SDK for generation and reasoning flows. See sdk.vercel.ai for details. [^2]

# Install client
npm i ai @ai-sdk/openai

# Environment
# Set OPENAI_API_KEY in your platform's env (server-side only)

# Next.js route handler example
import { generateText } from "ai"
import { openai } from "@ai-sdk/openai"

export async function POST(req: Request) {
  const { prompt } = await req.json()
  const { text } = await generateText({
    model: openai("gpt-4o"),
    prompt
  })
  return new Response(JSON.stringify({ text }))
}

For more, see the AI SDK docs (generateText, streamText, model providers). [^2]