> ## Documentation Index
> Fetch the complete documentation index at: https://evolink.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok Imagine Image 2.0 图像生成

> - Grok Imagine Image 2.0（grok-imagine-image-2.0）是 xAI 推出的图像生成与编辑模型，文生图与图像编辑共用同一个模型名
- 不传 `image_urls` 即为文生图；传入 `1~3` 张参考图会自动进入图像编辑模式，无需切换模型
- 异步处理模式，使用返回的任务ID  [进行查询](/cn/api-manual/task-management/get-task-detail)
- 生成的图像链接，有效期为24小时，请尽快保存



## OpenAPI

````yaml cn/api-manual/image-series/grok/grok-imagine-image-2.0-image-generate.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: grok-imagine-image-2.0接口
  description: 使用AI模型创建图像任务，支持多种模型和参数配置
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.evolink.ai
    description: 生产环境
security:
  - bearerAuth: []
tags:
  - name: 图像生成
    description: AI图像生成相关接口
paths:
  /v1/images/generations:
    post:
      tags:
        - 图像生成
      summary: grok-imagine-image-2.0接口
      description: >-
        - Grok Imagine Image 2.0（grok-imagine-image-2.0）是 xAI
        推出的图像生成与编辑模型，文生图与图像编辑共用同一个模型名

        - 不传 `image_urls` 即为文生图；传入 `1~3` 张参考图会自动进入图像编辑模式，无需切换模型

        - 异步处理模式，使用返回的任务ID 
        [进行查询](/cn/api-manual/task-management/get-task-detail)

        - 生成的图像链接，有效期为24小时，请尽快保存
      operationId: createImageGenerationGrokImagineImage2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
            examples:
              text_to_image:
                summary: 文生图（最简）
                value:
                  model: grok-imagine-image-2.0
                  prompt: 赛博朋克风格的东京街头夜景，霓虹灯倒映在湿漉漉的路面上
              text_to_image_hd:
                summary: 文生图（2K 宽屏）
                value:
                  model: grok-imagine-image-2.0
                  prompt: 黄昏时分未来都市天际线的电影级广角镜头
                  size: '16:9'
                  resolution: 2K
                  quality: medium
              image_edit:
                summary: 图像编辑（单张参考图）
                value:
                  model: grok-imagine-image-2.0
                  prompt: 把画面里的季节换成下雪的冬天
                  size: '1:1'
                  resolution: 1K
                  quality: medium
                  image_urls:
                    - https://example.com/input.png
                  callback_url: https://your-domain.com/webhook/image-done
              multi_image_edit:
                summary: 多图编辑（引用语法）
                value:
                  model: grok-imagine-image-2.0
                  prompt: 把 <IMAGE_0> 里的人物放进 <IMAGE_1> 的场景中，保持光线一致
                  size: '16:9'
                  resolution: 1K
                  quality: medium
                  image_urls:
                    - https://example.com/person.png
                    - https://example.com/scene.png
              batch_generation:
                summary: 批量生成（快速档）
                value:
                  model: grok-imagine-image-2.0
                  prompt: 像素风格的可爱机器人
                  size: '1:1'
                  resolution: 1K
                  quality: low
                  'n': 4
      responses:
        '200':
          description: 图像任务创建成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageGenerationResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: invalid_request
                  message: Invalid request parameters
                  type: invalid_request_error
        '401':
          description: 未认证、Token无效或过期
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: unauthorized
                  message: Invalid or expired token
                  type: authentication_error
        '402':
          description: 配额不足、需要充值
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: insufficient_quota
                  message: Insufficient quota. Please top up your account.
                  type: insufficient_quota
        '403':
          description: 无权限访问
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: model_access_denied
                  message: 'Token does not have access to model: grok-imagine-image-2.0'
                  type: invalid_request_error
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: rate_limit_exceeded
                  message: Too many requests, please try again later
                  type: rate_limit_error
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: internal_error
                  message: Internal server error
                  type: api_error
components:
  schemas:
    ImageGenerationRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          description: 图像生成模型名称，文生图与图像编辑共用此模型名，根据是否传入 `image_urls` 自动切换模式
          enum:
            - grok-imagine-image-2.0
          example: grok-imagine-image-2.0
        prompt:
          type: string
          description: >-
            提示词，描述想要生成的图像，或描述如何编辑传入的参考图


            **多图引用语法：**

            - 传入多张参考图时，可在提示词中用 `<IMAGE_0>`、`<IMAGE_1>`、`<IMAGE_2>` 分别引用第 1、2、3
            张参考图

            - 序号从 `0` 开始，与 `image_urls` 数组顺序一一对应

            - 示例：`把 <IMAGE_0> 中的人物放到 <IMAGE_1> 的场景里`
          example: 赛博朋克风格的东京街头夜景，霓虹灯倒映在湿漉漉的路面上
        image_urls:
          type: array
          description: >-
            参考图像URL列表，用于图生图与图像编辑功能


            **注意：**

            - 单次请求支持输入图像数量：`0~3`张（不传 = 文生图，传 `1~3` 张 = 图像编辑）

            - 仅支持公网可直接访问的 `http` / `https` 图像URL，不支持 base64 与 data URL

            - 支持的文件格式：`.jpeg`、`.jpg`、`.png`、`.webp`

            -
            图像URL需要服务器能直接查看，或者图像URL在访问时会直接进行下载（一般这种URL是以图像的扩展名作为结尾，例如`.png`、`.jpg`）

            - 图像编辑场景下，传入的参考图会产生额外费用，且每次请求只计算一次，不随 `n` 翻倍
          items:
            type: string
            format: uri
          maxItems: 3
          example:
            - https://example.com/person.png
            - https://example.com/scene.png
        size:
          type: string
          description: |-
            生成图像的宽高比，默认 `auto`

            **支持的比例（13 种）：**

            | 比例 | 说明 |
            |---|---|
            | `1:1` | 正方形 |
            | `4:3` / `3:4` | 传统横版 / 竖版 |
            | `3:2` / `2:3` | 标准横版 / 竖版 |
            | `16:9` / `9:16` | 宽屏 / 手机竖屏 |
            | `2:1` / `1:2` | 极宽横版 / 极窄竖版 |
            | `19.5:9` / `9:19.5` | 全面屏手机横版 / 竖版 |
            | `20:9` / `9:20` | 超宽屏横版 / 竖版 |

            **注意：**
            - `auto`：由模型自行决定比例，不传该参数等效于 `auto`（实际输出通常为竖版）
            - 不支持上表以外的取值
          enum:
            - '1:1'
            - '4:3'
            - '3:4'
            - '3:2'
            - '2:3'
            - '16:9'
            - '9:16'
            - '2:1'
            - '1:2'
            - 19.5:9
            - '9:19.5'
            - '20:9'
            - '9:20'
            - auto
          default: auto
          example: '16:9'
        resolution:
          type: string
          description: |-
            输出图像的像素档位，默认 `1K`，支持 `1K` 与 `2K` 两档

            **注意：**
            - 本模型不支持 `4K`
            - 取值大小写不敏感
          enum:
            - 1K
            - 2K
          default: 1K
          example: 1K
        quality:
          type: string
          description: |-
            生成质量档位，控制模型的思考深度，默认 `medium`

            | 取值 | 说明 |
            |---|---|
            | `low` | 出图更快，成本更低 |
            | `medium` | 画质与细节更好 |

            **注意：**
            - 本模型仅支持 `low` / `medium` 两档，不支持 `high` 等其他取值
            - `quality`（质量档）与 `resolution`（像素档）互相独立，可自由组合
            - 取值大小写不敏感
          enum:
            - low
            - medium
          default: medium
          example: medium
        'n':
          type: integer
          description: |-
            生成图片数量，取值范围 `1~10`，默认 `1`

            **注意：**
            - 每张图片独立计费，费用随 `n` 线性增加
            - 参考图产生的额外费用每次请求只计算一次，不随 `n` 翻倍
            - 任务完成后 `result_urls` 会返回 `n` 个互相独立的图像链接
          minimum: 1
          maximum: 10
          default: 1
          example: 1
        callback_url:
          type: string
          description: |-
            任务完成后的HTTPS回调地址

            **回调时机：**
            - 任务完成（completed）、失败（failed）或取消（cancelled）时触发
            - 在计费确认完成后发送

            **安全限制：**
            - 仅支持HTTPS协议
            - 禁止回调到内网IP地址（127.0.0.1、10.x.x.x、172.16-31.x.x、192.168.x.x等）
            - URL长度不超过`2048`字符

            **回调机制：**
            - 超时时间：`10`秒
            - 失败后最多重试`3`次（会分别在失败的`1`秒/`2`秒/`4`秒后进行重试）
            - 回调响应体格式与任务查询接口返回的格式一致
            - 回调地址若返回2xx状态码视为成功，其他状态码会触发重试
          format: uri
          example: https://your-domain.com/webhooks/image-task-completed
    ImageGenerationResponse:
      type: object
      properties:
        created:
          type: integer
          description: 任务创建时间戳
          example: 1757156493
        id:
          type: string
          description: 任务ID
          example: task-unified-1757156493-imcg5zqt
        model:
          type: string
          description: 实际使用的模型名称
          example: grok-imagine-image-2.0
        object:
          type: string
          enum:
            - image.generation.task
          description: 任务的具体类型
        progress:
          type: integer
          description: 任务进度百分比 (0-100)
          minimum: 0
          maximum: 100
          example: 0
        status:
          type: string
          description: 任务状态
          enum:
            - pending
            - processing
            - completed
            - failed
          example: pending
        task_info:
          $ref: '#/components/schemas/TaskInfo'
          description: 异步任务信息
        type:
          type: string
          enum:
            - text
            - image
            - audio
            - video
          description: 任务的输出类型
          example: image
        usage:
          $ref: '#/components/schemas/Usage'
          description: 使用量和计费信息
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: 错误代码标识符
            message:
              type: string
              description: 错误描述信息
            type:
              type: string
              description: 错误类型
    TaskInfo:
      type: object
      properties:
        can_cancel:
          type: boolean
          description: 任务是否可以取消
          example: true
        estimated_time:
          type: integer
          description: 预估完成时间（秒）
          minimum: 0
          example: 100
    Usage:
      type: object
      description: 使用量和计费信息
      properties:
        billing_rule:
          type: string
          description: 计费规则
          enum:
            - per_call
            - per_token
            - per_second
          example: per_call
        credits_reserved:
          type: number
          description: 预估消耗积分数
          minimum: 0
          example: 3.06
        user_group:
          type: string
          description: 用户组类别
          example: default
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |-
        ##所有接口均需要使用Bearer Token进行认证##

        **获取 API Key ：**

        访问 [API Key 管理页面](https://evolink.ai/dashboard/keys) 获取您的 API Key

        **使用时在请求头中添加：**
        ```
        Authorization: Bearer YOUR_API_KEY
        ```

````