promptstring必填
Text description of the desired image.
xai/grok-imagine-image/2.0/text-to-imageGrok Imagine Image 2.0 by xAI - generate stunning images from text prompts with state-of-the-art AI. Supports multiple aspect ratios, styles, and high-resolution output for creative and commercial use.
试用该模型
选择一个示例,将其输入和结果加载到 playground 中。
{
"prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific"
}人类偏好
基于盲测两两对比投票的 Elo 评分,与其他图像和视频模型进行比较。
文生图 arena:在不看到模型名称的情况下,用户从同一提示词生成的两张图片中选出更优的一张。
Grok Imagine Image 2.0 generates images at two quality levels and 1K or 2K.
| Field | Type | Default | Notes |
|---|---|---|---|
prompt | string, required | — | Up to 8,000 characters. |
aspect_ratio | 21:9 / 16:9 / 3:2 / 4:3 / 5:4 / 1:1 / 4:5 / 3:4 / 2:3 / 9:16 | — | Output shape. |
resolution | 1k / 2k | 1k | Sets the per-image rate. |
output_format | jpeg / png | jpeg | Output file format. |
quality | low / medium | medium | Sets the per-image rate. |
Per image: $0.04 (low) or $0.06 (medium) at 1K; $0.06 or $0.08 at 2K.
| Request | 1k | 2k |
|---|---|---|
| low | $0.04 | $0.06 |
| medium | $0.06 | $0.08 |
Failed runs are not charged.
Other Grok Imagine Image endpoints: xai/grok-imagine-image/quality, xai/grok-imagine-image/quality/edit, xai/grok-imagine-image/edit, xai/grok-imagine-image/2.0/edit.
开始构建
通过 SandBase Unified Run API 提交此模型。
# The quoted heredoc keeps Unicode and shell metacharacters unchanged.
result=$(curl --fail-with-body --silent \
-X POST "https://api.sandbase.ai/v1/run" \
-H "Authorization: Bearer $SANDBASE_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<'SANDBASE_JSON'
{
"model": "xai/grok-imagine-image/2.0/text-to-image",
"prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific",
"quality": "medium",
"resolution": "1k",
"output_format": "jpeg"
}
SANDBASE_JSON
)
run_id=$(printf '%s' "$result" | jq -r .id)
for attempt in $(seq 1 120); do
status=$(printf '%s' "$result" | jq -r .status)
case "$status" in completed|failed|timeout) break ;; esac
sleep 2
result=$(curl --fail-with-body --silent \
-H "Authorization: Bearer $SANDBASE_API_KEY" \
"https://api.sandbase.ai/v1/run/$run_id")
done
status=$(printf '%s' "$result" | jq -r .status)
[ "$status" = completed ] || { echo "Generation ended: $status" >&2; exit 1; }
printf '%s\n' "$result"创建一个 SandBase API 密钥,并将其设置到服务器环境中。所有请求都使用 Bearer 身份验证。
export SANDBASE_API_KEY="YOUR_API_KEY"请将密钥保存在服务器端。不要在浏览器代码中暴露它,也不要提交到仓库。
使用此模型 ID 及其输入向 /v1/run 发送 POST 请求。上方的请求示例包含提交和轮询。
使用返回的运行 ID 轮询,直到状态为 completed、failed 或 timeout。仅在 completed 后读取输出。
curl "https://api.sandbase.ai/v1/run/$RUN_ID" \
-H "Authorization: Bearer $SANDBASE_API_KEY"在模型的 image、video 或 audio 字段中传入一个可公开访问的文件 URL。支持的格式和限制显示在每个 Playground 输入项旁边。
在 Playground 中支持的图片字段上使用上传或替换控件。视频 URL 字段接受托管的 driving video;这并不表示支持视频上传。
promptstring必填Text description of the desired image.
qualitystringQuality level of the generated image.
默认值:"medium"
可选值:"low", "medium"
resolutionstringResolution of the generated image. `1k` for standard resolution, `2k` for high resolution.
默认值:"1k"
可选值:"1k", "2k"
aspect_ratiostringThe aspect ratio of the generated image.
可选值:"21:9", "16:9", "3:2", "4:3", "5:4", "1:1", "4:5", "3:4", "2:3", "9:16"
output_formatstringThe format of the generated image.
默认值:"jpeg"
可选值:"jpeg", "png"
{
"model": "xai/grok-imagine-image/2.0/text-to-image",
"prompt": "Abstract human silhouette, golden particles ready to burst outward representing joy, data visualization style, emotional expression through particles, artistic scientific",
"quality": "medium",
"resolution": "1k",
"output_format": "jpeg"
}已完成的运行会在输出中展示结果。以下内容是该模型保存的示例,而不是新的生成结果。
[
{
"source": "xAI schema mirror",
"source_url": "https://docs.x.ai/",
"url": "https://static.sandbase.ai/examples/133eedb7-0edd-49be-8452-894e6242d034/output/584e0e98-2988-4b27-9ce0-d87ba6bf1b4b.jpg"
}
]