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

# 编辑图片

> 编辑或扩展一张或多张上传的图片（multipart/form-data，字段 `image` 或 `image[]`，可选 `mask`）。计费、尺寸档位、`n`、`b64_json` 输出与长耗时行为同「生成图片」。整个请求最大 20 MiB。



## OpenAPI

````yaml /openapi.cn.json post /v1/images/edits
openapi: 3.1.0
info:
  title: OmniRelay API
  version: 1.0.0
  description: 面向已核验真实文本模型的兼容 OpenAI 网关。访问按工作空间开通，使用自己的模型列表查询能力与客户价格。
servers:
  - url: https://api.omnirelay.ai
security:
  - bearerAuth: []
tags:
  - name: 服务
  - name: 模型
  - name: 对话
  - name: 管理 API
  - name: 响应
  - name: 向量
  - name: 图片
  - name: 视频
paths:
  /v1/images/edits:
    post:
      tags:
        - 图片
      summary: 编辑图片
      description: >-
        编辑或扩展一张或多张上传的图片（multipart/form-data，字段 `image` 或 `image[]`，可选
        `mask`）。计费、尺寸档位、`n`、`b64_json` 输出与长耗时行为同「生成图片」。整个请求最大 20 MiB。
      operationId: editImage
      parameters:
        - name: X-Gateway-Tags
          in: header
          required: false
          description: >-
            本次调用的标签，以逗号分隔的 `key=value`，例如 `client=acme,env=prod`。与 API Key
            的默认标签合并；同名 key 以请求体 `tags` 字段为准。`X-OmniRelay-Tags` 是同一个请求头的旧名，继续接受。
          schema:
            type: string
          example: client=acme,env=prod
        - name: X-Gateway-Metadata
          in: header
          required: false
          description: >-
            传 `enabled` 时，响应会附带
            `gateway_metadata`，说明网关为本次调用做出的决定。其他值或不传此头，响应保持不变。`X-OmniRelay-Metadata`
            是同一个请求头的旧名，继续接受。
          schema:
            type: string
            enum:
              - enabled
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImagesEditRequest'
      responses:
        '200':
          description: 图片及已结算的用量与费用。
          headers:
            X-Request-ID:
              description: 用于诊断的 OmniRelay 请求 ID，与模型服务方追踪、响应头及响应体 ID 分别记录。
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImagesResponse'
        '400':
          description: >-
            JSON、表单或参数不合法（`response_format` 不是 `b64_json`、`stream`、无法识别的
            `size`、`n` 超过模型上限），或模型拒绝了某个参数。不扣费。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: unsupported_parameter
                request_id: 2f6c1d0e9a
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: >-
            inference_budget_or_access_denied：钱包、Key 或平台预算不足以覆盖所请求档位的 n
            张图片；member_budget_exceeded：超出成员额度。发往模型服务方前即被拒绝。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: inference_budget_or_access_denied
                request_id: 2f6c1d0e9a
        '403':
          description: '`model_not_allowed`：该 API Key 仅限其他模型；`ip_not_allowed`。不扣费。'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: model_not_allowed
                request_id: 2f6c1d0e9a
        '404':
          description: '`model_unavailable`：该模型不是本工作区可用的图片模型。'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: model_unavailable
                request_id: 2f6c1d0e9a
        '413':
          description: payload_too_large：请求体超过 20 MiB。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: payload_too_large
                request_id: 2f6c1d0e9a
        '429':
          description: 触发速率或并发限制。不扣费；请在 Retry-After 秒后重试。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: rate_limited
                request_id: 2f6c1d0e9a
        '502':
          description: >-
            `upstream_rejected`：服务方拒绝了调用，不扣费。`image_call_held`：连接中断、服务方服务器错误或返回无法核验；该调用进入人工复核，仅当服务方确实生成了图片时才扣费。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: image_call_held
                request_id: 2f6c1d0e9a
        '503':
          description: 实时访问尚未就绪或已暂停。未发送，不扣费。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: live_provider_unavailable
                request_id: 2f6c1d0e9a
        '504':
          description: '`image_call_held`：调用未能按时完成。该调用进入人工复核，仅当服务方确实生成了图片时才扣费。'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: image_call_held
                request_id: 2f6c1d0e9a
components:
  schemas:
    ImagesEditRequest:
      type: object
      required:
        - model
        - prompt
        - image
      description: >-
        其他字段（`background`、`output_format`、`output_compression`、`moderation`、`user`）原样传给模型，由模型决定是否接受。
      properties:
        model:
          type: string
          description: 图片模型 ID，例如 `gpt-image-2`。
          example: gpt-image-2
        prompt:
          type: string
          maxLength: 32000
          description: 图片的文字描述，最多 32000 个字符。
        'n':
          type: integer
          minimum: 1
          maximum: 4
          default: 1
          description: 图片张数，1 至模型上限（4）。预留 n 张的费用，只对实际返回的图片扣费。
        size:
          type: string
          default: auto
          example: 1024x1024
          description: >-
            `宽x高` 或 `auto`。决定价格档位：最长边不超过 1024 px 为 1K，不超过 2048 px 为 2K，不超过 4096
            px 为 4K；`auto` 或未传为 2K。
        quality:
          type: string
          description: 传给模型，例如 `low`、`medium`、`high` 或 `auto`。不影响价格。
        response_format:
          type: string
          enum:
            - b64_json
          description: 仅支持 `b64_json`。
        image:
          type: string
          format: binary
          description: 一张或多张原图（PNG、JPEG 或 WebP）。
        mask:
          type: string
          format: binary
          description: 可选蒙版图片，透明区域表示要编辑的位置。
      additionalProperties: true
    ImagesResponse:
      type: object
      required:
        - created
        - data
        - model
        - cost_microusd
      properties:
        created:
          type: integer
        model:
          type: string
        data:
          type: array
          description: 生成的图片。
          items:
            type: object
            required:
              - b64_json
            properties:
              b64_json:
                type: string
                description: Base64 编码的图片。
              revised_prompt:
                type: string
        background:
          type: string
        output_format:
          type: string
        quality:
          type: string
        size:
          type: string
        usage:
          type: object
          description: 模型报告的 token 数，仅供参考；图片按张计费，不按 token 计费。
          additionalProperties: true
        cost_microusd:
          type: integer
          description: 折扣后的扣费金额（micro-USD）。
        omnirelay_metadata:
          $ref: '#/components/schemas/RequestMetadata'
        gateway_metadata:
          $ref: '#/components/schemas/RequestMetadata'
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - type
          properties:
            code:
              type: string
              example: model_unavailable
            message:
              type: string
              example: The model does not exist or is disabled.
              description: 用于日志和 SDK 异常的简短英文说明；措辞可能调整，请按 code 判断。
            type:
              type: string
              example: not_found_error
              description: >-
                按 HTTP
                状态划分的错误类别：invalid_request_error、authentication_error、insufficient_quota、permission_error、not_found_error、conflict_error、rate_limit_error、service_unavailable
                或 api_error。
            param:
              type: string
              maxLength: 200
              description: 可识别时返回被拒绝的请求字段路径，不包含参数值；Responses 使用原生字段名。
        request_id:
          type: string
          description: 在对话补全、Responses 和 Embeddings 出错时返回。
    RequestMetadata:
      type: object
      description: >-
        仅在请求带有 `X-Gateway-Metadata: enabled` 时出现。同时以 `gateway_metadata` 和旧名
        `omnirelay_metadata` 返回，内容相同。流式响应中随第一个数据块返回。
      properties:
        request_id:
          type: string
          description: 请求 ID，与 `X-Request-ID` 相同。
        requested:
          type: string
          description: 你请求的模型 ID。
        model:
          type: string
          description: 实际响应本次调用的模型。
        provider:
          type: string
          description: 该模型的模型服务方。
        mode:
          type: string
          enum:
            - live
          description: live 表示调用了真实模型服务方。
        strategy:
          type: string
          enum:
            - direct
          description: 模型的解析方式。目前每个模型只有一个渠道，因此恒为 `direct`。
        attempt:
          type: integer
          description: 最终响应的是第几次尝试（从 1 开始）。在支持故障转移之前恒为 1。
        attempts:
          type: array
          description: 按顺序列出的全部尝试。
          items:
            type: object
            properties:
              provider:
                type: string
              model:
                type: string
              mode:
                type: string
        tags:
          type: object
          additionalProperties:
            type: string
          description: 本次调用记录的标签；没有时为 `{}`。
        deprecated_header:
          type: string
          description: >-
            当请求同时带有旧名请求头（`X-OmniRelay-Tags` 或
            `X-OmniRelay-Metadata`）和值不同的新名请求头时出现：给出被忽略的旧请求头名。
  responses:
    Unauthorized:
      description: '`unauthorized`：缺少 API Key，或该 Key 已吊销或无效。'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 在 OmniRelay 控制台创建的 API Key。所有者确认身份后可在控制台再次查看。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.