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": "98761286-cdc7-4085-abfe-c9f149ff722b",
    "model": "midjourney",
    "task_type": "inpaint",
    "status": "completed",
    "config": {
        "service_mode": "public",
        "webhook_config": {
            "endpoint": "https://webhook.site/d0ca59bc-35a6-4a1e-b1b1-aea7faeb7f67",
            "secret": ""
        }
    },
    "input": null,
    "output": {
        "image_url": "",
        "image_urls": [
            "https://image.legnext.ai/20250922/01k5qp2gqrfef8761r8n9q9w0c_0_0.png?Expires=1761102268&Signature=iNZM9BV0OCS32GXCSYEruuCs7zU%3D",
            "https://image.legnext.ai/20250922/01k5qp2gqrfef8761r8n9q9w0c_0_1.png?Expires=1761102268&Signature=6X1d2iMRXXn1afdYEKrAHKRAZW0%3D",
            "https://image.legnext.ai/20250922/01k5qp2gqrfef8761r8n9q9w0c_0_2.png?Expires=1761102268&Signature=clTVka9lszWiHZckseM%2BFafgbmc%3D",
            "https://image.legnext.ai/20250922/01k5qp2gqrfef8761r8n9q9w0c_0_3.png?Expires=1761102268&Signature=dH98ACZ%2FxBkvpsOD9BjmJpE4WN4%3D"
        ]
    },
    "meta": {
        "created_at": "2025-09-22T03:04:27Z",
        "started_at": "2025-09-22T03:04:28Z",
        "ended_at": "2025-09-22T03:05:03Z",
        "usage": {
            "type": "point",
            "frozen": 00,
            "consume": 00
        }
    },
    "detail": null,
    "logs": [],
    "error": {
        "code": 0,
        "raw_message": "",
        "message": "",
        "detail": null
    }
}