### Local Setup: Install Dependencies and Run Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-langchain/README.md Steps to install project dependencies and run the development server locally. This involves installing packages and starting the application. ```bash pnpm install ``` ```bash pnpm dev ``` -------------------------------- ### Install, Build, and Run the AI SDK Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/fastify/README.md Commands to install dependencies, build the project, and start the development server. ```sh pnpm install pnpm build pnpm dev ``` -------------------------------- ### Install Dependencies and Build Project Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/sveltekit-openai/README.md Installs project dependencies using pnpm and builds the project. This is a prerequisite for running the example. ```bash pnpm install pnpm build ``` -------------------------------- ### Local Development Setup Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-pages/README.md Steps to run the example locally. This involves signing up for OpenAI, generating an API key, setting it as an environment variable, installing dependencies, and starting the development server. ```bash # 1. Sign up at OpenAI's Developer Platform # 2. Generate an API KEY from OpenAI's dashboard # 3. Set the OPENAI_API_KEY environment variable in a .env.local file # Example .env.local: # OPENAI_API_KEY=your-openai-api-key pnpm install pnpm dev ``` -------------------------------- ### Run sveltekit-openai Development Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/sveltekit-openai/README.md Starts the sveltekit-openai example development server using pnpm. This command targets the specific sveltekit-openai package. ```bash pnpm -F sveltekit-openai dev ``` -------------------------------- ### Install AI SDK and Anthropic Provider Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/05-computer-use.mdx Installs the necessary AI SDK core package and the Anthropic provider package using pnpm. ```shell pnpm add ai @ai-sdk/anthropic ``` -------------------------------- ### PNPM Project Setup Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/ai-core/README.md Commands to install project dependencies and build the project using the PNPM package manager. These steps are necessary before running examples or tests. ```sh pnpm install pnpm build ``` -------------------------------- ### Install, Build, and Run the AI SDK Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/hono/README.md Installs dependencies, builds the project, and starts the development server. These commands are executed from the root directory of the AI SDK repository. ```Shell pnpm install pnpm build pnpm dev ``` -------------------------------- ### Install Dependencies and Run Development Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-fastapi/README.md Commands to install project dependencies using pnpm and start the local development server for the Next.js application. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install Dependencies and Run Locally Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-telemetry-sentry/README.md Commands to install project dependencies and start the development server for the Next.js AI example. Requires setting up environment variables for OpenAI and Sentry. ```bash pnpm install pnpm dev ``` -------------------------------- ### Install, Build, and Run the AI SDK Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/express/README.md Installs dependencies, builds the project, and starts the development server using pnpm. These commands are executed from the root directory of the AI SDK repository. ```sh pnpm install pnpm build pnpm dev ``` -------------------------------- ### Run Application Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/02-getting-started/04-svelte.mdx Command to start the Svelte AI chatbot application locally. ```shell pnpm run dev ``` -------------------------------- ### Install Dependencies and Run Locally Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-telemetry/README.md Steps to install project dependencies using pnpm and start the development server for local testing. Requires an OpenAI API key to be set in the environment. ```bash pnpm install pnpm dev ``` -------------------------------- ### Python Environment Setup for FastAPI Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-fastapi/README.md Steps to set up a Python virtual environment, activate it, and install project dependencies using pip for the FastAPI server. ```bash virtualenv venv source venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Install AI SDK Packages Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/24-o3.mdx Command to install the necessary AI SDK packages for a project, including the core AI SDK, the OpenAI provider, and the React integration for building UI components. ```bash pnpm install ai @ai-sdk/openai @ai-sdk/react ``` -------------------------------- ### Install Dependencies and Setup Environment Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-kasada-bot-protection/README.md Installs project dependencies using the pnpm package manager and copies an example environment file to `.env.local`. The `.env.local` file requires manual configuration with specific values for the application to run correctly. ```sh pnpm i cp .env.local.example .env.local # and fill in the required values ``` -------------------------------- ### Environment Setup and Dependency Installation Source: https://github.com/vercel/ai/blob/ai_5_0_0/CONTRIBUTING.md Instructions for setting up the development environment, including installing Node.js and PNPM, and installing project dependencies using PNPM. ```bash npm install -g pnpm@10 ``` ```bash brew install pnpm ``` ```bash pnpm install ``` -------------------------------- ### Install AI SDK and OpenAI Provider Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/22-gpt-4-5.mdx Installs the necessary AI SDK packages and the OpenAI provider for use with frameworks like Next.js. This command is typically run in your project's terminal. ```bash pnpm install ai @ai-sdk/openai @ai-sdk/react ``` -------------------------------- ### Run Development Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/node-http-server/README.md Starts the Node.js development server. This command should be executed after installing dependencies to launch the application. ```shell pnpm dev ``` -------------------------------- ### Build and Install dependencies Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/mcp/README.md Installs dependencies and builds the project using pnpm. ```sh pnpm install pnpm build ``` -------------------------------- ### Start SSE Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/mcp/README.md Starts the SSE server for the legacy SSE transport example. ```sh pnpm sse:server ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/sveltekit-openai/README.md Sets up the necessary environment variables for the example. The OPENAI_API_KEY must be provided in a .env.local file in the example's directory. ```env OPENAI_API_KEY= ``` -------------------------------- ### Start Development Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/04-natural-language-postgres.mdx Launches the local development server for the application. Once started, the application will typically be accessible at http://localhost:3000. ```bash pnpm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/node-http-server/README.md Installs all necessary project dependencies using the pnpm package manager. This command should be run from the root directory of the AI SDK repository. ```shell pnpm install ``` -------------------------------- ### Running the Example Application Source: https://github.com/vercel/ai/blob/ai_5_0_0/packages/angular/README.md Instructions for setting up and running the example application, which combines Angular and Express.js. It covers navigating to the example directory, setting up environment variables (like API keys), and starting the development servers. ```bash # Navigate to example cd examples/angular-chat # Set up environment echo "OPENAI_API_KEY=your_key_here" > .env # Start development (Angular + Express) pnpm start # Starts: # - Angular dev server: http://localhost:4200 # - Express API server: http://localhost:3000 # - Proxy routes /api/* to Express ``` -------------------------------- ### Computer Tool Setup with Anthropic Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/05-computer-use.mdx Defines a computer tool for the AI SDK using the Anthropic provider. This tool includes display dimensions and custom logic for executing actions like taking screenshots or performing other computer interactions. It also specifies how to convert tool results back into a model-understandable format. ```typescript import { anthropic } from '@ai-sdk/anthropic'; import { getScreenshot, executeComputerAction } from '@/utils/computer-use'; const computerTool = anthropic.tools.computer_20250124({ displayWidthPx: 1920, displayHeightPx: 1080, execute: async ({ action, coordinate, text }) => { switch (action) { case 'screenshot': { return { type: 'image', data: getScreenshot(), }; } default: { return executeComputerAction(action, coordinate, text); } } }, toModelOutput(result) { return typeof result === 'string' ? [{ type: 'text', text: result }] : [{ type: 'image', data: result.data, mediaType: 'image/png' }]; }, }); ``` -------------------------------- ### Install AI SDK and OpenAI Provider Dependencies Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/02-getting-started/06-nodejs.mdx Installs the AI SDK (`ai@beta`), the OpenAI provider (`@ai-sdk/openai@beta`), and utility packages like `zod` and `dotenv`. Development dependencies for TypeScript compilation (`@types/node`, `tsx`, `typescript`) are also installed. ```bash pnpm add ai@beta @ai-sdk/openai@beta zod dotenv pnpm add -D @types/node tsx typescript ``` -------------------------------- ### Setup Project Directory and Initialize with pnpm Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/02-getting-started/06-nodejs.mdx Creates a new project directory and initializes a Node.js project using `pnpm init`. This sets up the basic `package.json` file required for the project. ```bash mkdir my-ai-app cd my-ai-app pnpm init ``` -------------------------------- ### Running AI SDK Examples Source: https://github.com/vercel/ai/blob/ai_5_0_0/CONTRIBUTING.md Steps to navigate to example directories and execute AI SDK examples using PNPM, including specific commands for AI SDK Core and other framework examples. ```bash cd examples/ai-core ``` ```bash pnpm tsx src/stream-text/openai.ts ``` ```bash pnpm dev ``` -------------------------------- ### Start Nest.js AI Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/nest/README.md Starts the Nest.js development server in watch mode. This command requires pnpm to be installed and the project dependencies to be set up. ```sh pnpm run start:dev ``` -------------------------------- ### Create SvelteKit Application Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/02-getting-started/04-svelte.mdx Scaffolds a new SvelteKit project using the `create-svelte` command. This command initializes a basic SvelteKit application structure, ready for further customization. ```shell npx sv create my-ai-app ``` -------------------------------- ### Bootstrap Nuxt OpenAI Example Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/nuxt-openai/README.md Use create-nuxt to bootstrap the example project from a GitHub template. This command initializes a new Nuxt project with the specified AI SDK example. ```bash npx create-nuxt -t github:vercel/ai/examples/nuxt-openai nuxt-openai ``` -------------------------------- ### Install AI SDK and Anthropic Provider Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/20-sonnet-3-7.mdx Installs the AI SDK and the Anthropic provider using pnpm. This is a prerequisite for building AI-powered applications with Anthropic models in a Next.js environment. ```bash pnpm install ai @ai-sdk/anthropic ``` -------------------------------- ### Bootstrap Next.js App with AI SDK Example Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-upstash-rate-limits/README.md Use create-next-app with npm to quickly set up the project. This command clones the specified example repository into a new directory. ```bash npx create-next-app --example https://github.com/vercel/ai/tree/main/examples/next-openai-rate-limits next-openai-rate-limits-app ``` -------------------------------- ### Bootstrap Next.js App with AI SDK Example (pnpm) Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-upstash-rate-limits/README.md Use create-next-app with pnpm to quickly set up the project. This command clones the specified example repository into a new directory. ```bash pnpm create next-app --example https://github.com/vercel/ai/tree/main/examples/next-openai-rate-limits next-openai-rate-limits-app ``` -------------------------------- ### Install AI SDK and DeepSeek Provider Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/25-r1.mdx Installs the necessary AI SDK packages and the DeepSeek provider using pnpm. This command sets up your project to use AI SDK functionalities with DeepSeek models. ```bash pnpm install ai @ai-sdk/deepseek @ai-sdk/react ``` -------------------------------- ### Install AI SDK and Google Provider Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/17-gemini-2-5.mdx Command to install the core AI SDK and the Google Generative AI provider package using pnpm. This is a prerequisite for using Gemini models with the AI SDK. ```bash pnpm install ai @ai-sdk/google ``` -------------------------------- ### Install AI SDK and Anthropic Provider (pnpm) Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/18-claude-4.mdx Installs the necessary AI SDK core library and the Anthropic provider package using the pnpm package manager. This is the first step to integrate AI capabilities into your project. ```bash pnpm install ai @ai-sdk/anthropic ``` -------------------------------- ### Install AI SDK Dependencies Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/02-getting-started/04-svelte.mdx Installs the necessary AI SDK packages (`ai`, `@ai-sdk/openai`, `@ai-sdk/svelte`) along with `zod` for schema validation. These dependencies are crucial for integrating AI functionalities and OpenAI's models into your Svelte application. ```pnpm pnpm add -D ai @ai-sdk/openai @ai-sdk/svelte zod ``` ```npm npm install -D ai @ai-sdk/openai @ai-sdk/svelte zod ``` ```yarn yarn add -D ai @ai-sdk/openai @ai-sdk/svelte zod ``` -------------------------------- ### Install AI SDK 5 Beta Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/docs/01-announcing-ai-sdk-5-beta/index.mdx Installs the AI SDK 5 Beta and related provider/framework packages using npm. This command is essential for setting up the SDK in your project. ```bash npm install ai @ai-sdk/openai @ai-sdk/react ``` -------------------------------- ### Bootstrap Next.js App with AI SDK Example Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-langchain/README.md Instructions for bootstrapping a new Next.js project using the AI SDK example from GitHub. This command sets up the project structure and initial dependencies. ```bash npx create-next-app --example https://github.com/vercel/ai/tree/main/examples/next-langchain next-langchain-app ``` ```bash yarn create next-app --example https://github.com/vercel/ai/tree/main/examples/next-langchain next-langchain-app ``` ```bash pnpm create next-app --example https://github.com/vercel/ai/tree/main/examples/next-langchain next-langchain-app ``` -------------------------------- ### Start HTTP Server Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/mcp/README.md Starts the HTTP server for the streamable HTTP transport example. ```sh pnpm http:server ``` -------------------------------- ### Bootstrap Next.js App with AI SDK Example (Yarn) Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/next-openai-upstash-rate-limits/README.md Use create-next-app with Yarn to quickly set up the project. This command clones the specified example repository into a new directory. ```bash yarn create next-app --example https://github.com/vercel/ai/tree/main/examples/next-openai-rate-limits next-openai-rate-limits-app ``` -------------------------------- ### Run Stdio Client Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/mcp/README.md Runs the stdio client example. ```sh pnpm stdio:client ``` -------------------------------- ### Setup Angular AI Chat Application Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/angular/README.md This snippet demonstrates the steps to set up the Angular AI Chat application. It includes installing dependencies using pnpm, creating a .env file for the OpenAI API key, and starting the application. The setup process launches both the Angular frontend and the Express backend. ```bash # Install dependencies pnpm install # Create .env file with your OpenAI API key echo "OPENAI_API_KEY=your_key_here" > .env # Start the app pnpm start ``` -------------------------------- ### Install Dependencies with pnpm Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/nuxt-openai/README.md Installs all the necessary project dependencies using the pnpm package manager. This step is crucial before running the development server or building the project. ```bash pnpm install ``` -------------------------------- ### Node.js Braintrust Span Processor Setup Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/providers/05-observability/braintrust.mdx Configures the OpenTelemetry Node.js SDK with the BraintrustSpanProcessor for tracing LLM applications. Installs necessary packages and starts the SDK. Requires `ai`, `@ai-sdk/openai`, `braintrust`, `@opentelemetry/sdk-node`, `@opentelemetry/sdk-trace-base`, and `zod`. ```bash npm install ai @ai-sdk/openai braintrust @opentelemetry/sdk-node @opentelemetry/sdk-trace-base zod ``` ```typescript import { NodeSDK } from '@opentelemetry/sdk-node'; import { generateText, tool } from 'ai'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; import { BraintrustSpanProcessor } from 'braintrust'; const sdk = new NodeSDK({ spanProcessors: [ new BraintrustSpanProcessor({ parent: 'project_name:your-project-name', filterAISpans: true, }), ], }); sdk.start(); async function main() { const result = await generateText({ model: openai('gpt-4o-mini'), messages: [ { role: 'user', content: 'What are my orders and where are they? My user ID is 123', }, ], tools: { listOrders: tool({ description: 'list all orders', parameters: z.object({ userId: z.string() }), execute: async ({ userId }) => `User ${userId} has the following orders: 1`, }), viewTrackingInformation: tool({ description: 'view tracking information for a specific order', parameters: z.object({ orderId: z.string() }), execute: async ({ orderId }) => `Here is the tracking information for ${orderId}`, }), }, experimental_telemetry: { isEnabled: true, functionId: 'my-awesome-function', metadata: { something: 'custom', someOtherThing: 'other-value', }, }, maxSteps: 10, }); await sdk.shutdown(); } main().catch(console.error); ``` -------------------------------- ### Generate Text with OpenAI o3-mini Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/24-o3.mdx Demonstrates how to call the `generateText` function from the AI SDK to interact with the OpenAI o3-mini model. It shows the basic setup for sending a prompt and receiving a text response. ```typescript import { generateText } from 'ai'; import { openai } from '@ai-sdk/openai'; const { text } = await generateText({ model: openai('o3-mini'), prompt: 'Explain the concept of quantum entanglement.', }); ``` -------------------------------- ### Clone AI SDK Slackbot Repository Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/03-slackbot.mdx Clones the AI SDK Slackbot repository from GitHub and checks out the starter branch. This is the initial step for setting up the project locally. ```bash git clone https://github.com/vercel-labs/ai-sdk-slackbot.git cd ai-sdk-slackbot git checkout starter ``` -------------------------------- ### Stream Llama 3.1 Response Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/21-llama-3_1.mdx Shows how to stream the model's response as it is generated using the AI SDK's `streamText` function. This example uses the DeepInfra provider for the Llama 3.1 405B Instruct model. ```typescript import { streamText } from 'ai'; import { deepinfra } from '@ai-sdk/deepinfra'; const { textStream } = streamText({ model: deepinfra('meta-llama/Meta-Llama-3.1-405B-Instruct'), prompt: 'What is love?', }); ``` -------------------------------- ### Call Llama 3.1 with DeepInfra Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/21-llama-3_1.mdx Demonstrates how to use the AI SDK to call the Llama 3.1 405B Instruct model via the DeepInfra provider. This example uses the `generateText` function to retrieve a text response for a given prompt. ```typescript import { deepinfra } from '@ai-sdk/deepinfra'; import { generateText } from 'ai'; const { text } = await generateText({ model: deepinfra('meta-llama/Meta-Llama-3.1-405B-Instruct'), prompt: 'What is love?', }); ``` -------------------------------- ### Next.js Chat API Route Handler with Gemini Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/17-gemini-2-5.mdx Example of a Next.js API route handler (`app/api/chat/route.ts`) that streams text responses from the Gemini 2.5 Flash model. It processes incoming messages and returns a UI message stream. ```tsx import { google } from '@ai-sdk/google'; import { streamText, UIMessage, convertToModelMessages } from 'ai'; // Allow streaming responses up to 30 seconds export const maxDuration = 30; export async function POST(req: Request) { const { messages }: { messages: UIMessage[] } = await req.json(); const result = streamText({ model: google('gemini-2.5-flash'), messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse(); } ``` -------------------------------- ### Build Chat Interface with useChat Hook Source: https://github.com/vercel/ai/blob/ai_5_0_0/content/cookbook/00-guides/24-o3.mdx Example of a root page component (`app/page.tsx`) using the `useChat` hook from AI SDK UI. It manages chat messages, user input, and submission, rendering the conversation and a form for user interaction. ```tsx 'use client'; import { useChat } from '@ai-sdk/react'; export default function Page() { const { messages, input, handleInputChange, handleSubmit, error } = useChat(); return ( <> {messages.map(message => (
{message.role === 'user' ? 'User: ' : 'AI: '} {message.content}
))}
); } ``` -------------------------------- ### Run SSE Client Source: https://github.com/vercel/ai/blob/ai_5_0_0/examples/mcp/README.md Runs the SSE client example. ```sh pnpm sse:client ```