AIAPIAIAPI API

Grok Imagine Image 2.0

Model ID xai/grok-imagine-image-2.0/text-to-image

概览

支持 1K、2K 分辨率以及 low、medium 质量档位的图像生成模型。

xAI · text-to-image

接口

POST /v1/images/generations/async

认证

Authorization: Bearer <AIAPIAIAPI_API_KEY>

请求体

参数类型必填可空默认值约束说明
modelstring是否-values: xai/grok-imagine-image-2.0/text-to-image用于路由请求的模型 ID。
promptstring是否--图像生成或编辑提示词,最多 8000 个字符。
resolutionstring否否`1k`values: 1k, 2k输出图像分辨率。
aspect_ratiostring否否`1:1`values: 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1输出图像比例。
ninteger否否`1`range: 1-4输出图片数量,每张图片单独计费。
qualitystring否否`medium`values: low, medium图像生成质量档位。

model

类型:string · 必填:是 · 可空:否

用于路由请求的模型 ID。

prompt

类型:string · 必填:是 · 可空:否

图像生成或编辑提示词,最多 8000 个字符。

resolution

类型:string · 必填:否 · 可空:否

输出图像分辨率。

aspect_ratio

类型:string · 必填:否 · 可空:否

输出图像比例。

n

类型:integer · 必填:否 · 可空:否

输出图片数量,每张图片单独计费。

quality

类型:string · 必填:否 · 可空:否

图像生成质量档位。

请求示例

curl --request POST \
  --url https://aiapiaiapi.com/v1/images/generations/async \
  --header 'Authorization: Bearer $AIAPIAIAPI_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "xai/grok-imagine-image-2.0/text-to-image",
      "prompt": "A cinematic camera movement through a forest",
      "resolution": "1k"
    }'

JSON

{
  "model": "xai/grok-imagine-image-2.0/text-to-image",
  "prompt": "A cinematic camera movement through a forest",
  "resolution": "1k"
}

响应

{
  "code": "success",
  "message": "",
  "data": { "task_id": "image_01K2ABC123" }
}

任务状态

使用创建响应中的 task_id 查询:

GET /v1/images/generations/async/{task_id}

{
  "code": "success",
  "message": "",
  "data": {
    "task_id": "image_01K2ABC123",
    "status": "SUCCESS",
    "progress": "100%",
    "outputs": ["https://cdn.example.com/images/image_01K2ABC123.png"],
    "start_time": 1786960805,
    "finish_time": 1786960900,
    "submit_time": 1786960800,
    "fail_reason": ""
  }
}

错误响应

参数校验错误返回 HTTP 400,并包含稳定的错误代码。

{
  "code": "unsupported_parameter",
  "message": "The parameter is not supported by this model.",
  "data": null
}

文档索引

获取完整文档索引:

https://aiapiaiapi.com/llms.txt

使用该文件发现所有可用的 API 文档。