1. 问题现象与初步诊断
最近在基于Firebase的Angular项目中集成Vertex AI时遇到了一个奇怪的问题:使用gemini-2.5-flash-preview-05-20模型可以正常工作,但切换到gemini-2.5-pro-preview-06-05时却返回404错误。这个现象让我感到困惑,因为官方文档显示这两个模型都是公开可用的。
首先让我们明确几个关键信息点:
- 项目环境:Angular + Firebase + Vertex AI SDK
- 正常工作的模型:
gemini-2.5-flash-preview-05-20 - 报错的模型:
gemini-2.5-pro-preview-06-05 - 错误类型:HTTP 404 Not Found
需要模型API调用? 免费领10W Token,多模型网关一键接入 Claude、DeepSeek 等主流模型。
2. 模型可用性验证
2.1 检查模型发布状态
第一个需要验证的是模型是否真的可用。虽然用户提到模型是"公开可用版本",但预览版模型有时会有地域限制或阶段性发布。我通过以下步骤进行了验证:
- 访问Google Cloud Console的Vertex AI模型库
- 在"预训练模型"部分搜索"gemini-2.5-pro-preview-06-05"
- 确认模型确实存在于列表中,且我的项目所在区域(us-central1)支持该模型
2.2 测试不同调用方式
为了排除是Firebase集成特有的问题,我尝试了三种不同的调用方式:
javascript复制// 方式1:直接使用Vertex AI SDK(非Firebase环境)
const {VertexAI} = require('@google-cloud/vertexai');
const vertexAI = new VertexAI({project: 'my-project', location: 'us-central1'});
const model = vertexAI.getGenerativeModel({
model: 'gemini-2.5-pro-preview-06-05'
});
// 方式2:通过Firebase Functions中转
exports.callGemini = functions.https.onCall(async (data, context) => {
const vertexAI = new VertexAI({project: 'my-project', location: 'us-central1'});
const model = vertexAI.getGenerativeModel({
model: 'gemini-2.5-pro-preview-06-05'
});
// ...调用逻辑
});
// 方式3:使用Firebase前端SDK(原问题中的方式)
const model = getGenerativeModel(this.vertexAI, {
model: "gemini-2.5-pro-preview-06-05"
});
测试结果:
- 方式1和方式2工作正常
- 方式3仍然返回404错误
