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

# OpenAI Images Edits

根据一个或多个源图像和提示创建编辑或扩展后的图像。该接口与 OpenAI 官方 Images API 的 `POST /v1/images/edits` 请求和响应结构保持一致。文档翻译自 <a href="https://developers.openai.com/api/reference/resources/images/methods/edit" target="_self">官方文档</a>。",

支持模型包括 `gpt-image-2`、`gpt-image-1.5`、`gpt-image-1` 和 `dall-e-2`。

<Note>
  由于 OpenAI 图像编辑是同步响应，生成时间较长，建议使用 **[https://api.ttapi.org](https://api.ttapi.org)** 网关
</Note>


## OpenAPI

````yaml openapi/cn/openai.json POST /v1/images/edits
openapi: 3.1.0
info:
  title: Open AI API DOCS
  version: 1.0.0
  description: TTAPI Open AI API 接口服务
servers:
  - url: https://api.ttapi.io
security: []
paths:
  /v1/images/edits:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EditsRequest'
      responses:
        '200':
          description: 请求成功，返回Base64格式图像生成结果（当前仅支持该格式）
          content:
            application/json:
              schema:
                type: object
                properties:
                  created:
                    type: integer
                    description: 生成时间戳（秒）
                    example: 1713833628
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        b64_json:
                          type: string
                          description: 生成图像的Base64编码字符串
                          example: >-
                            iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSItDnaQIpKhOlkQVFIwU8CR1NZBLi4iFg8B4R33PTK77Z22p22e+628923923f/jH53eV73923/...
                      required:
                        - b64_json
                    description: 图像生成结果列表
                  usage:
                    type: object
                    description: Token使用量（Base64格式必返回）
                    properties:
                      input_tokens:
                        type: integer
                        description: 输入Token数
                        example: 50
                      input_tokens_details:
                        type: object
                        properties:
                          image_tokens:
                            type: integer
                            description: 图片Token数
                            example: 40
                          text_tokens:
                            type: integer
                            description: 文本Token数
                            example: 10
                        required:
                          - image_tokens
                          - text_tokens
                        example:
                          image_tokens: 40
                          text_tokens: 10
                      output_tokens:
                        type: integer
                        description: 输出Token数
                        example: 50
                      total_tokens:
                        type: integer
                        description: 总Token数
                        example: 100
                    required:
                      - input_tokens
                      - input_tokens_details
                      - output_tokens
                      - total_tokens
                    example:
                      input_tokens: 50
                      input_tokens_details:
                        image_tokens: 40
                        text_tokens: 10
                      output_tokens: 50
                      total_tokens: 100
                required:
                  - created
                  - data
                  - usage
                example:
                  created: 1713833628
                  data:
                    - b64_json: >-
                        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSItDnaQIpKhOlkQVFIwU8CR1NZBLi4iFg8B4R33PTK77Z22p22e+628923923f/jH53eV73923/...
                  usage:
                    total_tokens: 100
                    input_tokens: 50
                    output_tokens: 50
                    input_tokens_details:
                      text_tokens: 10
                      image_tokens: 40
        '400':
          $ref: '#/components/responses/400Response'
        '401':
          $ref: '#/components/responses/401Response'
      security:
        - CustomApiKey: []
components:
  schemas:
    EditsRequest:
      type: object
      properties:
        images:
          type: array
          items:
            type: object
            properties:
              file_id:
                type: string
                description: 已上传图片的 File API ID。
              image_url:
                type: string
                description: 完整 URL 或 base64 编码的数据 URL。
                format: uri
          description: 要编辑的输入图片引用。GPT Image 模型最多可提供 16 张图片。每个对象需提供 `file_id` 或 `image_url`。
        prompt:
          type: string
          description: 描述目标编辑结果的文本提示。GPT Image 模型最多支持 32000 个字符；`dall-e-2` 最多支持 1000 个字符。
        mask:
          type: object
          properties:
            file_id:
              type: string
              description: 已上传蒙版图片的 File API ID。
            image_url:
              type: string
              description: 完整 URL 或 base64 编码的数据 URL。
              format: uri
          description: 可选蒙版图片引用。需且仅需提供 `file_id` 或 `image_url` 之一。
        background:
          type: string
          description: >-
            设置输出图像背景的透明度。仅适用于 GPT Image 模型。可选 `transparent`、`opaque` 或
            `auto`（默认）。透明背景需要 `png` 或 `webp` 输出格式。
          enum:
            - transparent
            - opaque
            - auto
          default: auto
        input_fidelity:
          type: string
          description: 控制输入图像细节保留程度。可选 `high` 或 `low`，默认值为 `low`。仅适用于 GPT Image 模型。
          enum:
            - high
            - low
          default: low
        model:
          type: string
          description: 用于图像编辑的模型。
          enum:
            - gpt-image-2
            - gpt-image-1.5
            - gpt-image-1
        moderation:
          type: string
          description: GPT Image 模型的审核级别。可选 `low` 或 `auto`。
          enum:
            - low
            - auto
          default: auto
        'n':
          type: integer
          description: 要生成的图像数量，默认值为 1。可选范围 `1-10`。
        output_compression:
          type: integer
          description: >-
            生成图像的压缩级别（0-100）。仅适用于 `output_format` 为 `webp` 或 `jpeg` 的 GPT Image
            模型，默认值为 100。
          default: 100
        output_format:
          type: string
          description: 生成图像的返回格式。仅适用于 GPT Image 模型。可选 `png`（默认）、`jpeg` 或 `webp`。
          enum:
            - png
            - jpeg
            - webp
          default: png
        partial_images:
          type: integer
          description: 流式响应中要返回的部分图片数量，范围 `0-3`，默认值为 0。仅当 `stream` 为 `true` 时可用。
          default: 0
        quality:
          type: string
          description: |-
            图像质量。`auto`（默认）会为给定模型自动选择最佳质量。

            GPT Image 模型支持 `high`、`medium`、`low`；

            `dall-e-2` 仅支持 `standard`。
          default: auto
        response_format:
          type: string
          description: >-
            返回数据格式。仅 `dall-e-2` 支持 `url` 或 `b64_json`；URL 有效期为 60 分钟。GPT Image
            模型始终返回 `b64_json`。
          enum:
            - url
            - b64_json
        size:
          type: string
          description: |-
            图像尺寸。

            GPT Image 模型支持 `1024x1024`、`1536x1024`、`1024x1536`、`auto`（默认）；

            `dall-e-2` 支持 `256x256`、`512x512`、`1024x1024`。
          default: auto
        stream:
          type: boolean
          description: 是否以流式方式返回编辑进度。启用后可通过 `partial_images` 获取部分图片事件。
          default: false
        user:
          type: string
          description: 代表最终用户的唯一标识，可帮助 OpenAI 监测和检测滥用。
      required:
        - images
        - prompt
        - model
  responses:
    400Response:
      description: 参数错误
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: '"prompt" cannot be empty.'
              data:
                type: object
            required:
              - status
              - message
    401Response:
      description: 授权失败
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: Wrong TT-API-KEY or email is not activated.
            required:
              - status
              - message
  securitySchemes:
    CustomApiKey:
      type: apiKey
      in: header
      name: TT-API-KEY
      description: >-
        请前往 <a href='https://dashboard.ttapi.io' target='_blank'>TTAPI 控制台</a>
        获取 API 密钥。

````