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

# Edit images

> Edit existing images with gpt-image-2 using JSON image URLs or multipart uploads.

Use this endpoint for image-to-image edits, masking, or background replacement.

<Tip>
  JSON requests are easiest for remote image URLs. Multipart form-data is best when you want to upload local files directly.
</Tip>


## OpenAPI

````yaml POST /v1/images/edits
openapi: 3.1.0
info:
  title: SmewAI Images API
  description: OpenAI-compatible image generation and editing endpoints for SmewAI.
  version: 1.0.0
servers:
  - url: https://smew.ai
    description: Production API
security:
  - bearerAuth: []
paths:
  /v1/images/edits:
    post:
      tags:
        - Images
      summary: 编辑图片
      description: >-
        Edit an existing image with `gpt-image-2`. You can submit either JSON
        payloads with `image_url` values or multipart form-data with uploaded
        files.
      operationId: editImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageEditJsonRequest'
            examples:
              jsonEdit:
                summary: 使用图片链接编辑
                value:
                  model: gpt-image-2
                  prompt: Replace the background with a clean studio setup.
                  images:
                    - image_url: https://example.com/input.png
                  mask:
                    image_url: https://example.com/mask.png
                  size: 1024x1024
                  response_format: b64_json
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImageEditMultipartRequest'
      responses:
        '200':
          description: Edit accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EditResponse'
              examples:
                success:
                  value:
                    created: 1712345678
                    data:
                      - b64_json: iVBORw0KGgo...
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ImageEditJsonRequest:
      type: object
      required:
        - model
        - prompt
        - images
      properties:
        model:
          type: string
          enum:
            - gpt-image-2
        prompt:
          type: string
        images:
          type: array
          items:
            $ref: '#/components/schemas/ImageUrlObject'
        mask:
          $ref: '#/components/schemas/ImageUrlObject'
        size:
          type: string
          example: 1024x1024
        response_format:
          type: string
          enum:
            - url
            - b64_json
          default: url
    ImageEditMultipartRequest:
      type: object
      required:
        - model
        - prompt
        - image
      properties:
        model:
          type: string
          example: gpt-image-2
        prompt:
          type: string
        image:
          type: string
          format: binary
          description: Source image file.
        mask:
          type: string
          format: binary
          description: Optional mask file.
        size:
          type: string
          example: 1024x1024
    EditResponse:
      type: object
      properties:
        created:
          type: integer
        data:
          type: array
          items:
            type: object
            properties:
              url:
                type: string
                format: uri
              b64_json:
                type: string
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          example: error
        error:
          $ref: '#/components/schemas/ErrorDetail'
    ImageUrlObject:
      type: object
      required:
        - image_url
      properties:
        image_url:
          type: string
    ErrorDetail:
      type: object
      properties:
        type:
          type: string
          example: invalid_request_error
        message:
          type: string
          example: Invalid request body.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Paste your SmewAI API key as a Bearer token.

````