feat(vertex): 为 ai-proxy 插件的 Vertex AI Provider 添加 Express Mode 支持 || feat(vertex): Add Express Mode support to Vertex AI Provider of ai-proxy plug-in #3301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ⅰ. Describe what this PR did
本 PR 为 ai-proxy 插件的 Vertex AI Provider 添加了 Express Mode 支持。
背景
Vertex AI 新推出了 Express Mode,这是一种简化的访问模式,允许开发者只使用 API Key 即可快速开始使用 Vertex AI,无需配置复杂的 Service Account 认证。详见 Vertex AI Express Mode 官方文档。
主要变更
实现 Express Mode 逻辑(
provider/vertex.go):isExpressMode()方法:通过检测apiTokens是否配置来判断是否启用 Express ModeapiTokens,则使用 Express Mode,无需其他配置aiplatform.googleapis.com(不带 region 前缀)/v1/publishers/google/models/{model}:{action}?key={API_KEY}格式更新文档:
README.md- 添加 Express Mode 配置说明和使用示例(中文)README_EN.md- 添加 Express Mode 配置说明和使用示例(英文)添加单元测试(
test/vertex.go):Express Mode vs 标准模式对比
{region}-aiplatform.googleapis.comaiplatform.googleapis.com/v1/projects/{project}/locations/{location}/publishers/google/models/{model}:{action}/v1/publishers/google/models/{model}:{action}?key={API_KEY}配置简化说明
Express Mode 的配置与其他 Provider 保持一致,只需配置
apiTokens即可自动启用 Express Mode,无需额外的配置项:Ⅱ. Does this pull request fix one issue?
N/A - 这是一个新功能特性
Ⅲ. Why don't you add test cases (unit test/integration test)?
已添加完整的单元测试,位于
test/vertex.go,覆盖以下场景:所有测试均已通过。
Ⅳ. Describe how to verify it
方式一:运行单元测试
方式二:配置验证
aiplatform.googleapis.com/v1/publishers/google/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEYⅤ. Special notes for reviews
向后兼容:如果没有配置
apiTokens,则继续使用标准模式(Service Account 认证),不影响现有用户配置简化:与其他 Provider 保持一致,使用
apiTokens配置项,无需引入新的配置字段Claude 模型支持:Express Mode 同样支持通过 Vertex AI 调用 Anthropic Claude 模型
Ⅵ. AI Coding Tool Usage Checklist (if applicable)
Please check all applicable items:
AI Coding Summary
关键决策:
apiTokens配置项来判断是否启用 Express Mode,与其他 Provider 保持一致isExpressMode()辅助方法,通过检测len(apiTokens) > 0来判断模式主要变更:
provider/vertex.go- 添加isExpressMode()方法和 Express Mode 路径模板,修改配置验证、域名处理、路径生成和认证逻辑README.md/README_EN.md- 添加双语配置文档和使用示例test/vertex.go- 创建完整的测试套件main_test.go- 注册 Vertex 测试函数重要考虑和限制:
apiTokens一个配置项即可启用 Express ModeⅠ. Describe what this PR did
This PR adds Express Mode support to the Vertex AI Provider of the ai-proxy plugin.
Background
Vertex AI has newly launched Express Mode, a simplified access mode that allows developers to quickly start using Vertex AI using only API Keys without configuring complex Service Account authentication. For details, see Vertex AI Express Mode official documentation.
Major changes
Implement Express Mode logic (
provider/vertex.go):isExpressMode()method: determine whether Express Mode is enabled by detecting whetherapiTokensis configuredapiTokensis configured, Express Mode is used, no other configuration is requiredaiplatform.googleapis.com(without region prefix)/v1/publishers/google/models/{model}:{action}?key={API_KEY}formatUpdated Documentation:
README.md- Add Express Mode configuration instructions and usage examples (Chinese)README_EN.md- Add Express Mode configuration instructions and usage examples (English)Add unit test (
test/vertex.go):Express Mode vs Standard Mode Comparison
{region}-aiplatform.googleapis.comaiplatform.googleapis.com/v1/projects/{project}/locations/{location}/publishers/google/models/{model}:{action}/v1/publishers/google/models/{model}:{action}?key={API_KEY}Simplified configuration instructions
The configuration of Express Mode is consistent with other Providers. You only need to configure
apiTokensto automatically enable Express Mode without additional configuration items:Ⅱ. Does this pull request fix one issue?
N/A - This is a new feature
Ⅲ. Why don't you add test cases (unit test/integration test)?
Complete unit tests have been added, located in
test/vertex.go, covering the following scenarios:All tests passed.
Ⅳ. Describe how to verify it
Method 1: Run unit tests
Method 2: Configuration verification
aiplatform.googleapis.com/v1/publishers/google/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEYⅤ. Special notes for reviews
Backwards Compatibility: If
apiTokensis not configured, the standard mode (Service Account authentication) will continue to be used, and existing users will not be affected.Configuration Simplification: Consistent with other Providers, using the
apiTokensconfiguration item, no need to introduce new configuration fieldsClaude model support: Express Mode also supports calling the Anthropic Claude model through Vertex AI
Ⅵ. AI Coding Tool Usage Checklist (if applicable)
Please check all applicable items:
AI Coding Summary
Key Decisions:
apiTokensconfiguration item to determine whether to enable Express Mode, consistent with other ProvidersisExpressMode()auxiliary method to determine the mode by detectinglen(apiTokens) > 0Major changes:
provider/vertex.go- AddisExpressMode()method and Express Mode path template, modify configuration verification, domain name processing, path generation and authentication logicREADME.md/README_EN.md- Add bilingual configuration documents and usage examplestest/vertex.go- Create a complete test suitemain_test.go- Register Vertex test functionIMPORTANT CONSIDERATIONS AND LIMITATIONS:
apiTokensis needed to enable Express Mode