Alibaba教程
如何使用 Z-Image Turbo API
分步学习 Z-Image Turbo API,支持 Node.js、Python 和 cURL:提交 文生图 任务、轮询状态或接收 Webhook,然后下载 image。下方示例费用为 $0.005。
- 端点
- 1
- 文生图
- 请求示例
- $0.005
- 文生图
- 编程语言
- 3
- Node.js · Python · cURL
- 失败任务
- $0
- 自动退款
获取 API 密钥
创建账户、充值额度,然后前往“控制台”→“API 密钥”创建密钥。将其保存为 CHEAPERGEN_API_KEY 服务器上的环境变量。每个请求都要将其作为 Bearer 令牌发送。
选择 Z-Image Turbo 端点
每种任务都有专属端点。所有端点都接受 JSON 正文,并返回可供轮询的生成任务。
| 任务 | 端点 | 必填 | 起价 |
|---|---|---|---|
| 文生图 | alibaba/z-image-turbo/text-to-image | prompt | $0.0048 每张图像 |
提交 文生图 任务
此程序会提交任务,每 3 秒轮询一次直到任务完成,然后打印 image URL。你可以替换提示词和设置以满足自己的需求。
const API = "https://cheapergen.com/api/v1";
const headers = {
Authorization: `Bearer ${process.env.CHEAPERGEN_API_KEY}`,
"Content-Type": "application/json",
};
// 1. Submit the job
let job = await fetch(`${API}/run/alibaba/z-image-turbo/text-to-image`, {
method: "POST",
headers,
body: JSON.stringify({
"prompt": "霓虹灯照亮的面馆招牌,上面写着“深夜食堂 LATE NIGHT”,雨夜街景,电影感摄影",
"aspect_ratio": "1:1",
"resolution": "1K"
}),
}).then((r) => r.json());
// 2. Poll until it finishes (or pass webhook_url and skip polling)
while (job.status === "queued" || job.status === "running") {
await new Promise((r) => setTimeout(r, 3000));
job = await fetch(`${API}/generations/${job.id}`, { headers }).then((r) => r.json());
}
console.log(job.status === "succeeded" ? job.output.images[0].url : job.error);设置关键参数
alibaba/z-image-turbo/text-to-image 的设置及其对价格的影响。
| 参数 | 类型 · 默认值 | 功能说明 | 对价格的影响 |
|---|---|---|---|
| aspect_ratio | string (enum) · 1:1 | 输出图像比例。 1:1 · 4:3 · 3:4 · 16:9 · 9:16 · 3:2 · 2:3 | 1:1: $0.0048 每张图像 |
| resolution | string (enum) · 1K | 1K ≈ 1 MP;2K ≈ 4 MP(长边最高 2048 像素)。 1K · 2K | 1K: $0.0048 每张图像 2K: $0.0108 每张图像 |
| seed | integer | 使用相同的 seed 和设置即可复现结果。留空则随机生成。 | 无 |
| enable_safety_checker | boolean · true | If set to true, the safety checker will be enabled. Content our Acceptable Use Policy prohibits stays blocked either way. | 无 |
获取结果
任务状态会从 queued 变为 running,然后进入 succeeded、failed 或 canceled。请轮询 GET /api/v1/generations/{id},或传入 webhook_url,我们会通过 POST 将结果发送给你。请下载输出并自行保存。
200 — 已成功
{
"id": "gen_8c2QmX1nq0k4",
"object": "generation",
"model": "alibaba/z-image-turbo",
"endpoint": "alibaba/z-image-turbo/text-to-image",
"mode": "text-to-image",
"status": "succeeded",
"input": {
"prompt": "霓虹灯照亮的面馆招牌,上面写着“深夜食堂 LATE NIGHT”,雨夜街景,电影感摄影",
"aspect_ratio": "1:1",
"resolution": "1K"
},
"output": {
"images": [
{
"url": "https://cdn.cheapergen.com/outputs/gen_8c2Q-0.png",
"content_type": "image/png",
"width": 2048,
"height": 2048
}
]
},
"error": null,
"cost": {
"amount_usd": 0.2255,
"currency": "usd",
"estimated": false,
"official_usd": 0.264,
"list_price_source": "official",
"list_price_label": "Official",
"saved_usd": 0.0385
},
"source": "api",
"created_at": "2026-10-15T09:21:04Z",
"started_at": "2026-10-15T09:21:06Z",
"completed_at": "2026-10-15T09:22:31Z"
}运行前查询价格
报价端点免费且无需密钥。它会根据你提交的确切输入,返回价格、官方价格 和折扣。
curl -X POST https://cheapergen.com/api/v1/quote/alibaba/z-image-turbo/text-to-image \
-H "Content-Type: application/json" \
-d '{"prompt":"霓虹灯照亮的面馆招牌,上面写着“深夜食堂 LATE NIGHT”,雨夜街景,电影感摄影","aspect_ratio":"1:1","resolution":"1K"}'| 状态 | 代码 | 说明 |
|---|---|---|
| 400 | invalid_request | 缺少参数或参数超出范围,错误信息会指出具体字段。 |
| 401 | unauthorized | API 密钥缺失、格式错误或已撤销。 |
| 402 | insufficient_balance | 余额不足,无法支付报价金额;请充值或启用自动充值。 |
| 429 | rate_limited | 请求过多或进行中的生成任务过多;请稍后重试。 |
| 502 | upstream_error | 模型服务提供商发生错误;冻结金额已退还,你可以重试。 |
| 503 | model_unavailable | 当前没有运行正常的路由,请稍后重试或选择其他模型。 |
常见问题
Z-Image Turbo API 常见问题
不需要。API 使用标准 HTTPS 和 JSON,因此本页的 Node.js(fetch)和 Python(requests)示例都是完整程序。任何能够发送 HTTP 请求的语言都可以调用。
可以。在请求正文中添加 "webhook_url",生成任务完成后我们会向该地址 POST 结果,并使用 CheaperGen-Signature 标头进行签名(对时间戳和原始请求正文计算 HMAC-SHA256)。也可以轮询 GET /api/v1/generations/{id}。
文生图 起价为 $0.0048 每张图像;本页的请求示例费用为 $0.005,比 官方价格 低 69%。生成失败会自动退款。
