Nodes/ComfyUI_RS_NAI_API_Request/NAI Reference Inset
ComfyUI Node

NAI Reference Inset

The free half of reference-guided inpainting

By raspie10032·Created 2 years ago·Updated about 15 hours ago· 10
NAI Reference Inset
  • image
  • inset
  • canvas
  • generation_mask
◄canvas_width1216►
◄canvas_height832►
◄placementleft►
◄reference_percent50►

Here's the trick this node implements, and it's a good one. Paste your reference image onto one side of a canvas, leave the other side blank, and tell NovelAI to inpaint the blank side while it can see the reference. The model paints a new scene next to your character, referencing it as it goes, and you crop the new part out. That's NovelAI's own advanced reference-inpainting guide, and it's the pack's answer for "keep this character, put it somewhere else."

This node is the preparation half. It builds the canvas and the mask, entirely on your machine. No API token, no request, no Anlas. Only its partner node generates. So you can hammer this one as much as you like while you dial in sizes.

What it builds

You give it one image. It fits that image inside its allotted slice of the canvas without stretching or cropping - scale by the limiting dimension, LANCZOS resize, centred. Transparency gets composited onto white, and a thin black border is drawn around the reference so the model can see where the reference ends and the fresh canvas begins. Everything outside the reference is white, and the mask is 255 over the area to be generated and 0 over the reference.

  • image - one image. The tooltip says it plainly: fits without stretching or cropping, transparency composited on white.
  • canvas_width / canvas_height - the whole canvas, reference included. Defaults 1216 and 832, allowed 64–4096 in steps of 64.
  • placement - left, right, top, or bottom. The side the reference occupies; the other side is what gets generated.
  • reference_percent - 10–75, default 50. How much of the canvas the reference gets.

Outputs, and they're an odd little trio:

  • inset - type RS_NAI_INSET. This is the bundle (canvas, mask, crop box). Nothing but NAI Reference Inset Generate understands it; don't try to preview it.
  • canvas - the actual composed IMAGE. Wire it to Preview or Save if you want to see it.
  • generation_mask - a MASK, white where the model will paint. Run it through Convert Mask to Image and a Preview node if you want to eyeball the split.

The size maths that confuses everyone

Canvas dimensions include the reference, so the thing you end up with is smaller than what you typed. At the defaults - 1216×832, 50% on the left - the generated crop is 608×832. Move the reference to the top and it's 1216×416.

The node displays both numbers live in its own UI as you change the widgets. If a dimension is coming from another node, the display can't know it, so it says "run to preview" and you should actually execute the node to see the result - it's an output node, so it renders a preview without needing anything downstream.

Which brings up the one genuinely fiddly detail: the canvas must be a multiple of 64 (the API requires it, and the node enforces it), but the percentage split rounds to the nearest pixel, so your cropped output often won't be a multiple of 64. That's fine and intentional. The crop is exact and is never resized afterwards.

And the trade the whole node is built around: smaller reference space gives you a bigger output but weaker consistency. 50% is a reasonable starting point; 75% keeps the character tight and hands you a skinny little strip to generate into.

Install

Ships with the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/raspie10032/ComfyUI_RS_NAI_API_Request.git
cd ComfyUI_RS_NAI_API_Request
python -m pip install -r requirements.txt

Or ComfyUI Manager → search ComfyUI_RS_NAI_API_Request → Install → restart. requirements.txt is the pack's whole dependency set (requests, Pillow, numpy, python-dotenv, torch, segment-anything), so it's a chunky install even though this node only needs Pillow and numpy under the hood.

Load Image → NAI Reference Inset → (inset) → NAI Reference Inset Generate
                        canvas ─────→ Preview Image
                        generation_mask → Convert Mask to Image → Preview Image

Where people get burned

Feeding it a batch. One image per node - the pack rejects batches across its image inputs rather than silently taking frame one.

Expecting a 64-multiple output. Covered above, but it's the most common "is this a bug?" question. It isn't. The API canvas is aligned; the crop is exact.

Treating the canvas output as the result. canvas is reference-plus-blank-something. It's for previewing and for the generate node's own compositing step. The finished image comes out of the other node, cropped.

Forgetting it's the cheap node. If you're testing composition ideas, this is where you iterate. Sizes, side, percentage - all free. Only when the layout is right do you go spend Anlas on the generate side, and that node will refuse until you explicitly tell it you're okay with spending.

CategoryRS_NovelAI_API/Reference Inset

Inputs (5)

NameTypeDefaultDescription
imageIMAGEOne reference image. Fits without stretching or cropping; transparency is composited on white.
canvas_widthINT121664–4096Whole canvas including the reference. The cropped output will be smaller.
canvas_heightINT83264–4096Whole canvas including the reference. The cropped output will be smaller.
placementCOMBOleftSide occupied by the reference. The other side is generated.
reference_percentINT5010–75Percentage reserved for the reference. Smaller reference space gives a larger output, but may weaken consistency.

Outputs (3)

NameTypeDescription
insetRS_NAI_INSET—
canvasIMAGE—
generation_maskMASK—