Grok Imagine Image 2.0 API
1K–2K 生图与多图编辑 · 单次最高 10 张
POST /v1/images/generations · https://api.callmodels.dev/v1/images/generations
规格与计费
固定按张计费(每张实际交付图像 3.75–7.5 积分 × n);传入 1–3 张参考图时每张加收 +0.9375 积分(当次请求计一次,不随 n 倍增)。
| 规格说明 | 单价 (USD) | 积分 ($1 = 100) | $10 约可生成 |
|---|---|---|---|
| 1K · low 画质 · 每张输出图像 | $0.0375 | 3.750000 积分 | 约 266 张 |
| 1K · medium 画质(默认)· 每张输出图像 | $0.0563 | 5.625000 积分 | 约 177 张 |
| 2K · low 画质 · 每张输出图像 | $0.0563 | 5.625000 积分 | 约 177 张 |
| 2K · medium 画质 · 每张输出图像 | $0.0750 | 7.500000 积分 | 约 133 张 |
| 参考图输入费(image_urls 每传入 1 张,上限 3 张,当次请求计一次) | +$0.00938 | +0.937500 积分 / 张 | 按参考张数计 1 次 |
请求参数
本地参考素材:先调
POST /v1/files/uploads(0 积分)换取 24 小时签名链接。| 参数名 | 类型与默认 | 说明与约束 |
|---|---|---|
Authorization必填Header | string | Bearer sk-... 格式的服务端 API Key。 |
Idempotency-Key可选Header | string默认: recommended | 1 至 255 位 ASCII 字符;24 小时内及任务完成前防止重复提交与重复扣费。 |
model必填 | "grok-imagine-image-2.0" | xAI Grok Imagine Image 2.0 的稳定公开模型 ID。 |
prompt必填 | string | 1 至 5,000 字符的图像生成或编辑提示词。 |
resolution可选 | "1K" | "2K"默认: "1K" | 输出分辨率档位(支持 1K 与 2K)。 |
quality可选 | "low" | "medium"默认: "medium" | 渲染质量档位(low 或默认的 medium)。 |
size可选 | "auto" | 13 aspect ratios默认: "auto" | 支持 "auto" 及 13 种画幅比例(含移动端全面屏 19.5:9 / 20:9)。 |
n可选 | integer (1..10)默认: 1 | 单次并发生成张数(1–10 张),结算时严格按实际成功交付张数计费。 |
image_urls可选 | string[] (1..3)默认: omitted | 可选 1–3 张 HTTPS 参考图链接(每张参考图加收 0.9375 积分,当次请求计一次)。 |
代码示例
# Set CALLMODELS_OPERATION_ID once per job and keep it for retries.
: "${CALLMODELS_OPERATION_ID:?Set a stable job ID}"
curl --silent --show-error --fail-with-body --max-time 15 "https://api.callmodels.dev/v1/images/generations" \
-H "Authorization: Bearer $CALLMODELS_API_KEY" \
-H "Idempotency-Key: $CALLMODELS_OPERATION_ID" \
-H "Content-Type: application/json" \
--data-binary '{
"model": "grok-imagine-image-2.0",
"prompt": "Brushed silver grand tourer coupe parked on a misty coastal cliff road at dawn",
"size": "16:9",
"resolution": "1K",
"quality": "medium"
}'
# Set TASK_ID to the id from the response, then poll until terminal.
if [ -n "${TASK_ID:-}" ]; then
curl --silent --show-error --fail-with-body --max-time 15 "https://api.callmodels.dev/v1/tasks/$TASK_ID" \
-H "Authorization: Bearer $CALLMODELS_API_KEY"
fi响应示例
completed 时读取 results[0].url(30 天免鉴权直链)与 usage.cost_credits 实扣积分。
HTTP/1.1 202 Accepted
X-Request-Id: req_example
Cache-Control: no-store
{
"id": "task_01e561ba-859e-47fe-be79-60bc6f1d6499",
"model": "grok-imagine-image-2.0",
"object": "image.generation.task",
"created_at": "2026-11-21T00:00:00.000Z",
"status": "pending"
}错误码与计费保护
| 状态 / 错误码 | 原因与处理 | 计费 |
|---|---|---|
400 invalid_parameter400 model_not_found | 使用该端点支持的公开模型 ID 与参数。修正 JSON 后再提交。 | 本次拒绝扣 0 积分 |
| 401 invalid_api_key | 检查服务端 Bearer Key 的格式、到期和撤销状态。 | 本次拒绝扣 0 积分 |
402 insufficient_balance402 key_quota_exceeded | 用 GET /v1/credits 查询账户可用积分与密钥累计、每日限额。 | 本次拒绝扣 0 积分 |
403 model_access_denied403 account_disabled | 检查模型白名单与账户状态。 | 本次拒绝扣 0 积分 |
| 404 not_found | 检查任务 ID 或原始 Idempotency-Key,并确认使用提交任务的账户。 | 本次拒绝扣 0 积分 |
| 409 idempotency_key_conflict | 同一任务使用原始 JSON。创建新任务时才分配新的幂等键。 | 本次拒绝扣 0 积分 |
413 body_too_large415 unsupported_media_type | 发送 application/json,请求体最多 128 KiB。 | 本次拒绝扣 0 积分 |
500 internal_error503 service_unavailable503 model_unavailable | 遇到超时或暂时性错误,请查询原任务,重试时保留原幂等键与请求体。 | 以任务记录为准 |
Task: invalid_mediaTask: content_moderationTask: invalid_inputTask: submission_rejected | 任务已终态结束(retryable: false),预占积分已全额释放。请先修正提示词、参数或参考素材(格式、尺寸、长宽比、时长或外链可访问性),再使用新幂等键新建任务。 | 实扣 0 积分 |
Task: service_busyTask: timeoutTask: delivery_failedTask: submission_unknownTask: upstream_failed | 任务因算力临时繁忙、超时或交付校验异常结束(retryable: true),预占积分已全额释放。可等待片刻后使用新幂等键重新发起。 | 实扣 0 积分 |