ninteger
Images to generate (1-10). Each image is billed.
默认值:1
最小值:1
最大值:10
x-ai/grok-imagine-imageGrok Imagine Image by xAI generates images from a prompt or edits up to 5 input images, at $0.02 per image. Call it from this page, through /v1/run, or with the xAI Images API at SandBase.
试用该模型
PNG, JPEG, WebP, or GIF · 20 MiB maximum each · up to 5
您的输出将显示在这里
完成输入,然后点击运行。
Grok Imagine Image is xAI's previous image model, at $0.02 per image. It generates images from a prompt, or edits and combines up to 5 input images. For better quality and 1.5K output, use Grok Imagine Image 2.0.
Use the form on this page, call x-ai/ through /v1/run, or call the xAI API below with model: grok-imagine-image. Both bill the same as xAI.
| Field | Type | Default | Notes |
|---|---|---|---|
prompt | string, required | — | What to draw, or what to change. |
images | image list, up to 5 | — | Images to edit or combine. Leave empty to generate. |
n | integer 1–10 | 1 | Images to generate. |
aspect_ratio | auto1:116:99:164:33:43:22:32:11:219.5:99:19.520:99:2021:95:2 | auto | Output shape. |
resolution | 1k / 2k | 1k | Output size; the price is the same. |
SandBase implements xAI's Images and Videos API under https://api.sandbase.ai/grok/v1. Requests and responses match xAI's API reference field by field, so the xAI SDK or any OpenAI-style HTTP client works after you change the base URL and use your SandBase API key.
| xAI | SandBase | |
|---|---|---|
| Base URL | https://api.x.ai/v1 | https://api.sandbase.ai/grok/v1 |
| Generate | POST /images/generations | POST /images/generations |
| Edit | POST /images/edits | POST /images/edits |
| Deferred result | GET /images/{request_id} | GET /images/{request_id} |
model | grok-imagine-image | grok-imagine-image |
curl https://api.sandbase.ai/grok/v1/images/edits \
-H "Authorization: Bearer $SANDBASE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image",
"prompt": "Turn this photo into a watercolor painting",
"image": {"url": "https://example.com/photo.jpg"},
"response_format": "url"
}'
quality and resolution: 1.5k are only available on Grok Imagine Image 2.0 and return 400 here, as they do at xAI.
$0.02 per image. Editing adds $0.002 per input image. Failed runs are not billed.
| Request | Price |
|---|---|
| Generate 1 image | $0.02 |
| Generate 4 images | $0.08 |
| Edit 1 input image | $0.022 |
开始构建
通过 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": "x-ai/grok-imagine-image",
"n": 1,
"prompt": "A red fox standing in fresh snow at sunrise, soft golden light, shallow depth of field",
"resolution": "1k",
"aspect_ratio": "auto"
}
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;这并不表示支持视频上传。
nintegerImages to generate (1-10). Each image is billed.
默认值:1
最小值:1
最大值:10
imagesarrayUp to 5 images to edit or combine (upload or public HTTPS URL). Leave empty to generate from the prompt.
promptstring必填Describe the image, or the change to make to the input images.
resolutionstringOutput size: 1k or 2k.
默认值:"1k"
可选值:"1k", "2k"
aspect_ratiostringOutput aspect ratio. auto picks one from the prompt or the first input image.
默认值:"auto"
可选值:"auto", "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "2:1", "1:2", "19.5:9", "9:19.5", "20:9", "9:20", "21:9", "5:2"
{
"model": "x-ai/grok-imagine-image",
"n": 1,
"prompt": "A red fox standing in fresh snow at sunrise, soft golden light, shallow depth of field",
"resolution": "1k",
"aspect_ratio": "auto"
}已完成的运行会在输出中展示结果。以下内容是该模型保存的示例,而不是新的生成结果。
尚未发布示例输出。请在运行完成后使用 Playground → Result → JSON 查看响应。