You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JobServiceClient在Vertex AI创建自定义作业触发gRPC未实现错误

Vertex AI自定义作业.NET代码调用404异常排查

问题描述

使用gcloud命令可正常在Vertex AI中创建自定义作业:

gcloud ai custom-jobs --project my_project_id create --region=europe-west1 --display-name="train model based on custom container" --worker-pool-spec=machine-type=n1-standard-4,replica-count=1,container-image-uri=europe-west1-docker.pkg.dev/my_project_id/my-repo/my-custom-prototype:latest

参考Python实现及生成的代码编写了.NET代码,但调用时抛出404异常:

var projectId = "my_project_id";
var locationId = "europe-west1";
var client = await JobServiceClient.CreateAsync();

var createCustomJobRequest = new CreateCustomJobRequest
{
  ParentAsLocationName = new LocationName(projectId, locationId),
  CustomJob = new CustomJob
  {
    DisplayName = "train model based on custom container",
    JobSpec = new CustomJobSpec()
    {
      WorkerPoolSpecs =
      {
        new WorkerPoolSpec
        {
          MachineSpec = new MachineSpec
          {
            MachineType = "n1-standard-4"
          },
          ReplicaCount = 1,
          ContainerSpec = new ContainerSpec()
          {
            ImageUri = "europe-west1-docker.pkg.dev/my_project_id/my-repo/my-custom-prototype:latest"
          }
        }
      }
    }
  }
};

var result3 = await client.CreateCustomJobAsync(createCustomJobRequest); // exception thrown here

抛出的异常信息:

Grpc.Core.RpcException: 'Status(StatusCode="Unimplemented", Detail="Bad gRPC response. HTTP status code: 404")'

已尝试以下方案但均失败:

  • 使用接收CustomJob和Parent参数的CreateCustomJobAsync()重载方法;
  • 使用JobServiceClientBuilder替代JobServiceClient.CreateAsync(),将Endpoint设为europe-west1-aiplatform.googleapis.com。

请问还缺少什么配置才能成功启动自定义作业?

解决方案

针对该404异常,可从以下几个方面排查修正:

  1. 修正客户端Endpoint格式
    设置Endpoint时需包含端口号443,完整的客户端构建代码示例:

    var clientBuilder = new JobServiceClientBuilder
    {
        Endpoint = "europe-west1-aiplatform.googleapis.com:443",
        Credentials = GoogleCredential.GetApplicationDefault()
    };
    var client = clientBuilder.Build();
    

    之前遗漏端口号会导致gRPC请求无法正确路由到服务端。

  2. 验证权限与认证配置
    确保运行代码的环境拥有aiplatform.jobs.create权限,且认证凭据(如服务账号密钥)配置正确。可通过设置环境变量GOOGLE_APPLICATION_CREDENTIALS指向密钥文件,或在代码中显式加载凭据。

  3. 补全必填字段类型
    .NET客户端需显式指定部分字段的类型,比如ReplicaCount需为long类型(对应gRPC的int64),避免类型不匹配导致的隐性错误:

    new WorkerPoolSpec
    {
      MachineSpec = new MachineSpec { MachineType = "n1-standard-4" },
      ReplicaCount = 1L, // 显式指定为long类型
      ContainerSpec = new ContainerSpec { ImageUri = "europe-west1-docker.pkg.dev/my_project_id/my-repo/my-custom-prototype:latest" }
    }
    
  4. 确认Vertex AI API已启用
    再次确认项目中的Vertex AI API(aiplatform.googleapis.com)已启用,避免因API未启用导致的404错误。

内容的提问来源于stack exchange,提问作者OnionJack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 21:12:25