NovelAI SDKNovelAI SDKunofficial
Examples

Inpainting

Regenerate a masked area of an image.

Regenerate a masked area of an existing image. Use a mask image to specify which parts of the image to regenerate while keeping the rest intact.

Basic Example

from novelai.types import GenerateImageParams, InpaintParams

inpaint_params = InpaintParams(
    image="source.png",   # Source image (file path, Base64, or PIL Image)
    mask="mask.png",      # Mask image (white=inpaint, black=keep)
    strength=1.0,
)

# Model is automatically switched to the inpainting variant
# (e.g. nai-diffusion-4-5-full -> nai-diffusion-4-5-full-inpainting)
params = GenerateImageParams(
    prompt="1girl, standing, smile",
    model="nai-diffusion-4-5-full",
    inpaint=inpaint_params,
)

# images = client.image.generate(params)

Mask Format

  • White (#FFFFFF): Area to regenerate (inpaint)
  • Black (#000000): Area to keep unchanged

The mask is automatically preprocessed (binarized and resized) to match the API requirements.

Parameters

  • image (required): Source image
  • mask (required): Mask image defining the inpaint region
  • strength: Inpainting strength (0.011.0, default: 1.0)
  • seed: Random seed (auto-generated if omitted)

The model is automatically switched to the inpainting variant (e.g., nai-diffusion-4-5-fullnai-diffusion-4-5-full-inpainting). You don't need to specify it manually.

Tip

For best results, make the mask slightly larger than the area you want to change. This gives the model more context for seamless blending.

On this page