POST
/
v3
/
async
/
inpainting
curl --request POST \
  --url https://api.novita.ai/v3/async/inpainting \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: <content-type>' \
  --data '{
  "extra": {
    "response_image_type": "<string>",
    "webhook": {
      "url": "<string>",
      "test_mode": {
        "enabled": true,
        "return_task_status": "<string>"
      }
    },
    "custom_storage": {
      "aws_s3": {
        "region": "<string>",
        "bucket": "<string>",
        "path": "<string>",
        "save_to_path_directly": true
      }
    },
    "enterprise_plan": {
      "enabled": true
    },
    "enable_nsfw_detection": true,
    "nsfw_detection_level": 123
  },
  "request": {
    "model_name": "<string>",
    "image_base64": "<string>",
    "mask_image_base64": "<string>",
    "prompt": "<string>",
    "image_num": 123,
    "steps": 123,
    "guidance_scale": {},
    "sampler_name": "<string>",
    "mask_blur": 123,
    "negative_prompt": "<string>",
    "sd_vae": "<string>",
    "seed": 123,
    "loras": [
      {
        "model_name": "<string>",
        "strength": {}
      }
    ],
    "embeddings": [
      {
        "model_name": "<string>"
      }
    ],
    "clip_skip": 123,
    "strength": {},
    "inpainting_full_res": 123,
    "inpainting_full_res_padding": 123,
    "inpainting_mask_invert": 123,
    "initial_noise_multiplier": {}
  }
}'
{
  "task_id": "<string>"
}

Inpainting is a conservation process in which damaged, deteriorated, or missing parts of an artwork are filled in to present a complete image.

This is an asynchronous API; only the task_id will be returned. You should use the task_id to request the Task Result API to retrieve the image generation results.

Request Headers

Content-Type
string
required

Enum: application/json

Authorization
string
required

Bearer authentication format, for example: Bearer {{API Key}}.

Request Body

extra
object

Optional extra parameters for the request.

request
object
required

Response

task_id
string

Use the task_id to request the Task Result API to retrieve the generated outputs.

Example

I have no mask images. How do I generate mask parameters in the body?

You can use our playground to get the mask base64 information. Please be aware that mask images should have the same resolution as the input images. Guidance can be found here: Click Here

I already have mask images. How do I convert mask images to base64?

You can use the following code to convert mask images to base64.

import base64
# mask files path
filename_input = "mask_edited.png"

# read mask file
with open(filename_input, "rb") as f:
    base64_pic = base64.b64encode(f.read()).decode("utf-8")

# write mask file
with open("input.txt", "w") as f:
    f.write(base64_pic)

Start requesting inpainting.

Please set the Content-Type header to application/json in your HTTP request to indicate that you are sending JSON data. Currently, only JSON format is supported.

"model_name":"realisticVisionV40_v40VAE-inpainting_81543.safetensors" in body represent inpainting models, which, can be accessed in API /v3/model with sd_name like %inpainting%.

Request:

curl --location --request POST 'http://api.novita.ai/v3/async/inpainting' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{API Key}}' \
--data-raw '{
    "extra": {
        "response_image_type": "jpeg"
    },
    "request": {
        "model_name": "realisticVisionV40_v40VAE-inpainting_81543.safetensors",
        "prompt": "Leonardo DiCaprio",
        "negative_prompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, BadDream, UnrealisticDream",
        "image_num": 1,
        "steps": 25,
        "seed": -1,
        "clip_skip": 1,
        "guidance_scale": 7.5,
        "sampler_name": "Euler a",
        "mask_blur": 1,
        "inpainting_full_res": 1,
        "inpainting_full_res_padding": 32,
        "inpainting_mask_invert": 0,
        "initial_noise_multiplier": 1,
        "strength": 0.85,
        "image_base64": "{{base64 encoded image}}",
        "mask_image_base64": "{{base64 encoded mask image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "270f4fba-2cb0-4a56-8b82-xxxx"
    }
}
````"model_name":"realisticVisionV40_v40VAE-inpainting_81543.safetensors"` in body represent inpainting models, which, can be accessed in API /v3/model with `sd_name` like %inpainting%.

`Request:`
```bash
curl --location --request POST 'http://api.novita.ai/v3/async/inpainting' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{API Key}}' \
--data-raw '{
    "extra": {
        "response_image_type": "jpeg"
    },
    "request": {
        "model_name": "realisticVisionV40_v40VAE-inpainting_81543.safetensors",
        "prompt": "Leonardo DiCaprio",
        "negative_prompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, BadDream, UnrealisticDream",
        "image_num": 1,
        "steps": 25,
        "seed": -1,
        "clip_skip": 1,
        "guidance_scale": 7.5,
        "sampler_name": "Euler a",
        "mask_blur": 1,
        "inpainting_full_res": 1,
        "inpainting_full_res_padding": 32,
        "inpainting_mask_invert": 0,
        "initial_noise_multiplier": 1,
        "strength": 0.85,
        "image_base64": "{{base64 encoded image}}",
        "mask_image_base64": "{{base64 encoded mask image}}"
    }
}'

Response:

{
    "code": 0,
    "msg": "",
    "data": {
        "task_id": "270f4fba-2cb0-4a56-8b82-xxxx"
    }
}