Skip to main content

Inpainting


Inpainting

POST https://api.novita.ai/v3/async/inpainting

Inpainting is a conservation process where 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 at https://novita.ai/reference/task/task.htmlopen in new window to retrieve the image generation results.

Request header parameters

  • Authorizationstring

  • Content-TypestringRequired

    application/json

Request Body parameters

  • extraobject

    extra infos.

    Show properties
  • requestobjectRequired

    Show properties

Responses

  • task_idstring

Example

I have no mask images, how to generate mask parameters in body?

You can use our playground to get the mask base64 info, please be aware that mask images should be the same resolution with input images, guidance here: Click Hereopen in new window

novita.ai API

I already have mask images, how to transfer mask images to base64?

You can use the following code to transfer 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 for 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 {{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_fill": 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-f007284143bd"
    }
}