Skip to content

grok-imagine-image 接口文档(文生图)

支持的模型

  • grok-imagine-image

1.图片生成

  • n: 生成图片的数量

  • aspect_ratio:

RatioUse case
1:1Social media, thumbnails
16:9 / 9:16Widescreen, mobile, stories
4:3 / 3:4Presentations, portraits
3:2 / 2:3Photography
2:1 / 1:2Banners, headers
19.5:9 / 9:19.5Modern smartphone displays
20:9 / 9:20Ultra-wide displays
autoModel auto-selects the best ratio for the prompt
  • resolution: 1k / 2k

  • response_format: url / b64_json

示例

请求

bash
curl "https://apiok.cc/v1/images/generations" \
-H "Authorization: Bearer $APIKEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "grok-imagine-image",
   "response_format": "url",
   "prompt": "A cute orange cat wearing sunglasses",
   "n": 2,
   "aspect_ratio": "16:9",
   "resolution": "1k"
}'

返回

json
{
    "data": [
        {
            "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-bbe3d66f-deb4-9892-b2c8-f2174592d83c-256dbf82.jpeg",
            "mime_type": "image/jpeg"
        },
        {
            "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-bbe3d66f-deb4-9892-b2c8-f2174592d83c-2fad2002.jpeg",
            "mime_type": "image/jpeg"
        }
    ],
    "usage": {
        "cost_in_usd_ticks": 400000000
    }
}

2. 图片编辑

在图片生成的基础上增加了image_url参数

  • image_url: url or data:image/jpeg;base64

示例

请求

bash
curl 'https://apiok.cc/v1/images/edits' \
-H "Authorization: Bearer $APIKEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "grok-imagine-image",
    "prompt": "A cute orange cat with colorfull hat ",
    "image_url":  "https://xxx.jpeg"
}'

返回

json
{
    "data": [
        {
            "url": "https://xxx.jpeg",
            "mime_type": "image/jpeg"
        }
    ],
    "usage": {
        "cost_in_usd_ticks": 200000000
    }
}

3. 多图编辑

在图片生成的基础上增加了image_urls参数

  • image_urls: url or data:image/jpeg;base64 最多支持3张

示例

请求

bash
curl 'https://apiok.cc/v1/images/edits' \
-H "Authorization: Bearer $APIKEY" \
-H 'Content-Type: application/json' \
-d '{
    "model": "grok-imagine-image",
    "prompt": "A cute orange cat with colorfull hat ",
    "image_urls": [
        "https://xxx1.jpeg",
        "https://xxx2.jpeg"
    ]
}'

返回

json
{
    "data": [
        {
            "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-e7c049ec-786e-9012-b328-1e8ca639137e-e63cc3d5.jpeg",
            "mime_type": "image/jpeg"
        }
    ],
    "usage": {
        "cost_in_usd_ticks": 200000000
    }
}