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

# Edit Image

> Interface description: Edit images synchronously, edit based on reference images and instructions.

Before calling this interface, please request the ["Image Editing Models"](/en/api-reference/get-api-ai-models-image-edit) interface (`GET /api/ai/models/image/edit`) to obtain the currently available model list and the size, maximum number of input images, and price supported by each model, and then fill in the parameters of this interface accordingly.

Image editing as **image-to-image**: You must pass in the reference image `image`, and follow the prompts to modify, redraw or stylize it based on it. If you want to generate a new image (text-to-image) using only text, please use the ["Generate Image"](/en/api-reference/post-api-ai-image-generate) interface.

If you are already using the OpenAI SDK or ecological tools, you can use the OpenAI compatible endpoint ["OpenAI Image Editing"](/en/api-reference/post-api-ai-images-edits) instead.



## OpenAPI

````yaml /openapi/en/aitoearn.openapi.json post /api/ai/image/edit
openapi: 3.0.1
info:
  title: AiToEarn Open Platform API
  description: >-
    AiToEarn Open Platform API. You can switch between the China and
    international sites for testing. Business success is determined by whether
    the response body has code === 0.
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: China site
  - url: https://aitoearn.ai
    description: International site
security: []
tags:
  - name: AI Services
  - name: AI Services/Video Generation
  - name: AI Services/Image Generation
  - name: Channel Management
  - name: Channel Management/Accounts
  - name: Channel Management/Publishing
  - name: Channel Management/Platforms
  - name: Channel Management/Works
  - name: Channel Management/Account Groups
  - name: Channel Management/Authorization
  - name: Asset Management
  - name: AI Services/Large Language Models
paths:
  /api/ai/image/edit:
    post:
      tags:
        - AI Services/Image Generation
      summary: Edit Image
      description: >-
        Interface description: Edit images synchronously, edit based on
        reference images and instructions.


        Before calling this interface, please request the ["Image Editing
        Models"](/en/api-reference/get-api-ai-models-image-edit) interface (`GET
        /api/ai/models/image/edit`) to obtain the currently available model list
        and the size, maximum number of input images, and price supported by
        each model, and then fill in the parameters of this interface
        accordingly.


        Image editing as **image-to-image**: You must pass in the reference
        image `image`, and follow the prompts to modify, redraw or stylize it
        based on it. If you want to generate a new image (text-to-image) using
        only text, please use the ["Generate
        Image"](/en/api-reference/post-api-ai-image-generate) interface.


        If you are already using the OpenAI SDK or ecological tools, you can use
        the OpenAI compatible endpoint ["OpenAI Image
        Editing"](/en/api-reference/post-api-ai-images-edits) instead.
      operationId: ImageController_editImage
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: >-
                    Image editing model name. First call the ["Image Editing
                    Models"](/en/api-reference/get-api-ai-models-image-edit)
                    interface (`GET /api/ai/models/image/edit`) and pass in the
                    `data[n].name` returned by it; the size, maximum number of
                    input images and price supported by each model shall be
                    subject to the return of this interface.
                image:
                  anyOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                  description: original picture
                prompt:
                  type: string
                  minLength: 1
                  maxLength: 4000
                  description: Edit description
                mask:
                  type: string
                  description: >-
                    Mask image URL for **partial redraw** (optional). It needs
                    to be a PNG image with the same size as `image`: the
                    completely transparent area (alpha is 0) represents the part
                    that needs to be redrawn according to the prompt word, and
                    the opaque area remains unchanged. Edit the entire image
                    when not uploading.
                'n':
                  description: Number of images generated
                  type: integer
                  minimum: 1
                  maximum: 1
                size:
                  type: string
                  description: >-
                    Image size. The optional values ​​vary from model to model,
                    and are subject to the `data[n].sizes` returned by the
                    ["Image Editing
                    Models"](/en/api-reference/get-api-ai-models-image-edit)
                    interface; the prices for different sizes are different, see
                    `data[n].pricing`.
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  description: Return format
              required:
                - model
                - image
                - prompt
            examples: {}
        required: true
      responses:
        '200':
          description: >-
            The request has been processed by the service. Business success is
            determined by whether the response body has code === 0.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ImageResponseVo'
                  code:
                    type: integer
                    description: >-
                      Business status code. 0 means success; non-zero means a
                      business error.
                  message:
                    type: string
                    description: Response message.
                  requestId:
                    type: string
                    description: Request ID.
                  timestamp:
                    type: integer
                    description: Error response timestamp in Unix milliseconds.
                required:
                  - code
                  - message
              examples:
                success:
                  summary: Success
                  value:
                    code: 0
                    message: Request succeeded
                    data:
                      created: 1
                      list:
                        - url: string
                          b64_json: string
                          revised_prompt: string
                      usage:
                        input_tokens: 1
                        output_tokens: 1
                        total_tokens: 1
                      background: string
                      output_format: string
                      quality: string
                      size: string
                validationFailed10002:
                  summary: ValidationFailed (10002)
                  value:
                    code: 10002
                    message: Parameter validation failed
                    data: {}
                    timestamp: 1772099056662
                unauthorized401:
                  summary: Unauthenticated or invalid API Key
                  value:
                    code: 401
                    message: Unauthorized
                    data: {}
                    timestamp: 1772099056662
                invalidModel12300:
                  summary: InvalidModel (12300)
                  value:
                    code: 12300
                    message: Invalid AI model
                    data: {}
                    timestamp: 1772099056662
      deprecated: false
      security:
        - apikey-header-X-Api-Key: []
components:
  schemas:
    ImageResponseVo:
      type: object
      properties:
        created:
          type: number
          description: Create timestamp
        list:
          type: array
          items:
            type: object
            properties:
              url:
                description: Image URL
                type: string
              b64_json:
                description: base64 encoded image
                type: string
              revised_prompt:
                description: Revised prompt words
                type: string
            additionalProperties: false
          description: Generated image list
        usage:
          description: token usage
          type: object
          properties:
            input_tokens:
              description: Enter the number of tokens
              type: number
            output_tokens:
              description: Output the number of tokens
              type: number
            total_tokens:
              description: Total number of tokens
              type: number
          additionalProperties: false
        background:
          type: string
          description: background
        output_format:
          type: string
          description: Output format
        quality:
          type: string
          description: Quality level
        size:
          type: string
          description: Image size
      required:
        - created
        - list
      additionalProperties: false
  securitySchemes:
    apikey-header-X-Api-Key:
      type: apiKey
      in: header
      name: X-Api-Key
      description: >-
        Need to get API Key from AiToEarn. Click to go to ["API Key Obtaining
        Tutorial"](/en/use/api-key).

````