调用Google AutoML JS predict接口报Unsupported payload type `row`错误
报错根因
Unsupported payload type 'row' 报错由两个核心问题导致:
- 客户端库不匹配:Python代码使用的是Vertex AI平台的
aiplatform客户端,对应JS端应该使用@google-cloud/aiplatform库,你当前使用的旧版@google-cloud/automlv1beta1客户端和Vertex AI预测接口的请求结构完全不兼容。 - Payload结构错误:Vertex AI预测接口不需要嵌套
row.values字段,直接传入实例数组即可。
修复步骤
- 第一步:替换依赖库
npm uninstall @google-cloud/automl npm install @google-cloud/aiplatform
- 第二步:调整请求代码结构
const {PredictionServiceClient} = require('@google-cloud/aiplatform').v1; const ai = new PredictionServiceClient({ projectId: projectId, // Vertex AI API端点为区域专属,需要替换为你部署模型的区域 apiEndpoint: `${computeRegion}-aiplatform.googleapis.com` }); // 直接复用你原有的data数组,不需要额外嵌套结构 const instances = data; const request = { // 替换为你实际的Vertex AI端点ID,不要使用旧AutoML的model ID name: `projects/${projectId}/locations/${computeRegion}/endpoints/${ENDPOINT_ID}`, instances: instances, parameters: {feature_importance: true} }; const [result] = await ai.predict(request);
额外排查验证点
- 确认
computeRegion参数和模型部署的区域完全一致,如us-central1、asia-east1 - 确认表格类模型传入的每个实例字段名、字段类型和训练时的特征完全匹配,无缺失必填字段
- 确认你使用的模型已经部署到Vertex AI端点,替换代码中的
ENDPOINT_ID为实际端点ID
内容的提问来源于stack exchange,提问作者xfx
相关产品推荐
相关产品推荐

