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

# Edit an image

> Remove an object or watermark with LaMa. Upload a picture and a PNG mask to get a full-resolution PNG.

Upload your picture and a mask that marks what to remove. LaMa fills the marked area using the surrounding picture. You get one PNG at the original resolution. Pixels outside the mask stay unchanged. If you set `grow`, this applies to the expanded mask.

## Request

Send `multipart/form-data`. Upload the files themselves in the `image` and `mask` fields.

| Field | What to send |
| - | - |
| `image` | Required. A PNG, JPEG or WebP file. |
| `mask` | Required. A PNG with the same width and height as the picture. |
| `model` | `lama` (default) or its alias `inpaint`. |
| `response_format` | Only `b64_json` (default). |
| `n` | Only `1` (default). |
| `grow` | A whole number from 0 to 64. Expands the removal area by this many pixels. Defaults to 0. This is a ShareMyAI extension. |
| `prompt` | Optional. The API accepts this field and ignores it. LaMa takes no prompt. |
| `async` | Send `true` to get a job id and poll for the result. You can also send `Prefer: respond-async`. See [Image jobs](https://docs.sharemy.ai/api-reference/jobs.md). |

Each file can be up to 50 MB (52,428,800 bytes). Neither side can exceed 4,096 pixels. If you set a file's content type, use its actual image type or `application/octet-stream`.

With the OpenAI Python SDK, pass the two open files to `client.images.edit(...)`. Use `prompt=""` and send `grow` with `extra_body={"grow": 4}`.

## How to mark the mask

* If any pixel has transparency, only fully transparent pixels are removed. Partly transparent and opaque pixels are kept, whatever their color.
* If every pixel is opaque, white or bright pixels are removed. Dark pixels are kept. On a grayscale mask, 128 through 255 mark pixels to remove.

## Price

You pay 3 credits per 4 million pixels in the full picture, with a 3-credit minimum. A 4,000 × 2,000 picture has 8 million pixels and costs 6 credits, even if you mark only a small watermark. See [Credits and pricing](https://docs.sharemy.ai/credits-and-pricing.md#image-edits).

## Response

The default response is HTTP 200. `created` is a Unix timestamp in seconds. Decode `data[0].b64_json` to save the edited PNG. The base64 below is shortened.

```json theme={null}
{
  "created": 1764547200,
  "data": [{ "b64_json": "iVBORw0KGgo..." }]
}
```

`X-ShareMyAI-Cost-Credits` gives the price. `X-ShareMyAI-Balance-Credits` gives your balance just after the hold. Every response includes an `x-request-id`.

## Errors

File and field checks can fail at submission. The machine checks the decoded dimensions when it runs the edit. For an async edit, read processing errors in the failed job's `error` field.

| Status | `error.code` | What to check |
| - | - | - |
| 400 | `invalid_value` | Check the multipart body, upload both files and use a whole number from 0 to 64 for `grow`. |
| 400 | `invalid_input` | The machine could not decode a file, or the mask dimensions differ from the picture. Check `error.param` for `image` or `mask`. |
| 400 | `model_not_found` | Use `lama` or `inpaint`. |
| 400 | `unsupported_value` | Check `n` and `response_format`. |
| 413 | `file_too_large` | The file named in `error.param` exceeds 50 MB. |
| 413 | `image_too_large` | The image or mask exceeds 4,096 pixels on a side. |
| 415 | `unsupported_image` | Check the file format, its header and its declared content type. The mask must be a PNG. |
| 503 | `storage_unavailable` | Async result storage is unavailable. Try again later. |

For authentication, balance, concurrency and machine errors, see [Errors and limits](https://docs.sharemy.ai/errors-and-limits.md).


## OpenAPI

````yaml api-reference/openapi.json POST /v1/images/edits
openapi: 3.1.0
info:
  title: ShareMyAI API
  version: 1.0.0
  description: >-
    OpenAI-shaped endpoints that run jobs on shared GPUs. Closing the connection
    cancels an unfinished synchronous job and returns its held credits. CORS
    allows any origin, echoes requested preflight headers and exposes Location,
    the request id, concurrency, retry, cost, balance, token cap and sample rate
    headers.
servers:
  - url: https://sharemy.ai
    description: ShareMyAI
security:
  - bearerAuth: []
tags:
  - name: Models
  - name: Chat
  - name: Images
  - name: Jobs
  - name: Audio
paths:
  /v1/images/edits:
    post:
      tags:
        - Images
      summary: Edit an image
      description: >-
        Remove a masked object or watermark with LaMa. The full-resolution PNG
        keeps the pixels outside the expanded mask. Edits cost 3 credits per 4
        million input pixels, with a 3-credit minimum.
      operationId: editImage
      parameters:
        - name: Prefer
          in: header
          description: Send respond-async to receive a job id and poll for the result.
          schema:
            type: string
          example: respond-async
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImageEditRequest'
            encoding:
              image:
                contentType: image/png, image/jpeg, image/webp
              mask:
                contentType: image/png
      responses:
        '200':
          description: One edited picture.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageEditResponse'
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            x-ratelimit-limit-concurrent:
              $ref: '#/components/headers/x-ratelimit-limit-concurrent'
            x-ratelimit-remaining-concurrent:
              $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
            X-ShareMyAI-Cost-Credits:
              $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
            X-ShareMyAI-Balance-Credits:
              $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        '202':
          $ref: '#/components/responses/JobAccepted'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '403':
          $ref: '#/components/responses/Suspended'
        '405':
          $ref: '#/components/responses/MethodNotAllowed'
        '413':
          description: >-
            file_too_large for an upload over 50 MB. image_too_large for a side
            over 4,096 pixels. The error param names image or mask.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            x-ratelimit-limit-concurrent:
              $ref: '#/components/headers/x-ratelimit-limit-concurrent'
            x-ratelimit-remaining-concurrent:
              $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        '415':
          description: >-
            unsupported_image for an unreadable header, unsupported file format
            or mismatched image content type. The error param names image or
            mask.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          headers:
            x-request-id:
              $ref: '#/components/headers/x-request-id'
            x-ratelimit-limit-concurrent:
              $ref: '#/components/headers/x-ratelimit-limit-concurrent'
            x-ratelimit-remaining-concurrent:
              $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        '429':
          $ref: '#/components/responses/TooManyCalls'
        '499':
          $ref: '#/components/responses/Cancelled'
        '502':
          $ref: '#/components/responses/NetworkError'
        '503':
          $ref: '#/components/responses/ImageUnavailable'
      x-codeSamples:
        - lang: bash
          label: curl
          source: |-
            set -eo pipefail
            curl -fsS https://sharemy.ai/v1/images/edits \
              -H "Authorization: Bearer $SHAREMYAI_API_KEY" \
              -F 'image=@photo.jpg;type=image/jpeg' \
              -F 'mask=@mask.png;type=image/png' \
              -F model=lama -F grow=4 \
              | jq -er '.data[0].b64_json' | base64 --decode > edited.png
        - lang: python
          label: Python
          source: >-
            import base64, os

            from pathlib import Path

            from openai import OpenAI


            client = OpenAI(api_key=os.environ["SHAREMYAI_API_KEY"],
            base_url="https://sharemy.ai/v1")


            with open("photo.jpg", "rb") as image, open("mask.png", "rb") as
            mask:
                result = client.images.edit(
                    model="lama",
                    image=image,
                    mask=mask,
                    prompt="",  # The SDK takes a prompt. LaMa ignores it.
                    extra_body={"grow": 4},
                )
            Path("edited.png").write_bytes(base64.b64decode(result.data[0].b64_json))
        - lang: javascript
          label: Node
          source: >-
            import fs from "node:fs";

            import OpenAI from "openai";


            const client = new OpenAI({ apiKey: process.env.SHAREMYAI_API_KEY,
            baseURL: "https://sharemy.ai/v1" });

            const result = await client.images.edit({
              model: "lama",
              image: fs.createReadStream("photo.jpg"),
              mask: fs.createReadStream("mask.png"),
              prompt: "",
              grow: 4,
            });

            fs.writeFileSync("edited.png", Buffer.from(result.data[0].b64_json,
            "base64"));
components:
  schemas:
    ImageEditRequest:
      type: object
      required:
        - image
        - mask
      properties:
        image:
          type: string
          format: binary
          description: >-
            Upload a PNG, JPEG or WebP. Up to 50 MB and 4,096 pixels on each
            side.
        mask:
          type: string
          format: binary
          contentMediaType: image/png
          description: >-
            Upload a PNG of the same dimensions, up to 50 MB. If any pixel has
            transparency, only fully transparent pixels are removed. In an
            opaque mask, bright pixels mark the removal area.
        model:
          type: string
          enum:
            - lama
            - inpaint
          default: lama
        response_format:
          type: string
          const: b64_json
          default: b64_json
        'n':
          type: integer
          const: 1
          default: 1
        grow:
          type: integer
          minimum: 0
          maximum: 64
          default: 0
          description: Expand the removal mask by this many pixels. A ShareMyAI extension.
        prompt:
          type: string
          description: Accepted and ignored. LaMa takes no prompt.
        async:
          type: boolean
          default: false
          description: Send the multipart value true to receive a job id.
    ImageEditResponse:
      type: object
      required:
        - created
        - data
      properties:
        created:
          type: integer
          description: Unix time in seconds.
        data:
          type: array
          minItems: 1
          maxItems: 1
          items:
            type: object
            required:
              - b64_json
            properties:
              b64_json:
                type: string
                contentEncoding: base64
                contentMediaType: image/png
                description: The full-resolution edited picture.
    Error:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
    JobReceipt:
      type: object
      required:
        - id
        - object
        - created
        - endpoint
        - status
      properties:
        id:
          type: string
          description: Job id returned at submission.
        object:
          type: string
          const: job
        created:
          type: integer
          description: Unix time in seconds.
        endpoint:
          type: string
          enum:
            - /v1/images/generations
            - /v1/images/edits
        status:
          type: string
          const: queued
    ErrorDetail:
      type: object
      required:
        - message
        - type
        - param
        - code
      properties:
        message:
          type: string
          description: What went wrong, for a person to read.
        type:
          type: string
          description: >-
            402 uses insufficient_quota, other 4xx errors use
            invalid_request_error, and 5xx errors use api_error.
          enum:
            - invalid_request_error
            - insufficient_quota
            - api_error
        param:
          type:
            - string
            - 'null'
          description: The request field at fault, when there is one.
        code:
          type:
            - string
            - 'null'
          description: A stable code. The Errors and limits page lists them all.
          examples:
            - model_not_found
        price_credits:
          type: number
          description: Job price in credits on an insufficient_quota error.
        balance_credits:
          type: number
          description: Account balance in credits on an insufficient_quota error.
      if:
        properties:
          code:
            const: insufficient_quota
      then:
        required:
          - price_credits
          - balance_credits
  headers:
    x-request-id:
      description: Identifier for this API response.
      schema:
        type: string
    x-ratelimit-limit-concurrent:
      description: Job slots per account across all tokens.
      schema:
        type: integer
        const: 4
    x-ratelimit-remaining-concurrent:
      description: Free account slots when headers are sent.
      schema:
        type: integer
        minimum: 0
        maximum: 4
    X-ShareMyAI-Cost-Credits:
      description: >-
        Quoted price in credits when a job was accepted. For a Janus batch, the
        total for completed pictures.
      schema:
        type: number
    X-ShareMyAI-Balance-Credits:
      description: >-
        Balance in credits after the hold, from the last successful quote on a
        Janus batch.
      schema:
        type: number
    Retry-After:
      description: >-
        Seconds to wait. 2 on async submission and unfinished polls, 1 on a 429,
        and 30 on HTTP 503 no_provider.
      schema:
        type: integer
    X-ShareMyAI-Max-Tokens:
      description: Only on chat requests whose output budget was capped.
      schema:
        type: integer
        const: 4096
    x-should-retry:
      description: >-
        Suppress automatic retries for insufficient_quota,
        content_policy_violation or no_provider.
      schema:
        type: string
        const: 'false'
    Allow:
      description: Methods available for the requested path, including OPTIONS.
      schema:
        type: string
  responses:
    JobAccepted:
      description: >-
        Queued for background execution. Wait for Retry-After before polling
        Location.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/JobReceipt'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        Location:
          description: Relative path to poll with GET.
          schema:
            type: string
            format: uri-reference
        Retry-After:
          $ref: '#/components/headers/Retry-After'
    BadRequest:
      description: >-
        A field failed validation (invalid_value, model_not_found or
        unsupported_value), the body could not be read (null), a content check
        failed (content_policy_violation), or the job input was malformed
        (invalid_input).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Choose a temperature from 0 to 2.
              type: invalid_request_error
              param: temperature
              code: invalid_value
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
    Unauthorized:
      description: >-
        The message distinguishes a missing token, a key without the smai_
        prefix and an unknown or revoked ShareMyAI token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                Send your API token as Authorization: Bearer smai_…. Create one
                at https://sharemy.ai, account panel, API tokens.
              type: invalid_request_error
              param: null
              code: invalid_api_key
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
    InsufficientCredits:
      description: The balance is less than the job's price.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                This costs 8.192 credits and your balance is 3.000 credits. Add
                credits at https://sharemy.ai.
              type: insufficient_quota
              param: null
              code: insufficient_quota
              price_credits: 8.192
              balance_credits: 3
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
    Suspended:
      description: The account is suspended.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                This account is suspended. If you think that is a mistake,
                contact us.
              type: invalid_request_error
              param: null
              code: account_suspended
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    MethodNotAllowed:
      description: The path exists. Use a method listed in Allow (method_not_allowed).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        Allow:
          $ref: '#/components/headers/Allow'
    TooManyCalls:
      description: >-
        Four job calls are already in flight across the account's tokens, or
        eligible machines stayed busy for 10 minutes. Both return
        rate_limit_exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: At most 4 API calls at once. Wait for one to finish.
              type: invalid_request_error
              param: null
              code: rate_limit_exceeded
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
    Cancelled:
      description: >-
        The caller hung up before the job finished. The job was dropped and its
        credits returned.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    NetworkError:
      description: >-
        The job failed on the network, for example after three machines in turn
        left or stopped answering. Its credits were returned.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                The machine running this left the network. (request
                69ba81e5-6a67-4cd5-a28b-2e023337b936)
              type: api_error
              param: null
              code: network_error
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        X-ShareMyAI-Max-Tokens:
          $ref: '#/components/headers/X-ShareMyAI-Max-Tokens'
    ImageUnavailable:
      description: >-
        no_provider when no eligible machine can run a synchronous job.
        storage_unavailable when async result storage is unavailable at
        submission. Retry-After and x-should-retry apply to no_provider.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      headers:
        x-request-id:
          $ref: '#/components/headers/x-request-id'
        x-ratelimit-limit-concurrent:
          $ref: '#/components/headers/x-ratelimit-limit-concurrent'
        x-ratelimit-remaining-concurrent:
          $ref: '#/components/headers/x-ratelimit-remaining-concurrent'
        X-ShareMyAI-Cost-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Cost-Credits'
        X-ShareMyAI-Balance-Credits:
          $ref: '#/components/headers/X-ShareMyAI-Balance-Credits'
        x-should-retry:
          $ref: '#/components/headers/x-should-retry'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        An API token from the account panel on sharemy.ai. Tokens start with
        `smai_`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.