Skip to main content
POST
/
v1
/
inpaint
Inpaint
curl --request POST \
  --url https://api.legnext.ai/api/v1/inpaint \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "jobId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "imageNo": 0,
  "mask": {
    "areas": [
      {
        "width": 2298,
        "height": 2298,
        "points": [
          123
        ]
      }
    ],
    "url": "<string>"
  },
  "remixPrompt": "<string>",
  "callback": "<string>"
}
'
Repaint or modify specific regions within an existing generated image using mask-based editing.

Endpoint

POST https://api.legnext.ai/api/v1/inpaint

Headers

HeaderTypeRequiredDescription
x-api-keystringYesYour API key

Request Body

ParameterTypeRequiredDescription
jobIdstringYesID of the original image generation task
imageNointegerYesImage number to edit (0/1/2/3)
maskMaskYesRegions to repaint
remixPromptstringNoText prompt for the repaint area (1-8192 characters)
areaPolygonNoSingle polygon area to repaint (deprecated, use mask instead)
callbackstringNoCallback URL for task completion notifications

Data Types

Mask

Choose one of the following methods to define the repaint area:
FieldTypeDescription
areasPolygon[]Array of polygonal areas to repaint
urlstringBlack and white mask image URL (white areas will be repainted)

Polygon

FieldTypeDescription
widthintegerImage width in pixels (500-4096)
heightintegerImage height in pixels (500-4096)
pointsinteger[]Polygon coordinates in XYXY format, clockwise from top-left

Example Request

Using Polygon Areas

curl -X POST "https://api.legnext.ai/api/v1/inpaint" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jobId": "5dd94ec3-7282-4f04-9445-59e850ef1822",
    "imageNo": 0,
    "mask": {
        "areas": [
            {
                "width": 500,
                "height": 500,
                "points": [
                    10,
                    10,
                    10,
                    100,
                    100,
                    100,
                    100,
                    10
                ]
            }
        ]
    },
    "remixPrompt": "Add a tree in the center",
    "callback": "https://webhook.site/c98cb890-fb92-439f-8d60-42c8a51eb52d"
  }'

Using Mask Image

{
  "jobId": "job_12345",
  "imageNo": 0,
  "remixPrompt": "Add autumn leaves",
  "mask": {
    "url": "https://example.com/mask-image.png"
  },
  "callback": "https://your-domain.com/webhook"
}

Response

Returns a task object containing the task information.
{
    "job_id": "72e20f1a-6c76-4ec5-bda2-490016056fa8",
    "model": "midjourney",
    "task_type": "inpaint",
    "status": "completed",
    "config": {
        "service_mode": "public",
        "webhook_config": {
            "endpoint": "https://webhook.site/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "secret": ""
        }
    },
    "input": null,
    "output": {
        "image_url": "https://cdn.legnext.ai/temp/1760415460188.png",
        "image_urls": [
            "https://cdn.legnext.ai/mj/72e20f1a-6c76-4ec5-bda2-490016056fa8_0.png",
            "https://cdn.legnext.ai/mj/72e20f1a-6c76-4ec5-bda2-490016056fa8_1.png",
            "https://cdn.legnext.ai/mj/72e20f1a-6c76-4ec5-bda2-490016056fa8_2.png",
            "https://cdn.legnext.ai/mj/72e20f1a-6c76-4ec5-bda2-490016056fa8_3.png"
        ],
        "seed": "1573740627",
        "available_actions": {
            "edit": [
                0,
                1,
                2,
                3
            ],
            "inpaint": [
                0,
                1,
                2,
                3
            ],
            "outpaint": [
                0,
                1,
                2,
                3
            ],
            "pan": [
                0,
                1,
                2,
                3
            ],
            "remix": [
                0,
                1,
                2,
                3
            ],
            "reroll": true,
            "upscale": [
                0,
                1,
                2,
                3
            ],
            "variation": [
                0,
                1,
                2,
                3
            ]
        }
    },
    "meta": {
        "created_at": "2025-10-14T04:14:22Z",
        "started_at": "2025-10-14T04:14:23Z",
        "ended_at": "2025-10-14T04:17:43Z",
        "usage": {
            "type": "point",
            "frozen": 120,
            "consume": 120
        }
    },
    "detail": null,
    "logs": [],
    "error": {
        "code": 0,
        "raw_message": "",
        "message": "",
        "detail": null
    }
}

Authorizations

x-api-key
string
header
required

API key for authentication

Body

application/json
jobId
string<uuid>
required

ID of the original image generation task

imageNo
integer
required

Image number to edit (0, 1, 2, or 3)

Required range: 0 <= x <= 3
Example:

0

mask
object
required

Regions to repaint (use either areas or url)

remixPrompt
string

Text prompt for the repaint area

Required string length: 1 - 8192
callback
string<uri>

Callback URL for task completion notifications

Response

200

Inpaint task created successfully