> ## 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.

# 이미지 편집 생성

> CometAPI에서 POST /v1/images/edits를 사용해 multipart 업로드, 마스크, GPT 이미지 모델, 인코딩된 이미지 출력 제어로 이미지를 편집합니다.

이 경로를 사용하면 CometAPI에서 OpenAI 호환 multipart 업로드로 기존 이미지를 편집할 수 있습니다.

## 이 경로를 사용하는 경우

* 이미 소스 이미지가 있고 프롬프트(Prompt) 기반 편집을 원할 때
* 특정 부분만 변경하기 위해 마스크가 필요할 수 있을 때
* 일반 JSON 요청 대신 multipart 파일 업로드를 처리할 수 있을 때

## 안전한 첫 요청

* PNG 또는 JPG 파일 1개로 시작하세요
* 기본 편집 흐름이 작동할 때까지 마스크는 건너뛰세요
* 이 경로에서 GPT 이미지 편집 요청에는 `model: "gpt-image-2"`를 사용하세요
* 눈에 보이는 변경 1가지를 요청하는 짧은 지시문 1개를 사용하세요
* 편집된 결과는 `data[0].b64_json`에서 읽으세요
* JPEG 페이로드가 필요하면 `output_format: "jpeg"`를 설정하세요
* 일반 이미지 생성보다 지연 시간이 더 길 수 있음을 예상하세요

## 모델 동작

* 이 경로의 GPT 이미지 편집 모델은 인라인 base64 이미지 데이터를 반환합니다
* `output_format`은 `b64_json` 내부의 인코딩된 이미지 형식을 제어합니다
* `response_format`은 모델이 URL 출력을 지원할 때만 의미가 있습니다
* `qwen-image-edit`는 동일한 CometAPI 경로 뒤에서 provider별 편집 동작을 따릅니다


## 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 mark the regions to
                    edit. The mask dimensions must match the source image
                    exactly.
                '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.
                  background:
                    type: string
                    description: Background mode returned by models that expose it.
                  output_format:
                    type: string
                    description: Encoded image type returned by GPT image models.
                  quality:
                    type: string
                    description: Quality level returned by models that expose it.
                  size:
                    type: string
                    description: Output size returned by models that expose it.
                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>
              example:
                created: 1781075000
                background: opaque
                output_format: png
                quality: low
                size: 1024x1024
                usage:
                  input_tokens: 784
                  input_tokens_details:
                    image_tokens: 768
                    text_tokens: 16
                  output_tokens: 196
                  output_tokens_details:
                    image_tokens: 196
                    text_tokens: 0
                  total_tokens: 980
                data:
                  - b64_json: iVBORw0KGgoAAAANSUhEUgAA...
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/v1/images/edits \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -F image=@cat.jpg \
              -F prompt="Add a small red bow tie on the cat" \
              -F model=gpt-image-2 \
              -F quality=low
        - lang: Shell
          label: With mask
          source: >
            # The mask is a PNG whose transparent areas mark the regions to
            edit.

            # Its dimensions must match the source image exactly.

            curl https://api.cometapi.com/v1/images/edits \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -F image=@cat.jpg \
              -F mask=@mask.png \
              -F prompt="Replace the masked area with a red bow tie" \
              -F model=gpt-image-2 \
              -F quality=low
        - lang: Python
          label: Default
          source: |
            import base64
            import os
            from openai import OpenAI

            client = OpenAI(
                base_url="https://api.cometapi.com/v1",
                api_key=os.environ["COMETAPI_KEY"],
            )

            with open("cat.jpg", "rb") as image_file:
                result = client.images.edit(
                    model="gpt-image-2",
                    image=image_file,
                    prompt="Add a small red bow tie on the cat",
                    quality="low",
                )

            image_bytes = base64.b64decode(result.data[0].b64_json)
            with open("edited.png", "wb") as f:
                f.write(image_bytes)
        - lang: Python
          label: With mask
          source: >
            import base64

            import os

            from openai import OpenAI


            client = OpenAI(
                base_url="https://api.cometapi.com/v1",
                api_key=os.environ["COMETAPI_KEY"],
            )


            # The mask is a PNG whose transparent areas mark the regions to
            edit.

            # Its dimensions must match the source image exactly.

            with open("cat.jpg", "rb") as image_file, open("mask.png", "rb") as
            mask_file:
                result = client.images.edit(
                    model="gpt-image-2",
                    image=image_file,
                    mask=mask_file,
                    prompt="Replace the masked area with a red bow tie",
                    quality="low",
                )

            image_bytes = base64.b64decode(result.data[0].b64_json)

            with open("edited.png", "wb") as f:
                f.write(image_bytes)
        - lang: JavaScript
          label: Default
          source: >
            import fs from "node:fs";

            import OpenAI, { toFile } from "openai";


            const client = new OpenAI({
                baseURL: "https://api.cometapi.com/v1",
                apiKey: process.env.COMETAPI_KEY,
            });


            const result = await client.images.edit({
                model: "gpt-image-2",
                image: await toFile(fs.createReadStream("cat.jpg"), "cat.jpg", { type: "image/jpeg" }),
                prompt: "Add a small red bow tie on the cat",
                quality: "low",
            });


            fs.writeFileSync("edited.png", Buffer.from(result.data[0].b64_json,
            "base64"));
        - lang: JavaScript
          label: With mask
          source: >
            import fs from "node:fs";

            import OpenAI, { toFile } from "openai";


            const client = new OpenAI({
                baseURL: "https://api.cometapi.com/v1",
                apiKey: process.env.COMETAPI_KEY,
            });


            // The mask is a PNG whose transparent areas mark the regions to
            edit.

            // Its dimensions must match the source image exactly.

            const result = await client.images.edit({
                model: "gpt-image-2",
                image: await toFile(fs.createReadStream("cat.jpg"), "cat.jpg", { type: "image/jpeg" }),
                mask: await toFile(fs.createReadStream("mask.png"), "mask.png", { type: "image/png" }),
                prompt: "Replace the masked area with a red bow tie",
                quality: "low",
            });


            fs.writeFileSync("edited.png", Buffer.from(result.data[0].b64_json,
            "base64"));
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````