VibeAPIVibeAPI 开发者文档

Grok 图像

grok-imagine-image-2.0 与上一代的文生图、图生图:参数支持、画幅、出图耗时、图生图的四种传图写法与一致性

POST /v1/images/generations · POST /v1/images/edits

模型 grok-imagine-image-2.0,按张计费;上一代 grok-imagine-image-quality 同端点、同价、仍在线(官方定于 2026-11-02 退役)。 图生图不换模型:把生图模型送到 /v1/images/edits 就是改图。最后验证:2026-09-12。

基本调用

curl https://www.vibeapi.cn/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "a red apple on a wooden table, photo",
    "n": 1
  }'
from openai import OpenAI

client = OpenAI(base_url="https://www.vibeapi.cn/v1", api_key="YOUR_API_KEY")

result = client.images.generate(
    model="grok-imagine-image-2.0",
    prompt="a red apple on a wooden table, photo",
    n=1,
)
item = result.data[0]
print(item.url or "b64_json")   # 临时链接,生成后立即下载落盘
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://www.vibeapi.cn/v1", apiKey: "YOUR_API_KEY" });

const result = await client.images.generate({
  model: "grok-imagine-image-2.0",
  prompt: "a red apple on a wooden table, photo",
  n: 1,
});
const item = result.data[0];
console.log(item.url ?? "b64_json");   // 临时链接,生成后立即下载落盘

响应:

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

图片 URL 是临时地址,请在生成后立即下载落盘,不要直接交给终端用户或作为长期地址存储。

请求参数

参数支持取值 / 说明
prompt必填
n110,超出返回 400;按张计费
aspect_ratio⚠️官方取值 1:116:9 / 9:164:3 / 3:43:2 / 2:32:1 / 1:219.5:9 / 9:19.520:9 / 9:2021:95:2auto2.0 在本网关不生效,固定 1248×832;上一代生效
resolution⚠️官方 1k(默认)/ 2k2.0 在本网关不生效
quality⚠️官方仅 2.0 支持,low / medium / auto(默认;生成按 low、编辑按 medium 服务,按实际档计费)。本网关传 mediumhigh 都返回 200,尺寸不变,是否影响计费未验证
response_formaturl(默认)或 b64_json
seed固定随机种子
size⚠️不报错但无效,改用 aspect_ratio

画幅

grok-imagine-image-2.0 在本网关上只出 1248 × 832 一种尺寸aspect_ratio 七种取值、resolution: 2kquality 逐一试过, 既不报错也不生效。这与 xAI 官方文档(2.0 支持全部画幅与 2K)不一致,属本网关当前表现。

aspect_ratiogrok-imagine-image-2.0grok-imagine-image-quality
1:11248 × 8321024 × 1024
16:91248 × 8321280 × 720
9:161248 × 832864 × 1152
4:31248 × 8321152 × 864
3:21248 × 8321248 × 832
2:3 / 3:4 / 21:91248 × 832

需要竖图、方图或任何非 3:2 画幅,用 grok-imagine-image-quality。它退役后由 2.0 以 quality: low 接管——如果届时 2.0 仍不认画幅,竖图就没有替代方案了。 上一代的尺寸口径也会变(9:16 曾返回 720 × 1280,现为 864 × 1152),不要把尺寸写死在代码里,以返回图片的实际宽高为准。

出图耗时

同一句提示词、同样单张:grok-imagine-image-2.0 36–64 秒grok-imagine-image-quality5 秒。 批量出图、或接在用户交互链路上的场景,按这个差距估算超时与并发。

图生图

curl https://www.vibeapi.cn/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "change the apple color to bright green, keep everything else identical",
    "image": {"type": "image_url", "url": "https://example.com/apple.jpg"}
  }'

只收 JSON body。 OpenAI SDK 的 images.edit() 走 multipart 表单上传,打到本网关会 502 (分组 auto 下模型 grok-imagine-image-2.0 的可用渠道不存在)。改图请自行 POST JSON,图片走 URL 或 base64 内联。

image 字段接受四种写法,都能正常出图、计费一致:

"image": {"type": "image_url", "url": "https://example.com/apple.jpg"}   // 文档写法
"image": {"url": "https://example.com/apple.jpg"}                       // 省略 type
"image": "https://example.com/apple.jpg"                                // 直接给字符串
"image": {"type": "image_url", "url": "data:image/jpeg;base64,...."}     // base64 内联

官方还支持一次最多 5 张源图(输出画幅默认跟随第一张,可用 aspect_ratio 覆盖)和 Files API 的 file_id;本网关输出仍固定 1248 × 832。 计费与文生图同档,按张;耗时 2.0 约 36–58 秒,上一代约 5 秒。

一致性

当前的改图更像「重画」而不是「编辑」:同一张红苹果原图、keep everything else identical,两代模型六次输出全部是按提示词重新绘制的新场景—— 苹果确实变绿了,但桌面、背景、道具、构图都换了。

对一致性有硬要求的链路(换色、局部替换、批量套版),先用自己的图跑一遍再上线。 把必须保留的元素直接写进提示词(背景、材质、机位、光线)比只写「保留其余部分」更有效;如果目标是「同一主体动起来」, 视频接口的 image(锁首帧)与 reference_images 反而更接近「保留原图」的语义。

在线调试

填入你自己的 API Key 即可直接发起请求,参数表与响应结构由接口定义生成。

模型填 grok-imagine-image-2.0aspect_ratio 等 Grok 专有参数可在请求体里手动加。改图接口只收 JSON,通用调试器走 multipart,不适用,请直接用上文的 curl。

POST
/v1/images/generations/
AuthorizationBearer <token>

In: header

Request Body

application/json

model?string

用于图像生成的模型。dall-e-2dall-e-3gpt-image-1 之一。默认为 dall-e-2,除非使用特定于 gpt-image-1 的参数。

prompt*string

所需图像的文本描述。gpt-image-1 的最大长度为 32000 个字符,dall-e-2 的最大长度为 1000 个字符,dall-e-3 的最大长度为 4000 个字符。

n?integer

要生成的图像数量。必须介于 1 到 10 之间。对于 dall-e-3,仅支持 n=1

size?string

生成的图像的大小。对于 gpt-image-1,必须是 1024x10241536x1024(横向)、1024x1536(纵向)或自动(默认值)之一,对于 dall-e-2,必须是 256x256、``512x5121024x1024 之一,对于 dall-e-3,必须是 1024x10241792x10241024x1792 之一。

background?string

允许为生成的图像的背景设置透明度。此参数仅支持 gpt-image-1。必须是以下之一 透明不透明自动(默认值)。使用自动时,模型将自动确定图像的最佳背景。

如果是透明的,则输出格式需要支持透明度,因此应将其设置为 png(默认值)或 webp

moderation?string

控制 gpt-image-1 生成的图像的内容审核级别。必须为低, 以进行限制较少的筛选或自动(默认值)。

quality?string

将生成的图像的质量。

stream?string
style?string
user?string

Response Body

application/json

curl -X POST "https://www.vibeapi.cn/v1/images/generations/" \  -H "Content-Type: application/json" \  -d '{    "prompt": "string"  }'
{
  "created": 0,
  "data": [
    {
      "b64_json": "string",
      "url": "string"
    }
  ],
  "usage": {
    "total_tokens": 0,
    "input_tokens": 0,
    "output_tokens": 0,
    "input_tokens_details": {
      "text_tokens": 0,
      "image_tokens": 0
    }
  }
}

官方文档