翻篇收录说明
翻篇网页快照

AI Gateway Text Generation Quickstart

https://vercel.com/docs/ai-gateway/getting-started/text

最近抓取:2026-12-04 04:04:00(北京时间)

最近内容变化:2026-12-04 04:04:00(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Generate and stream text responses through Vercel AI Gateway in minutes using a coding agent, cURL, the AI SDK, or OpenAI-compatible clients.

正文摘录

Copy pageCopy pageAI Gateway Text Generation QuickstartCopy pageCopy pageStream a text response through AI Gateway. Generate your first text response Use a coding agent Paste this prompt into a coding agent with terminal access: Agent PromptAdd 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 <team-slug> ai-gateway api-keys create --name <descriptive-name>. Capture stdout directly into AI_GATEWAY_API_KEY for the request or existing ignored secret storage, and never expose the value. Use openai/gpt-6-astra, stream the generated text, run the result, and report the output.Show more 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. Terminalexport AI_GATEWAY_API_KEY="your_ai_gateway_api_key" Install the AI SDK: Terminalpnpm add ai@latest Create index.mts: index.mtsimport { streamText } from 'ai'; const result = streamText({ model: 'openai/gpt-6-astra', prompt: 'Invent a new holiday and describe its traditions.', }); for await (const textPart of result.textStream) { process.stdout.write(textPart); } console.log(); Run the script: Terminalnode index.mts Next steps 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 Last updated December 2, 2026PreviousMigrate to AI GatewayNextImageWas this helpful?