Grok Imagine Image
Grok Imagine Image 使用 OpenAI 兼容的 Images 接口调用,适合文生图、海报、产品图和创意视觉生成。
接口地址
http
POST /v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json图片编辑 / 图生图使用:
http
POST /v1/images/edits
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-data支持模型
| 模型 | 说明 |
|---|---|
grok-imagine-image | 标准图片生成模型,适合大多数文生图场景 |
grok-imagine-image-pro | 高质量图片生成模型,适合更重视画面细节、质感和稳定性的场景 |
grok-imagine-image-edit | 图片编辑 / 图生图模型,适合基于参考图修改、重绘或风格转换 |
实际可用模型以账户权限和平台配置为准。普通出图优先使用 grok-imagine-image;需要更高质量时再使用 grok-imagine-image-pro;带参考图编辑时推荐使用 grok-imagine-image-edit。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | grok-imagine-image 或 grok-imagine-image-pro |
prompt | string | 是 | 图片生成描述 |
n | integer | 否 | 生成图片数量,默认 1,范围 1 到 10 |
size | string | 否 | 输出尺寸,默认 1024x1024 |
response_format | string | 否 | 返回格式,支持 url 或 b64_json,默认 url |
图片编辑参数
/v1/images/edits 使用 multipart/form-data,至少上传一张参考图。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 推荐使用 grok-imagine-image-edit |
image | file | 是 | 参考图文件字段。多图时可重复传 image 字段 |
prompt | string | 是 | 图片编辑描述 |
n | integer | 否 | 生成图片数量,默认 1 |
size | string | 否 | 输出尺寸,默认 1024x1024 |
response_format | string | 否 | 返回格式,支持 url 或 b64_json,默认 url |
为了兼容客户端选择模型的习惯,编辑接口也接受 grok-imagine-image、grok-imagine-image-pro、grok-imagine-image-lite 作为 model,但建议显式传 grok-imagine-image-edit。
支持尺寸
size 使用 WIDTHxHEIGHT 格式。常用取值:
size | 比例 |
|---|---|
1024x1024 | 1:1 |
1280x720 | 16:9 |
720x1280 | 9:16 |
1792x1024 | 3:2 |
1024x1792 | 2:3 |
如果不确定比例,建议先使用 1024x1024 或 720x1280。
请求示例
bash
curl -X POST https://cubicspaces.cloud/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-imagine-image",
"prompt": "A clean product photo of a transparent glass spaceship on a white studio background, soft lighting, high detail",
"size": "1024x1024",
"n": 1,
"response_format": "url"
}'高质量模型示例:
bash
curl -X POST https://cubicspaces.cloud/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-imagine-image-pro",
"prompt": "A premium watch product advertisement, black marble surface, dramatic rim light, realistic reflections, luxury editorial style",
"size": "1792x1024",
"n": 1,
"response_format": "b64_json"
}'图片编辑 / 图生图示例:
bash
curl -X POST https://cubicspaces.cloud/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=grok-imagine-image-edit" \
-F "image=@reference.png" \
-F "prompt=Keep the main subject, change the background to a bright modern studio, realistic lighting" \
-F "size=1024x1024" \
-F "response_format=url"返回格式
response_format 为 url 时:
json
{
"created": 1770000000,
"data": [
{
"url": "https://example.com/generated-image.png",
"revised_prompt": "A clean product photo..."
}
]
}response_format 为 b64_json 时:
json
{
"created": 1770000000,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"revised_prompt": "A premium watch product advertisement..."
}
]
}客户端应从 data[].url 或 data[].b64_json 读取图片结果。
SDK 示例
python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1",
)
result = client.images.generate(
model="grok-imagine-image",
prompt="A clean product photo of a tiny glass spaceship on a white background",
size="1024x1024",
n=1,
response_format="url",
)
print(result.data[0].url)python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://cubicspaces.cloud/v1",
)
result = client.images.edit(
model="grok-imagine-image-edit",
image=open("reference.png", "rb"),
prompt="Keep the main subject, change the background to a bright modern studio",
size="1024x1024",
response_format="url",
)
print(result.data[0].url)js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://cubicspaces.cloud/v1"
});
const result = await client.images.generate({
model: "grok-imagine-image",
prompt: "A clean product photo of a tiny glass spaceship on a white background",
size: "1024x1024",
n: 1,
response_format: "url"
});
console.log(result.data[0].url);js
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://cubicspaces.cloud/v1"
});
const result = await client.images.edit({
model: "grok-imagine-image-edit",
image: fs.createReadStream("reference.png"),
prompt: "Keep the main subject, change the background to a bright modern studio",
size: "1024x1024",
response_format: "url"
});
console.log(result.data[0].url);注意事项
grok-imagine-image推荐作为默认图片模型。grok-imagine-image-pro更适合产品图、广告图、细节要求高的图片。grok-imagine-image-edit用于带参考图的图片编辑,请调用/v1/images/edits并上传image文件字段。- 图片生成是非流式接口,建议客户端等待完整响应后读取结果。
- 如返回内容审核或上游失败错误,请调整提示词后重试。
- 实际可用模型和并发能力以账户权限和平台配置为准。