与 URL 方式相同,仅 response_format 改为 "b64_json":data[i].b64_json 返回 base64 编码的图片数据,可直接用于 或解码保存为文件。已实测通过(在 2k 分辨率测试中以 b64_json 成功拿到 base64 数据)。大陆网络推荐此方式,避开 imgen.x.ai 链接无法直连的问题。
curl --location --globoff '{{baseUrl}}/v1/images/generations' \
--header 'Accept: application/json' \
--header 'Authorization: {{YOUR API KEY}}' \
--header 'Content-Type: application/json' \
--data '{
"model": "grok-imagine-image-2.0",
"prompt": "a cute orange cat sitting on a windowsill, sunny day",
"n": 1,
"response_format": "b64_json"
}'{
"data": [
{
"b64_json": "/9j/4AAQSkZJRg...(base64 图片数据)"
}
],
"usage": {
"cost_in_usd_ticks": 400000000
}
}