Vertex AI API Key mode builds URL without project_id, causing 404 for official Vertex endpoints
Vertex AI API Key mode builds URL without project_id, causing 404 for official Vertex endpoints
Current new-api version
Local source checked against QuantumNous/new-api:
- Branch:
main - Commit:
7c28993f6bd9e92616f3f578212577f8b7c40b45 - Commit date:
2026-07-12 00:24:17 +0800 - Latest GitHub
mainwas also checked on 2026-07-16, and the same URL-building behavior still exists.
Issue Description
When configuring a Vertex AI channel with Vertex AI Key Format = API Key, NewAPI builds the upstream Vertex URL without project_id.
For Gemini image/text models on Vertex AI, the official Google endpoint format requires:
https://aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{REGION}/publishers/google/models/{MODEL}:generateContent?key={API_KEY}
Example official Vertex AI call:
curl -X POST \
-H "Content-Type: application/json" \
"https://aiplatform.googleapis.com/v1/projects/zmdy6v-mffg/locations/global/publishers/google/models/gemini-3.1-flash-image:streamGenerateContent?key=${API_KEY}" \
-d '{
"contents": {
"role": "user",
"parts": {
"text": "介绍一下你自己"
}
}
}'
However, with vertex_key_type = api_key, the current NewAPI source passes an empty projectID to BuildGoogleModelURL:
BuildGoogleModelURL(info.ChannelBaseUrl, DefaultAPIVersion, "", region, modelName, suffix)
This produces a URL like:
https://aiplatform.googleapis.com/v1/publishers/google/models/gemini-3.1-flash-image:generateContent?key={API_KEY}
The /projects/{PROJECT_ID}/locations/{REGION} segment is missing, and Vertex AI returns 404.
Steps to Reproduce
- Create a Vertex AI channel.
- Set
Vertex AI Key FormattoAPI Key. - Set key to a valid Google API key that works with the official Vertex AI URL.
- Configure deployment region:
{"default":"global","gemini-3.1-flash-image":"global"}
- Add model:
gemini-3.1-flash-image
- Call NewAPI through OpenAI-compatible Chat Completions:
curl -X POST "https://your-newapi.example/v1/chat/completions" \
-H "Authorization: Bearer ${NEWAPI_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"messages": [
{"role": "user", "content": "生成一张橘猫宇航员海报"}
],
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "1:1",
"image_size": "1K"
}
}
}
}'
Actual Result
NewAPI returns an upstream 404 wrapped as:
{
"error": {
"message": "openai_error",
"type": "bad_response_status_code",
"param": "",
"code": "bad_response_status_code"
}
}
Expected Result
API Key mode should provide a way to configure project_id, and should build the same official Vertex AI path:
https://aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{REGION}/publishers/google/models/{MODEL}:generateContent?key={API_KEY}
Source Analysis
Current code path:
relay/channel/vertex/adaptor.gogetRequestUrl
For JSON service account mode, project_id is read from the service account JSON:
return BuildGoogleModelURL(info.ChannelBaseUrl, DefaultAPIVersion, adc.ProjectID, region, modelName, suffix), nil
For API Key mode, projectID is hardcoded to empty string:
return fmt.Sprintf(
"%s%skey=%s",
BuildGoogleModelURL(info.ChannelBaseUrl, DefaultAPIVersion, "", region, modelName, suffix),
keyPrefix,
info.ApiKey,
), nil
BuildAPIBaseURL only appends /projects/{projectID}/locations/{region} when projectID is non-empty.
Suggested Fix
Add a project_id setting for Vertex AI API Key mode, for example under ChannelOtherSettings, and pass it into BuildGoogleModelURL when vertex_key_type == api_key.
Possible configuration:
{
"vertex_key_type": "api_key",
"vertex_project_id": "zmdy6v-mffg"
}
Then API Key mode can build:
BuildGoogleModelURL(info.ChannelBaseUrl, DefaultAPIVersion, info.ChannelOtherSettings.VertexProjectID, region, modelName, suffix)
Related Issues / PRs
- #2404 discusses Vertex official
/projects/{PROJECT_ID}/locations/{REGION}style endpoint paths for Vertex AI open-source/MaaS models. - #4200 fixed Vertex custom
base_urlhandling, but it still relies on service-account JSON mode forproject_id. - #1055 also discusses Vertex AI API address behavior.
[Bot Review]
Thanks for the detailed report. The issue includes a clear description and reproduction steps, but it is missing the required Submission Checks checkbox section, and the version info is not under the standard 版本/version template section. Please update the issue to match the bug report template structure so it can be reviewed more easily.
我准备处理这个 issue。修复思路:在 ChannelOtherSettings 加一个 vertex_project_id 字段,前端在 VertexKeyType=api_key 时显示输入框;后端 getRequestUrl 的 api_key 分支用这个字段替代硬编码的空字符串,调 BuildGoogleModelURL / BuildAnthropicModelURL 时透传 project_id。
我准备处理这个问题。修复思路:在
ChannelOtherSettings加一个vertex_project_id字段,前置在VertexKeyType=api_key时显示输入;仓库getRequestUrl的api_key框分支用这个字段替代硬编码的空字符串,调BuildGoogleModelURL/BuildAnthropicModelURL时透传project_id。
我很需要这个更新,请一定要合并啊!
same problem