Logo Ai Gateway

Ai Gateway

Tổ chức
vercel
ai-gateway

Vercel AI Gateway guidance for setup, model discovery, authentication, routing, fallbacks, BYOK, budgets, spend reporting, observability, compatible APIs, and coding-agent configuration. Use when adding AI Gateway to an app, migrating provider calls, choosing models or providers, debugging gateway requests, or running `vercel ai-gateway` commands.

Tổng quan

Nhà phát hànhvercel
Kho mãvercel-plugin
Tên kỹ năngai-gateway
Sao
286
Bản fork
56
Tệp đi kèm
4
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 4 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được vercel công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Ai Gateway trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/vercel/vercel-plugin/tree/main/skills/ai-gateway
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/vercel/vercel-plugin.git /tmp/vercel-plugin
mkdir -p .claude/skills
cp -r /tmp/vercel-plugin/skills/ai-gateway .claude/skills/ai-gateway
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Ai Gateway trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Ai Gateway ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Ai Gateway với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Vercel AI Gateway

AI Gateway exposes models from multiple providers through shared authentication, model IDs, routing, billing, and observability. Model availability, SDK APIs, CLI commands, prices, and product capabilities change frequently. Verify them from current sources before changing code.

Start with current sources

Before implementing:

  1. Inspect the project's language, package manager, installed AI SDK version, and existing provider integration.

  2. Read the relevant Vercel page under https://vercel.com/docs/ai-gateway. Use the page's .md form when a tool needs Markdown.

  3. Fetch the complete live model list. Do not construct model variants by analogy:

    bash
    curl -fsSL https://ai-gateway.vercel.sh/v1/models
  4. If the code uses the ai package, load the ai-sdk skill when available. Read version-matched docs under node_modules/ai/docs/ and source under node_modules/ai/src/. If the skill is not installed, use those bundled files directly.

  5. Run vercel ai-gateway <command> --help before documenting or scripting CLI flags.

The live model endpoint and installed package take precedence over model names or SDK syntax remembered from training data.

Vercel CLI inventory

The vercel ai-gateway command manages gateway resources for the current team. The setup subcommand connects local coding agents; the rest of the CLI covers the jobs that previously required dashboard work:

CommandWhat it does
api-keys create/list/inspect/removeCreate and manage AI Gateway API keys, with budgets, spend alerts, expiry, and restriction exemptions
budgets set/list/inspect/removeSet metered spend limits for the team, a project, a user, or an API key
budgets defaults set/list/removeSet per-scope default limits covering projects, keys, or members without a custom budget
models list / models endpoints <model>List the model catalog and one model's provider endpoints from the CLI
rules add/list/edit/removeManage routing rules; the CLI marks rules beta, so check --help before relying on them. REST CRUD exists under /v1/ai-gateway/rules
setupConfigure supported coding agents; see references/coding-agents.md
leaderboardExplore public, anonymized usage leaderboards; rarely needed for implementation work

Use the CLI for credential and spend management when the user is working from a terminal or in CI. Check vercel ai-gateway <command> --help for current flags before scripting; do not copy a flag list from this skill into generated code.

Route the request to the right guide

User's jobRead
Ask a coding agent to make one Gateway request, or handle first-request credentials, compatible SDKs, or migrationreferences/setup.md
Provider selection, model fallbacks, caching, BYOK, or timeoutsreferences/routing.md
Credits, budgets, reporting, Logs, or request debuggingreferences/spend-observability.md
Route Claude Code, Codex, OpenCode, Pi, or another coding agent's own model traffic through Gatewayreferences/coding-agents.md

Read each relevant reference before editing. A task can require more than one.

Choose the integration surface

Existing projectDefault path
JavaScript or TypeScript using AI SDKUse a plain provider/model string with generateText, streamText, ToolLoopAgent, or the relevant modality API
Python using AI SDK for PythonUse ai.get_model('provider/model') and the current Python SDK docs
Existing OpenAI SDKKeep the SDK and point baseURL or base_url to https://ai-gateway.vercel.sh/v1
Existing Anthropic SDKKeep the SDK and point baseURL or base_url to https://ai-gateway.vercel.sh
Provider-neutral HTTPUse an AI Gateway compatible endpoint, such as Chat Completions or OpenResponses
Existing direct-provider AI SDK integrationReplace the provider instance with a live AI Gateway provider/model string, then remove provider credentials only after verifying the gateway path
Coding agentUse vercel ai-gateway setup; inspect its help before claiming agent support

AI Gateway also supports OpenAI Responses, Anthropic Messages, OpenResponses, Cohere Rerank, embeddings, image and video generation, speech, transcription, and realtime sessions. Modality pages under https://vercel.com/docs/ai-gateway/modalities cover each request shape, including background jobs for long-running video generation. Read the relevant modality or API page instead of translating one request shape from memory.

Minimal AI SDK request

The current AI SDK requires Node.js 22 or later. Confirm the installed package's engines field before enforcing a version in an existing project.

ts
import { generateText } from 'ai';

const model = process.env.AI_GATEWAY_MODEL;
if (!model) {
  throw new Error('Set AI_GATEWAY_MODEL to an ID returned by /v1/models');
}

const { text } = await generateText({
  model,
  prompt: 'Explain the project in one paragraph.',
});

console.log(text);

Honor an exact model the user or task specifies after confirming it exists. Otherwise fetch /v1/models, choose a model that fits the requested modality, capabilities, price, context window, data-retention policy, and team access, and set AI_GATEWAY_MODEL to that ID. Do not put a time-sensitive model recommendation in reusable examples.

Plain model strings route through AI Gateway. Add @ai-sdk/gateway only when the task needs its exported provider, types, model discovery, generation lookup, or spend-report helpers.

Authentication decision

  • Use an AI Gateway API key for local scripts, CI, external servers, and non-Vercel deployments. Store it in AI_GATEWAY_API_KEY and never print or commit it.
  • Use Vercel OIDC for Vercel deployments and linked local projects. Vercel deployments receive VERCEL_OIDC_TOKEN; local development uses vercel link and vercel env pull.
  • BYOK provider credentials do not replace AI Gateway request authentication. They decide how AI Gateway authenticates to a model provider.
  • A plain Node.js script does not automatically load .env.local. Export variables in the shell or load that file explicitly. Framework behavior may differ.

Do not ask the user to paste a secret into chat, source code, a committed config file, or a command that will enter shell history unless the repository has an established secure mechanism.

Implementation workflow

  1. Establish the user's job, runtime, deployment target, current provider, and required capabilities.
  2. Select authentication from the rules above. Preserve a working existing method unless the user asked to migrate it.
  3. Fetch live model metadata and choose a compatible model. State why it fits.
  4. Read the matching SDK, API, modality, routing, or coding-agent docs.
  5. Make the smallest end-to-end change. Reuse the current project structure and error handling.
  6. Handle only errors the application can act on. Common gateway outcomes include authentication failure, insufficient credits, budget exhaustion, rate limiting, and provider capacity failure.
  7. Run the project's formatter, type checker, and focused tests.
  8. When the task authorizes a live request, run one and inspect the returned model, text or media, usage, and provider metadata.
  9. Verify the request in AI Gateway Logs when dashboard access is available. Logs can take about 90 seconds to ingest.

Only spend credits, create keys, change budgets, change routing rules, or write coding-agent config when the user requested or approved that outward-facing action. Prefer dry runs and interactive previews when available.

Routing invariants

  • Model IDs use the exact provider/model strings returned by /v1/models.
  • order controls provider preference, only restricts providers, and sort ranks providers by a supported metric.
  • models lists fallback models after the primary model.
  • caching: 'auto' manages provider prompt-cache markers. It is not an HTTP response cache.
  • providerTimeouts applies to BYOK provider attempts and measures time until the provider starts responding.
  • A reasoning entry in providerOptions overrides the AI SDK top-level reasoning value entirely; the two never merge.
  • user and tags attach reporting dimensions. They do not create per-user rate limits.
  • Request-scoped provider credentials belong under providerOptions.gateway.byok and must remain secret.

Read references/routing.md before adding any of these fields.

Verification checklist

  • The model ID exists in the full live model response.
  • The selected API or SDK supports the requested modality and feature.
  • Authentication works in the actual runtime, including .env.local loading where relevant.
  • The example prints or returns a result instead of discarding the response.
  • The project type checker and focused tests pass.
  • A live request was made only when authorized, and its cost was understood.
  • Provider routing or fallback behavior is visible in response metadata or Logs.
  • No secret appears in source, logs, diffs, or the final response.
  • The final report distinguishes code verification from live and dashboard verification.

Current documentation

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Ai Gateway làm được gì?

Vercel AI Gateway guidance for setup, model discovery, authentication, routing, fallbacks, BYOK, budgets, spend reporting, observability, compatible APIs, and coding-agent configuration. Use when adding AI Gateway to an app, migrating provider calls, choosing models or providers, debugging gateway requests, or running `vercel ai-gateway` commands.

Vì sao nên dùng Ai Gateway trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Ai Gateway là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Ai Gateway trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/vercel/vercel-plugin/tree/main/skills/ai-gateway. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Ai Gateway?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Ai Gateway với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Ai Gateway với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Ai Gateway có miễn phí không?

Kỹ năng này được vercel phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇