Seamlessly integrate AI models into your Vercel project. Learn more
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.
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-4.1', 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).