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

Getting Started with AI Gateway

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

最近抓取:2026-12-03 20:43:22(北京时间)

最近内容变化:2026-12-03 20:43:22(北京时间)

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

访问原网页

页面简介

Set up AI Gateway with a coding agent, route the agent through AI Gateway, or make your first request with cURL, TypeScript, or Python.

正文摘录

Copy pageCopy pageGetting Started with AI GatewayCopy pageCopy pageUse AI Gateway from any environment to call models, connect coding agents, and inspect routing and spend. AI Gateway API keys belong to a Vercel team and work in local development, CI, external servers, and Vercel deployments. Choose how to start GoalStart hereAsk a coding agent to make a requestCopy the agent setup promptRoute a coding agent through AI GatewayRun the coding-agent setupMake your first requestUse cURL, TypeScript, or PythonUse AI Gateway with existing codeUse an SDK or API, or migrate to AI Gateway For agents Ask a coding agent to make a request Use this path when you want a coding agent to write and run an AI Gateway request in your current environment. Paste this prompt into a coding agent with terminal access: Agent PromptSet up AI Gateway and make one text-generation request from this 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, package manager, and AI client when possible; otherwise use cURL. Reuse AI_GATEWAY_API_KEY without exposing it. If the key is missing, use npx vercel@latest to create a team-scoped key without installing the Vercel CLI globally. Ask for the team slug only if the current CLI scope is ambiguous, and capture the new key without printing it. Use openai/gpt-6-astra. Run the request and report only the generated text and any action I need to take.Show more Install the Vercel plugin to give your coding agent Vercel guidance beyond AI Gateway.npx plugins add vercel/vercel-plugin Route a coding agent through AI Gateway Use this path when you want to route a coding agent's own model requests through AI Gateway. The Vercel CLI detects supported agents, including Claude Code, and lets you select which ones to connect: Terminalnpx vercel@latest ai-gateway setup The command provisions or reuses an API key, previews its configuration changes, and connects the agents you select. For Claude Code, it uses the dedicated AI Gateway endpoint and adds Gateway models to the /model picker. For Claude Desktop, configure Third-Party Inference in the app settings. See Coding Agents for all supported agents and manual setup. Make your first request Create an API key You need a Vercel account. To use free AI Gateway Credits, add a valid payment method to your team. The cURL path needs no runtime. The TypeScript path needs Node.js 22.18 or later, and the Python path needs Python 3.12 or later with uv. Create and export an API key: Open the Create API Key dialog, enter a name, and select Create API Key. The link opens the dialog directly. Copy the key immediately and export it in the terminal where you will run the example. You cannot retrieve its value again. Terminalexport AI_GATEWAY_API_KEY="your_ai_gateway_api_key" Vercel deployments can use an OIDC token instead of a long-lived API key. This tutorial uses an API key so the examples work in any environment. These examples use openai/gpt-6-astra and consume AI Gateway Credits. You can replace the model slug with any model your team can access. If your team has not purchased credits, choose a free-tier model. cURLTypeScriptPythonSend a Chat Completions request directly to AI Gateway:Terminalcurl https://ai-gateway.vercel.sh/v1/chat/completions \ -H "Authorization: Bearer $AI_GATEWAY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-6-astra", "messages": [ { "role": "user", "content": "Invent a new holiday and describe its traditions." } ] }'Install the AI SDK:Terminalpnpm add ai@latestCreate index.mts:index.mtsimport { generateText } from 'ai'; const { text } = await generateText({ model: 'openai/gpt-6-astra', prompt: 'Invent a new holiday and describe its traditions.', }); console.log(text);Run the script:Terminalnode index.mtsCreate quickstart.py:quickstart.pyimport asyncio import ai async def main() -> None: model = ai.get_model('openai/gpt-6-astra') messages = [ ai.user_message('Invent a new holiday and describe its traditions.') ] async with ai.stream(model, messages) as stream: async for event in stream: if isinstance(event, ai.events.TextDelta): print(event.chunk, end='', flush=True) print() if __name__ == '__main__': asyncio.run(main())Run the script with the AI SDK for Python:Terminaluv run --with ai quickstart.py Monitor your request After the request completes, open AI Gateway Logs and select the newest request. You can inspect its status, model, provider, token usage, cost, duration, and routing attempts. Logs may take up to 90 seconds to appear. Refresh the page if you don't see the request. Use AI Gateway with existing code Use a supported SDK or API to connect an existing client. To move calls from a provider endpoint without changing their behavior, migrate to AI Gateway. Next steps Troubleshoot request errors by status code, type, and message Generate text, images, video, realtime audio, or speech Answer typed questions about application state in the Decision quickstart Extract typed field values from text in the Extraction quickstart Browse models by capability, provider, price, and free-tier availability, or query GET /v1/models Configure provider routing and model fallbacks Build an agent application Last updated November 19, 2026PreviousAI GatewayNextMigrate to AI GatewayWas this helpful?