AI Gateway

AI Gateway Text Generation Quickstart
Text
Stream a text response through AI Gateway.
Copy page
Paste this prompt into a coding agent with terminal access:
Add streaming text generation through AI Gateway in the current environment. Use the AI Gateway skill for this task. If it is unavailable, run npx skills add vercel/vercel-plugin --skill ai-gateway, then find and read its SKILL.md before continuing. Reuse the environment's language, framework, package manager, and AI client when possible, and add only required dependencies. Read AI_GATEWAY_API_KEY from the environment. If it is missing, run npx vercel@latest whoami and pause for login if needed. Determine the team, then run npx vercel@latest --scope
Run the Node.js example
Use Node.js 22.18 or later and a team with available AI Gateway Credits. Export AI_GATEWAY_API_KEY in your current shell. If you need a key, open the Create API Key dialog.
Install the AI SDK:
Create index.mts:
export AI_GATEWAY_API_KEY="your_ai_gateway_api_key"
pnpm addai@latest
}
constresult=streamText({
model:'openai/gpt-6-astra',
});
console.log();
import { streamText } from'ai';
process.stdout.write(textPart);
Next steps
node index.mts
Last updated September 8, 2026
Run the script:
Cross-link map: AI Gateway Text Generation Quickstart (/docs/ai-gateway/getting-started/text)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesAI Gateway Speech Quickstart: Transcription and TTS — Generate speech and transcribe it using AI Gateway.OpenAI Responses Text Generation with AI Gateway — Generate text responses with the OpenAI Responses API through AI Gateway.OpenResponses Text Generation with AI Gateway — Generate text responses using the OpenResponses API through AI Gateway.Video Generation Quickstart — Generate a video from a text prompt using AI Gateway.AI Gateway Image Generation Quickstart — Generate an image from a text prompt using AI Gateway.This page links to (8)AI Gateway Text Generation — Generate and stream text from hundreds of models through AI Gateway, with tool calling and structured output.AI Gateway Provider Routing and Fallbacks — Configure provider routing, ordering, and fallback behavior in Vercel AI Gateway.AI Gateway Pricing — Understand AI Gateway token pricing, free and paid credits, BYOK costs, add-on charges, and payment fees. Manage creditAI SDK with AI Gateway — Build AI-powered TypeScript applications using the AI SDK with AI Gateway for unified access to 200+ models.Anthropic Messages API with AI Gateway — Use the Anthropic Messages API with AI Gateway. Configure authentication and send requests with streaming, tools, imagesOpenAI Chat Completions API with AI Gateway — Use OpenAI SDKs with the AI Gateway Chat Completions API. Configure the base URL and authentication for chat, streaming,OpenResponses API with AI Gateway — Use the OpenResponses API specification with AI Gateway for a unified, provider-agnostic interface.OpenAI Responses API with AI Gateway — Use the OpenAI Responses API with AI Gateway to generate text, call tools, stream tokens, and more across any supportedPages that link here (2)By site: vercel-docs (2)Getting Started with AI Gateway — Set up AI Gateway with a coding agent, route the agent through AI Gateway, or make your first request with cURL, TypeScrAI Gateway Text Generation — Generate and stream text from hundreds of models through AI Gateway, with tool calling and structured output.
Was this helpful?
- Use AI Gateway with the AI SDK, OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, or OpenResponses
- Add tools and structured output
- Configure provider routing and fallbacks