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

如何通过Python API访问旧版AI Platform模型而非Vertex AI模型

google-cloud-aiplatform Python SDK是专门为Vertex AI服务设计的官方客户端,和旧版Google AI Platform(即执行gcloud ai-platform系列命令对应的传统机器学习平台服务)是两套独立的服务接口,因此调用aiplatform.Model.list()只会返回Vertex AI下的模型资源,无法获取旧版AI Platform的模型列表。

旧版AI Platform模型列表的Python调用方法

旧版AI Platform没有提供独立的高层封装SDK,可通过Google通用API客户端构建ML Engine v1服务实例调用对应接口,返回结果和gcloud ai-platform models list完全一致。

  1. 安装依赖包
pip install google-api-python-client google-auth
  1. 调用示例代码
from googleapiclient.discovery import build
from google.auth import default

# 自动加载当前环境的认证凭证,与本地gcloud命令行的认证状态互通
creds, project_id = default()
# 初始化旧版AI Platform(ML Engine)服务客户端
ml_service = build("ml", "v1", credentials=creds)

# 发起模型列表查询请求
response = ml_service.projects().models().list(parent=f"projects/{project_id}").execute()
model_list = response.get("models", [])

# 遍历输出模型信息
for model in model_list:
    print(f"模型名:{model.get('name')},默认版本:{model.get('defaultVersion', {}).get('name', '未配置')}")
注意事项
  • 上述代码调用的是旧版AI Platform的官方v1生产接口,和gcloud ai-platform命令行的底层调用逻辑完全一致,返回结果不会混入Vertex AI的资源。
  • Google目前已经停止对旧版AI Platform的新功能迭代,所有平台新特性仅在Vertex AI上提供,官方推荐将存量模型逐步迁移到Vertex AI,迁移完成后即可直接使用google-cloud-aiplatform SDK操作所有平台资源。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.30 00:54:32