报错是这么冒出来的。google-cloud-aiplatform 1.71 在 asia-east1 的项目里调 gemini-2.5-flash,按文档把 location 改成 global,返回 400,原文 Publisher Model projects/xxx/locations/global/publishers/google/models/gemini-2.5-flash was not found,改回 us-central1 就通。
中间走过弯路,把「SDK 里 endpoint 与 location 两个参数同时传,后者被覆盖」当成主因,改完现象没变。
这类报错背后常见的原因有几处,逐个排除就行。global 端点不参与区域路由,客户端仍按区域拼主机名。另一种情况是该模型在 global 只有部分账号可见,项目还没开通。
少数情况下是初始化客户端时缓存了旧 endpoint,改了配置没生效。
动手时先打印客户端实际使用的 api_endpoint
python -c "from google import genai;c=genai.Client(vertexai=True,project='p',location='global');print(c._api_client._http_options.base_url)"
再往下用 curl 直接打 global 的 v1beta 接口核对模型名
curl -X POST "https://aiplatform.googleapis.com/v1beta/projects/p/locations/global/publishers/google/models/gemini-2.5-flash:generateContent" -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -d '{"contents":[{"role":"user","parts":[{"text":"ping"}]}]}'
接着换成支持区域的主机名再请求一次
curl -X POST "https://us-central1-aiplatform.googleapis.com/v1/projects/p/locations/us-central1/publishers/google/models/gemini-2.5-flash:generateContent" -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -d '{"contents":[{"role":"user","parts":[{"text":"ping"}]}]}'
剩下的就是确认项目在该区域的配额已开通
gcloud services list --enabled --project p | grep aiplatform
怎么算真的好了,看的是同一批现象。返回 200 且 candidates 里有正常文本,日志里的 base_url 与 location 一致,延迟回到 300ms 量级。
容易忽略的是,global 只是路由策略,主机名仍要按规范写,别把 location 直接拼进域名;多区域部署时把 endpoint 显式传进去,比依赖 SDK 推断可靠。拖得越久,排查成本越高,因为现场状态会被后续操作覆盖。
