@googledevs:不再有硬编码端点。API Gateway 的模型路由现已进入公开预览!通过单个端点即可访问 Gemini、Claude 和 OSS 模型……
摘要
Google Cloud API Gateway 宣布模型路由公开预览,让开发者通过使用 OpenAPI 规范的单一端点访问 Gemini、Claude 和 OSS 模型。
查看缓存全文
缓存时间: 2026/08/04 18:13
不再需要硬编码端点。API Gateway 的模型路由现已进入公开预览版!通过单个端点访问 Gemini、Claude 和 OSS 模型,只需在 OpenAPI 规范中将模型名称作为参数即可。
阅读配置指南 ➔ https://t.co/K71ZvP0uD5 https://t.co/NHGhjPOsLn
用于 AI 模型路由的统一 API
来源:https://developers.googleblog.com/a-unified-api-for-ai-model-routing/
- 社区/活动 (https://developers.google.com/community)
- 学习 (https://developers.google.com/solutions/catalog)
- 博客 (https://developers.googleblog.com/)
- YouTube (https://www.youtube.com/user/GoogleDevelopers)
在构建 AI 应用时,开发者需要能够自由地将流量路由到最适合任务的模型,而无需硬编码端点或管理开源代理。Google Cloud API Gateway (https://docs.cloud.google.com/api-gateway/docs) 现已提供公开预览版模型路由来解决这一问题。它提供了一个轻量级的无服务器入口层,可接受 OpenAI 兼容请求,并动态地将它们路由到 Gemini、Claude 或 OpenAI OSS-GPT。
API Gateway 既可独立用于简单的速率限制和令牌跟踪,也可与 Gemini Enterprise Agent Platform 无缝搭配。例如,您可以将代理的出站流量通过 Agent Gateway 路由,以实现严格的安全治理,然后将请求传递给 API Gateway,由其处理到 Google 托管的 LLM 的动态路由。以下是如何配置路由逻辑的分步指南。
路由你的流量
设置模型路由逻辑只需几个步骤:
- 配置路由规则: 您可以直接在 OpenAPI 3.x 规范中使用新的
x-google-api-management扩展块,将虚拟模型名称映射到特定的后端目标。
`` openapi: 3.0.4
info: title: OpenAPI 3.x spec using Model Routing description: Using Model Routing in an OAS 3.x spec version: 1.0.0
x-google-api-management: backends: gemini-35-flashlite: address: >- https://aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/global/publishers/google/models/gemini-3.5-flash-lite:generateContent deadline: 60.0 pathTranslation: CONSTANT_ADDRESS
anthropic-claude-opus-47:
address: >-
https://aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/global/publishers/anthropic/models/claude-opus-4-7:rawPredict
deadline: 60.0
pathTranslation: CONSTANT_ADDRESS
openai-gpt-oss-120b:
address: >-
https://aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/global/endpoints/openapi/chat/completions
deadline: 60.0
pathTranslation: CONSTANT_ADDRESS
ai: models: routing: routers: # Router 1: route between Gemini (default) and Claude. gemini-claude-router: defaultModel: backend: gemini-35-flashlite targetModel: google/gemini-3.5-flash-lite rules: - model: “claude-opus-4-7” backend: anthropic-claude-opus-47 targetModel: anthropic/claude-opus-4-7
# Router 2: route between OpenAI GPT (default) and Gemini.
openai-gemini-router:
defaultModel:
backend: openai-gpt-oss-120b
targetModel: openai/gpt-oss-120b-maas
rules:
- model: "gemini-3.5-flash-lite"
backend: gemini-35-flashlite
targetModel: google/gemini-3.5-flash-lite
servers:
- url: “https://my-gateway-url.com”
paths: /v1/chat/gemini-claude: post: summary: “Endpoint:defaults to Gemini & Claude as an option.” operationId: “chatGeminiClaude” x-google-model-router: gemini-claude-router responses: ‘200’: description: “OK”
/v1/chat/openai-gemini: post: summary: “Endpoint:defaults to OpenAI & Gemini as an option.” operationId: “chatOpenAIGemini” x-google-model-router: openai-gemini-router responses: ‘200’: description: “OK” ``
YAML
已复制
注意: 单个路由器引用的所有后端必须共享同一主机(例如 aiplatform.googleapis.com)。路由会在该共享 Vertex 主机上选择不同的模型和路径——不会跨不同主机进行路由。
-
部署网关: 部署更新后的 API 配置,使网关处于活动状态并准备好处理流量。
-
发送标准请求: 您的应用只需发送标准 OpenAI
POST /v1/chat/gemini-claude或POST /v1/chat/openai-gemini请求。网关会拦截该请求,将负载转码为后端的原生架构,并即时进行路由。例如(请为$API_KEY和my-gateway-url.com使用适当的值):
curl -X POST "https://my-gateway-url.com/v1/chat/gemini-claude" \ -H "content-type: application/json" \ -H "x-api-key: $API_KEY" \ -d '{ "model": "claude-opus-4-7", "messages": [ {"role": "user", "content": "Introduce yourself in 5 words"} ] }'
Shell
已复制
开始使用
模型路由现已在 API Gateway 中提供公开预览版。为了不再管理代理并开始统一你的 AI 流量,请查看我们的文档 (https://docs.cloud.google.com/api-gateway/docs/model-routing-overview) 来立即部署你的第一个模型路由器。
相似文章
AI模型路由的统一API(3分钟阅读)
Google Cloud API Gateway 现已在公开预览版中提供模型路由,提供一个无服务器入口层,可接受兼容 OpenAI 的请求,并动态路由到 Gemini、Claude 或 OpenAI 模型。
@googledevs: Agent and Model Evaluations in Gemini Enterprise Agent Platform are now Generally Available (GA)! Measure, test, and mo…
Google announces GA of Agent and Model Evaluations in Gemini Enterprise Agent Platform, enabling consistent measurement and monitoring of AI agents in dev and production with pre-built metrics, adaptive rubrics, simulators, and online monitors.
我们为AI智能体构建了一个统一API网关——经验教训
我们为AI智能体构建了一个统一API网关,通过单个兼容OpenAI的端点支持Claude、GPT、Codex、Gemini等多种模型。它简化了构建AI智能体和SaaS产品的开发者的集成、计费和部署流程。
@googledevs:Interactions API 现已正式发布(GA),成为构建……的主要接口
Google 针对 Gemini 模型和智能体的 Interactions API 现已正式发布,推出了托管智能体、用于长时间运行任务的背景执行,以及即将支持的 Gemini Omni。
@GoogleAIStudio:今天我们首次在 AI Studio 中分享 Gemini API 文档的预览。我们从零开始构建了这个体验…
Google AI Studio 推出首个集成 Gemini API 文档的预览,通过直接将资源整合到平台内,提升开发者的便利性。