Generation tools¶
Three tools that produce images from a text prompt — pure text-to-image,
image-conditioned (img2img), and mask-conditioned (inpaint). All three
return a base64 Image block plus the saved file path.
generate_image¶
Text-to-image. The most common tool — produces one or more images from a prompt string. Supports NovelAI V3 / V4 / V4.5 models, multi-character composition, and vibe transfer.
Parameters¶
Name |
Type |
Default |
Notes |
|---|---|---|---|
|
|
required |
Positive prompt. Tags separated by commas. |
|
|
|
Negative prompt (UC). |
|
|
|
Override model id. See |
|
|
|
Image width (px). Multiple of 64. |
|
|
|
Image height (px). Multiple of 64. |
|
|
|
Sampler steps (1–50). |
|
|
|
CFG scale (0–20). |
|
|
|
Sampler id (see |
|
|
|
RNG seed. |
|
|
|
Number of images (1–8). |
|
|
|
Use the quality tags preset (V4+). |
|
|
|
Negative-prompt preset (0=heavy, 1=light, 2=human focus). |
|
|
|
CFG rescale (0–1, V4+). |
|
|
model-dependent |
Enable SMEA. |
|
|
model-dependent |
Enable dynamic SMEA. |
|
|
|
Auto-select SMEA based on resolution. |
|
|
|
Prefer Brownian noise schedule (V4+). |
|
|
|
Noise schedule ( |
|
|
|
V4+ multi-character composition. |
|
|
|
V4+ vibe tokens (base64 vibe strings from |
Returns¶
list[ContentBlock] — base64 Image + saved-path text.
Example¶
# Simple text-to-image
await ctx.session.call_tool("generate_image", {
"prompt": "a fox in a snowy forest, masterpiece, best quality",
"negative_prompt": "lowres, bad anatomy, watermark",
"width": 832,
"height": 1216,
"steps": 28,
"scale": 5.0,
"seed": 42,
})
Multi-character composition (V4+)¶
await ctx.session.call_tool("generate_image", {
"prompt": "two characters talking in a cafe",
"character_prompts": [
{"prompt": "1girl, red hair, blue eyes", "x": 0.3, "y": 0.5, "negative_prompt": ""},
{"prompt": "1boy, black hair, green eyes", "x": 0.7, "y": 0.5, "negative_prompt": ""},
],
})
x and y are normalized centers in the range 0.1–0.9. The first
character is always the focal subject.
Vibe transfer (V4+)¶
# 1. Encode a reference image
vibe = await ctx.session.call_tool("encode_vibe", {"reference": ref_b64})
# 2. Use the vibe as a reference
await ctx.session.call_tool("generate_image", {
"prompt": "1girl, watercolor style",
"references": [vibe],
})
See vibe transfer tutorial for the full workflow.
image_to_image¶
Image-to-image. Produces a new image conditioned on an input image.
Parameters¶
Name |
Type |
Default |
Notes |
|---|---|---|---|
|
|
required |
Positive prompt. |
|
|
required |
Base64-encoded input PNG/JPEG. |
|
|
|
Negative prompt. |
|
|
default |
Model id. Must match the input image domain. |
|
|
|
0.01–0.99. How far to deviate from the input. |
|
|
|
0–0.99. Extra variation. |
|
(see |
(same defaults) |
|
|
|
|
Separate seed for noise (defaults to |
Example¶
await ctx.session.call_tool("image_to_image", {
"prompt": "1girl, masterpiece, smile",
"image": image_b64,
"strength": 0.4,
"noise": 0.05,
})
Tip
strength=0.5 is a good starting point. Below 0.3, the result looks like a
re-denoise of the input; above 0.7, it drifts toward a fresh text-to-image.
inpaint¶
Locally redraw a region of an image. The region is defined by a mask — non-transparent pixels are regenerated.
Parameters¶
Name |
Type |
Default |
Notes |
|---|---|---|---|
|
|
required |
Prompt for the regenerated region. |
|
|
required |
Base64-encoded input PNG/JPEG. |
|
|
required |
Base64-encoded mask. Non-transparent = redraw. |
|
|
|
Negative prompt for the region. |
|
|
default |
Must be an inpaint model (e.g. |
|
(see |
(same defaults) |
Example¶
await ctx.session.call_tool("inpaint", {
"prompt": "1girl, masterpiece, smiling",
"image": image_b64,
"mask": mask_b64,
"model": "nai-diffusion-4-5-full-inpainting",
"strength": 0.5,
})
Warning
Inpainting requires a dedicated inpaint model. Calling inpaint with a
non-inpaint model returns a NovelAIValidationError. Use
is_inpaint_model (in the nai.constants submodule) to
check before calling.
See inpaint tutorial for a mask-creation walkthrough.
See also¶
Configuration — defaults applied when a parameter is omitted