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

# Image Editing

> Use POST /v1/images/edits in CometAPI to edit images with multipart uploads, masks, GPT image models, and encoded image output controls.

Use this route to edit existing images with OpenAI-compatible multipart uploads on CometAPI.

## Use this route when

* You already have a source image and want a prompt-driven edit
* You may need a mask for targeted changes
* You can handle multipart file upload instead of a plain JSON request

## Safe first request

* Start with one PNG or JPG file
* Skip the mask until the base edit flow works
* Use `model: "gpt-image-2"` for GPT image edit requests on this route
* Use one short instruction that asks for one visible change
* Read the edited result from `data[0].b64_json`
* Set `output_format: "jpeg"` when you want a JPEG payload
* Expect longer latency than plain image generation

## Model behavior

* GPT image edit models on this route return inline base64 image data
* `output_format` controls the encoded image type inside `b64_json`
* `response_format` only matters when a model supports URL output
* `qwen-image-edit` follows provider-specific edit behavior behind the same CometAPI route


## OpenAPI

````yaml /api/openapi/image/openai/post-image-editing.openapi.json POST /v1/images/edits
openapi: 3.1.0
info:
  title: Image Editing API
  version: 1.0.0
  description: >-
    Edit existing images through the OpenAI-compatible CometAPI image edits
    route. GPT image edit models return inline base64 payloads in
    `data[].b64_json`, and `output_format` controls the encoded image type.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/images/edits:
    post:
      summary: Edit images
      description: >-
        Upload one or more source images, optionally include a mask, and request
        an edited result with a text instruction.
      operationId: image_editing
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - image
                - prompt
              properties:
                image:
                  type: string
                  format: binary
                  description: >-
                    Source image file. Start with one PNG or JPG input for the
                    simplest flow.
                prompt:
                  type: string
                  description: Edit instruction describing the change you want.
                  example: Add a small red ribbon to the paper boat.
                model:
                  type: string
                  description: >-
                    The image editing model to use. Choose a supported model
                    from the [Models page](/overview/models).
                  default: gpt-image-2
                mask:
                  type: string
                  format: binary
                  description: >-
                    Optional PNG mask. Transparent areas indicate regions that
                    should be edited.
                'n':
                  type: string
                  description: Number of edited images to return.
                  default: '1'
                quality:
                  type: string
                  enum:
                    - high
                    - medium
                    - low
                  description: Quality setting for models that support it.
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  description: >-
                    Requested response container when supported by the selected
                    model. GPT image edit models return `data[].b64_json`; use
                    `output_format` to choose the encoded image type.
                output_format:
                  type: string
                  description: >-
                    Encoded image type for GPT image edit results returned in
                    `data[].b64_json`. For example, use `jpeg` for a JPEG
                    payload.
                  example: jpeg
                size:
                  type: string
                  description: Requested output size when supported by the selected model.
              default:
                model: gpt-image-2
                prompt: Add a small red ribbon to the paper boat.
                output_format: jpeg
      responses:
        '200':
          description: Edited image result.
          content:
            application/json:
              schema:
                type: object
                required:
                  - created
                  - data
                  - usage
                properties:
                  created:
                    type: integer
                  usage:
                    type: object
                    properties:
                      prompt_tokens:
                        type: integer
                      completion_tokens:
                        type: integer
                      total_tokens:
                        type: integer
                      prompt_tokens_details:
                        type: object
                        properties:
                          cached_tokens_details:
                            type: object
                            properties: {}
                      completion_tokens_details:
                        type: object
                        properties: {}
                      input_tokens:
                        type: integer
                      output_tokens:
                        type: integer
                      input_tokens_details:
                        type: object
                        properties:
                          image_tokens:
                            type: integer
                          text_tokens:
                            type: integer
                          cached_tokens_details:
                            type: object
                            properties: {}
                      claude_cache_creation_5_m_tokens:
                        type: integer
                      claude_cache_creation_1_h_tokens:
                        type: integer
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        b64_json:
                          type: string
                          description: >-
                            Base64-encoded image payload. Decode this value to
                            get the edited image bytes.
                        url:
                          type: string
                          description: >-
                            Temporary image URL when the selected model supports
                            URL output.
                        revised_prompt:
                          type: string
                          description: Provider-rewritten prompt, when available.
                example:
                  created: 1776836647
                  usage:
                    prompt_tokens: 0
                    completion_tokens: 0
                    total_tokens: 981
                    prompt_tokens_details:
                      cached_tokens_details: {}
                    completion_tokens_details: {}
                    input_tokens: 785
                    output_tokens: 196
                    input_tokens_details:
                      image_tokens: 768
                      text_tokens: 17
                      cached_tokens_details: {}
                    claude_cache_creation_5_m_tokens: 0
                    claude_cache_creation_1_h_tokens: 0
                  data:
                    - b64_json: <base64-image-data>
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````