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

# 图片生成

<Note>
  注：你可以在模型广场筛选查看[系统支持的画图模型列表](https://geekai.co/models)，画图模型基础请求/响应参数结构兼容 [OpenAI](https://platform.openai.com/docs/api-reference/images)，同时扩展了一些新的参数来适配其他模型的功能，切换模型时只需修改对应的模型名称即可，若模型请求/响应参数和 OpenAI 不一致，极客智坊底层会自动转换对齐。
  响应数据格式和 OpenAI 完全兼容。
</Note>

不同AI平台的画图模型支持的尺寸不一样，具体支持的尺寸请参考下面的表格：

<div style={{ width: '100%', overflowX: 'auto' }}>
  <table style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed' }}>
    <thead>
      <tr>
        <th style={{ border: '1px solid #ccc', padding: '10px'}}>平台</th>
        <th style={{ border: '1px solid #ccc', padding: '10px'}}>模型</th>
        <th style={{ border: '1px solid #ccc', padding: '10px', width: '60%'}}>支持的尺寸</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>OpenAI</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>GPT-Image系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          GPT-Image-2开始支持指定范围内的任意尺寸，其他版本：1024x1024,1024x1536,1536x1024,auto，默认是auto
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Google</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Imagen系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          无尺寸配置，支持宽高比：1:1、3:4、4:3、9:16、16:9，
          默认1:1，HTTP调用只支持默认值。
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Google</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Banana系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          无尺寸配置，支持通过`size`字段传递分辨率：1k、2k、4k，支持宽高比：1:1、2:3、3:2、3:4、4:3、4:5、5:4、9:16、16:9，21:9，
          默认1:1。
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>智谱清言</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>CogView系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          1024x1024,768x1344,864x1152,1344x768,
          1152x864,1440x720,720x1440，默认是1024x1024
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>阿里巴巴</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>通义万相系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          图像宽高边长的像素范围为：\[768, 1440]，单位像素。
          可任意组合以设置不同的图像分辨率，最高可达200万像素。
          默认值：1024\*1024
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>可灵AI</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>kling系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          无尺寸配置，支持宽高比：16:9、9:16、1:1、4:3、3:4、3:2、2:3，
          默认1:1
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>字节跳动</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>即梦系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          支持宽高比及对应尺寸：512x512（默认值）、512x384、384x512、512x341、
          341x512、512x288、288x512
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>字节跳动</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Seeddream系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          支持宽高比及对应尺寸：[点此查看](https://docs.geekai.co/cn/docs/image/bytedance/doubao-seedream-4.0#%E6%A8%A1%E5%9E%8B%E5%8F%82%E6%95%B0)
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Stability</td>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Stable Image系列</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          图像宽高边长的像素范围为：\[64, 16384]，单位像素。
          可任意组合以设置不同的图像分辨率，总像素数至少需要达到 4096 像素。
        </td>
      </tr>

      <tr>
        <td style={{ border: '1px solid #ccc', padding: '8px' }}>Midjourney</td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          *
        </td>

        <td style={{ border: '1px solid #ccc', padding: '8px' }}>
          *
        </td>
      </tr>
    </tbody>
  </table>
</div>

画图模型 API 调用示例可以参考这里：[生成图像](https://docs.geekai.co/cn/docs/image/model)。

### 请求/响应参数明细


## OpenAPI

````yaml openapi.yaml POST /images/generations
openapi: 3.1.0
info:
  title: 极客智坊 API文档
  description: 极客智坊 API 消息接口规范文档
  version: 1.0.0
servers:
  - url: https://geekai.co/api/v1
    description: 国内代理入口
  - url: https://geekai.dev/api/v1
    description: 海外代理入口
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /images/generations:
    post:
      tags:
        - Image
      summary: 图片生成接口
      description: 基于文本提示生成AI图片的接口，支持多种图片生成模型和参数配置
      operationId: createImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - prompt
              properties:
                model:
                  type: string
                  description: 图片生成模型
                  example: gpt-image-1
                prompt:
                  type: string
                  description: 文本提示
                  example: 画一只可爱的小猫
                negative_prompt:
                  type: string
                  description: 反向提示词，用来描述不希望在画面中看到的内容，可以对画面进行限制
                image:
                  oneOf:
                    - type: string
                      description: 单张图片URL/Base64编码数据，仅支持图生图模型支持该配置
                    - type: array
                      description: 多张图片URL/Base64编码数组列表，仅支持图生图模型支持该配置
                      items:
                        type: string
                strength:
                  type: number
                  description: 以图生图引用图片的影响强度，取值范围[0, 1]，默认0.5
                  default: 0.5
                size:
                  type: string
                  description: 图片尺寸，不同模型设置不同，详见模型尺寸表
                  default: 1024x1024
                aspect_ratio:
                  type: string
                  description: 图片宽高比，不同模型设置不同，详见模型尺寸表
                  default: '1:1'
                'n':
                  type: integer
                  description: 图片数量，默认为1
                  default: 1
                quality:
                  type: string
                  description: >-
                    图片质量，可灵AI支持 std、pro 两个配置，OpenAI/智谱清言支持 standard、hd 两个配置，GPT
                    Image支持 auto/low/medium/high 四个配置项
                  default: medium
                style_preset:
                  type: string
                  description: 风格预设，目前仅 stable image 支持该配置
                  example: 3d-model
                response_format:
                  type: string
                  description: 图片响应格式，支持 url/b64_json 两种格式，默认为url
                  enum:
                    - url
                    - b64_json
                  default: url
                output_format:
                  type: string
                  description: 图片输出格式，支持 png/jpg/webp 三种格式，默认为png
                  enum:
                    - png
                    - jpg
                    - webp
                  default: png
                mask:
                  type: string
                  description: 图片遮罩，支持图片URL/Base64编码数据
                watermark:
                  type: boolean
                  description: 是否添加AI生成水印，默认为false，仅部分模型支持
                  default: false
                background:
                  type: string
                  description: 背景透明度，目前仅 gpt-image-1 支持该配置
                  enum:
                    - transparent
                    - opaque
                    - auto
                  default: auto
                extra_body:
                  type: object
                  description: 额外参数配置项，以适配不同画图模型的多样化配置
                  properties:
                    sequential_image_generation:
                      type: string
                      description: 控制是否关闭组图功能，仅 doubao-seedream-4.0 支持该参数，默认disabled
                      enum:
                        - auto
                        - disabled
                      default: disabled
                    sequential_image_generation_options:
                      type: object
                      description: >-
                        组图功能的配置，仅当 sequential_image_generation 为 auto 时生效。仅
                        doubao-seedream-4.0 支持该参数。
                      properties:
                        max_images:
                          type: integer
                          description: 组图张数，取值范围1-15，默认15
                          default: 15
                async:
                  type: boolean
                  description: 是否异步生成，默认false，即同步等待图片生成成功后返回生成结果，如果异步需要通过调用图片获取接口获取生成结果
                  default: false
                retries:
                  type: integer
                  description: 自动重试次数，默认0，表示失败不重试
                  default: 0
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                required:
                  - created
                  - data
                properties:
                  task_id:
                    type: string
                    description: 图片生成任务ID
                    format: uuid
                  task_status:
                    type: string
                    description: 任务状态
                    enum:
                      - pending
                      - running
                      - succeed
                      - failed
                    example: running
                  created:
                    type: integer
                    description: 创建时间戳
                    format: unix-timestamp
                  data:
                    type: array
                    description: 生成的图片列表(仅在task_status=succeed时返回)
                    items:
                      type: object
                      required:
                        - url
                      properties:
                        url:
                          type: string
                          description: 图片URL
                          format: uri
                        b64_json:
                          type: string
                          description: 图片Base64编码数据
                          format: base64
                        revised_prompt:
                          type: string
                          description: 优化后的提示文本
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          description: 提示文本过长
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/StandardError'
components:
  responses:
    ValidationError:
      description: 参数验证错误
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: validation_error
              message:
                type: string
                example: 参数验证失败
              details:
                type: object
                additionalProperties:
                  type: string
                example:
                  field: 错误描述
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: unauthorized
              message:
                type: string
                example: Invalid API key or token
    StandardError:
      description: 标准错误响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: 错误代码
          example: invalid_request
        message:
          type: string
          description: 错误信息描述
          example: 请求参数不合法
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: API认证token
    apiKeyAuth:
      type: apiKey
      in: header
      name: GeekAI-API-Key
      description: API密钥认证

````