用途:该技能面向在 Google Cloud Platform(GCP)上通过 Vertex AI 调用 Claude/Anthropic 模型,以及与 Secret Manager、Cloud Run、Cloud Monitoring、BigQuery 等 GCP 服务配合的场景,记录实测发现的失败模式与正确用法。
主要能力与要点: 模型 ID:在 Vertex 上使用不带版本后缀的模型 ID 获取最新模型,例如 model: 'claude-sonnet-4-5';带版本后缀在 Vertex 不受支持。 SDK:应使用 @anthropic-ai/vertex-sdk,而非 @google-cloud/vertexai;安装命令为 npm install @anthropic-ai/vertex-sdk。Claude 模型位于 publishers/anthropic,而非 publishers/google。 anthropic_beta 必须在请求体中作为数组传入,而非 HTTP 头。 thinking 参数:Vertex 不支持 { type: 'adaptive' },应使用 thinking: { type: 'enabled', budget_tokens: 10000 }。 认证:本地开发可用标准 GCP 应用默认凭据:gcloud auth application-default login 与 gcloud config set project YOUR_PROJECT_ID,Vertex SDK 会自动读取 ADC。
限制与注意事项: Secret Manager 以环境变量注入时使用原始字节,末尾换行会一并带入,可能导致长度校验或字符串比较失败;建议存储时不带尾换行,读取后 .strip()。 Cloud Run Job 在创建时即校验 Secret 版本是否存在,IAM 绑定可能存在传播延迟;可改用 gcloud run jobs update 等方式挂载,并用 lifecycle ignore_changes 防止 Terraform 覆盖。 Cloud Monitoring 的 notification_rate_limit 仅适用于基于日志的告警策略,指标类告警策略会返回 400,应省略 alert_strategy。 结合 BigQuery 与 Vertex AI Claude 调用时,建议先用 bigquery CLI 技能查询,再将结果作为结构化上下文传入 Claude API 请求体。