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

# Image Edits

> Edit existing images using AI

Create variations or edits of existing images using AI models.

## Edit Images

`POST /images/edits`

Create edited or extended versions of an existing image.

### Request Body

<ParamField body="image" type="file" required>
  The image to edit. Must be a valid PNG file, less than 4MB, and square.
</ParamField>

<ParamField body="mask" type="file">
  Additional image whose fully transparent areas indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
</ParamField>

<ParamField body="prompt" type="string" required>
  A text description of the desired image(s)
</ParamField>

<ParamField body="model" type="string">
  The model to use for image editing ("flux-1-kontext-pro", "flux-1-kontext-max", etc)
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate (1-10)
</ParamField>

<ParamField body="size" type="string">
  Size of the generated images ("256x256", "512x512", "1024x1024")
</ParamField>

<ParamField body="response_format" type="string">
  Format of the generated images ("url" or "b64\_json")
</ParamField>

### Response

Returns an array of image objects with URLs or base64-encoded images.

### Example

<CodeGroup>
  ```javascript Node.js theme={null}
  const formData = new FormData();
  formData.append('image', imageFile);
  formData.append('prompt', 'Add a blue sky to this image');
  formData.append('n', '1');
  formData.append('size', '1024x1024');

  const response = await fetch('https://api.electronhub.ai/v1/images/edits', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    },
    body: formData
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  with open('image.png', 'rb') as image_file:
      response = requests.post(
          'https://api.electronhub.ai/v1/images/edits',
          headers={
              'Authorization': 'Bearer YOUR_API_KEY'
          },
          files={
              'image': image_file
          },
          data={
              'prompt': 'Add a blue sky to this image',
              'n': 1,
              'size': '1024x1024'
          }
      )

  print(response.json())
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.electronhub.ai/v1/images/edits" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F image="@image.png" \
    -F prompt="Add a blue sky to this image" \
    -F n=1 \
    -F size="1024x1024"
  ```
</CodeGroup>

## Image Variations

`POST /images/variations`

Create variations of an existing image.

### Request Body

<ParamField body="image" type="file" required>
  The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
</ParamField>

<ParamField body="model" type="string">
  The model to use for generating variations ("flux-1-kontext-pro", "flux-1-kontext-max", etc)
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate (1-10)
</ParamField>

<ParamField body="size" type="string">
  Size of the generated images ("256x256", "512x512", "1024x1024")
</ParamField>

<ParamField body="response_format" type="string">
  Format of the generated images ("url" or "b64\_json")
</ParamField>


## OpenAPI

````yaml POST /images/edits
openapi: 3.0.1
info:
  title: Electron Hub API
  description: >-
    Unified API platform integrating 200+ AI models for chat, image generation,
    speech-to-text, embeddings, and more.
  version: 1.0.0
  contact:
    name: Electron Hub Support
    email: support@electronhub.ai
    url: https://discord.com/invite/electronhub
  license:
    name: MIT
servers:
  - url: https://api.electronhub.ai/v1
    description: Production API v1
security:
  - bearerAuth: []
paths:
  /images/edits:
    post:
      summary: Edit Images
      description: Edit images with prompts
      operationId: editImages
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImageEditRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
components:
  schemas:
    ImageEditRequest:
      type: object
      required:
        - image
        - prompt
        - model
      properties:
        image:
          type: string
          format: binary
          description: The image to edit
        prompt:
          type: string
          description: A text description of the desired image
        model:
          type: string
          example: flux-1-kontext-pro
        'n':
          type: integer
          minimum: 1
          maximum: 10
          default: 1
        size:
          type: string
          enum:
            - 256x256
            - 512x512
            - 1024x1024
          default: 1024x1024
        response_format:
          type: string
          enum:
            - url
            - b64_json
          default: url
    ImageResponse:
      type: object
      required:
        - created
        - data
      properties:
        created:
          type: integer
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
    ImageData:
      type: object
      properties:
        url:
          type: string
          format: uri
        b64_json:
          type: string
        revised_prompt:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your API key (starts with 'ek-')

````