Agent may make mistakes and shouldn't be used in production
AI Gateway offers a unified API to multiple providers with budgets, monitoring, load-balancing, and fallbacks. Choose a quickstart based on what you want to build.
AI Gateway offers a unified API to multiple providers with budgets, monitoring, load-balancing, and fallbacks. Choose a quickstart based on what you want to build.
Set up AI Gateway for text generation. First, make sure the Vercel CLI is installed (`npm i -g vercel`). If I'm using Claude Code, Codex, or Cursor, install the Vercel Plugin (`npx plugins add vercel/vercel-plugin`). For other agents, install Vercel Skills (`npx skills add vercel-labs/agent-skills`). Then: 1. Initialize a Node.js project and install the `ai` package, dotenv, @types/node, tsx, and typescript. 2. Save my AI_GATEWAY_API_KEY in .env.local. 3. Create an index.ts that uses the AI SDK streamText function with the model 'openai/gpt-5.4' to stream a response and log token usage. 4. Run it with tsx to verify it works.
Create a new directory and initialize a Node.js project.
mkdir ai-text-demo && cd ai-text-demopnpm initInstall the AI SDK and development dependencies.
pnpm add ai dotenv @types/node tsx typescriptCreate an API key in your Vercel dashboard and save it to your environment file.
AI_GATEWAY_API_KEY=your_api_key_hereAlternatively, use OIDC tokens for automatic authentication in Vercel deployments.
Save this script as index.ts and run it with tsx.
import { streamText } from 'ai';import 'dotenv/config';
async function main() { const result = streamText({ model: 'openai/gpt-5.4', prompt: 'Invent a new holiday and describe its traditions.', });
for await (const textPart of result.textStream) { process.stdout.write(textPart); }
console.log(); console.log('Token usage:', await result.usage);}
main().catch(console.error);pnpm tsx index.tsNext steps: Learn about provider routing, OpenAI compatibility, or try other SDKs like Anthropic.
Learn more about AI Gateway features including OpenAI compatibility, provider routing, and bring your own keys (BYOK).