ppio-gpus SDK 调用 Async Serverless Endpoint,以及如何自定义 worker handler。
1. 安装 SDK
在客户端环境或 worker 运行环境中安装 SDK:Bash
2. 使用 SDK 提交任务
ppio-gpus SDK 默认请求地址为 https://async-public.serverless.ppinfra.com/v1。调用时只需要设置 API Key,并使用 Endpoint 名称创建客户端。这里的 API Key 用于客户端提交、查询、取消任务,不用于 worker 拉取任务或回传结果。
Python
3. ComfyUI 任务示例
对于image.ppinfra.com/prod-gpucloudpublic/comfyui-worker:v0.0.1,任务输入需要包含 ComfyUI workflow。下面是一个最小示例:
Python
4. 自定义 Handler
worker 侧使用ppio_gpus.start({"handler": handler}) 启动任务循环。平台会把任务内容传入 handler(job):
job["id"]:当前 job idjob["input"]:提交任务时的 input 内容- handler 返回的内容会作为任务 output
- 如果返回 dict 中包含
error字段,任务会被标记为失败
Python
5. 返回图片或文件
Async Serverless Endpoint 的status 接口返回结果有大小限制。图片、视频等大文件建议先上传到对象存储,再在 output 中返回 URL。
在 Endpoint 环境变量中配置对象存储:
Bash
Python
6. 常见问题
handler 返回什么会被认为失败?
如果 handler 返回 dict 且包含error 字段,任务会被标记为失败:
Python