Reference Conditioning
Give your Flux Kontext workflow a reference image the Kontext way
- conditioning
- pixels
- vae
- mask
- conditioning
- image
- mask
- latent
Flux Kontext is an in-context editor: it doesn't inject your reference image through adapter embeddings the way IP-Adapter or PuLID do. It concatenates the image into the model's context alongside the prompt, so identity is preserved structurally rather than averaged through a learned adapter. That's why it holds a subject across a chain of edits where adapter approaches drift. Reference Conditioning (from comfyui-ysnodes) is the ComfyUI building block for that style - it encodes your reference image and attaches it to your existing conditioning so a Kontext-style model actually sees it.
To be clear about what it is not: it doesn't load Kontext, download a checkpoint, or do any editing itself. It's the conditioning glue. If you already have a Kontext workflow or a model that reads reference_latents, this replaces the VAEEncode + ReferenceLatent + pre-scaling stack with one node.
How it works
The pipeline mirrors ComfyUI core's ReferenceLatent node exactly:
- Optionally scale the reference image to a target
megapixels(this is the bit stock nodes make you do by hand). VAEEncodeit with the connected VAE.- Append the encoded latent to your conditioning's
reference_latentslist - the field in-context models read.
There's a parallel path for an optional mask, scaled with the same method and target so the reference and mask stay aligned. The mask comes back as zeros when not connected.
Inputs and outputs
The core set:
conditioning- what you're attaching the reference to. Works for positive or negative conditioning, so you can reference the same image on both sides.pixels- the reference image.vae- required, unlike the pack's scaling nodes. No VAE, no encoding, no node.enable_megapixels(default on),megapixels,multiple- whether to normalize the reference size before encoding. Leaving it on at ~1 MP is usually right; turning it off uses your image exactly as-is, which you want when the reference is already at the model's native resolution.
Outputs: conditioning (the attached version), plus image, mask, and latent passthroughs of the scaled/encoded reference - useful for previewing what the model is actually seeing.
Installing it
Standard zero-dependency install for this pack - no models, no pip packages.
cd ComfyUI/custom_nodes
git clone https://github.com/MrYassinox/comfyui-ysnodes.git
or search comfyui-ysnodes in ComfyUI Manager, restart, and it's under YSNodes/conditioning.
The honest caveat
Attaching a reference latent only does anything if the model you're sampling with consumes reference_latents. On a vanilla Flux Dev checkpoint, this node runs fine and changes nothing - the reference just sits in the conditioning, unread. Which is the actual mechanism difference worth internalizing: Kontext-style conditioning is structural (the image is in the context), so it's tightly coupled to models that know the format. If you're on a plain checkpoint and want style/subject transfer, you want an adapter approach like IP-Adapter instead. Also worth knowing: Kontext's license-era NSFW crackdown and its history of anatomy degradation at full-body scale apply regardless of what node you build the conditioning with - the reference node is neutral plumbing, the model's limitations come along for the ride.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| conditioning | CONDITIONING | Conditioning to attach the reference latent to. Works for positive or negative conditioning. | |
| pixels | IMAGE | Reference image to encode and attach as a latent reference. | |
| vae | VAE | VAE model used to encode the reference image. Required. | |
| upscale_method | COMBO | nearest-exact | Interpolation method used when scaling. |
| megapixels | FLOAT | 1.000.01–64 | Target resolution in megapixels when enable_megapixels=True. The image is scaled so width × height ≈ megapixels × 1,048,576, preserving aspect ratio. |
| multiple | INT | 88–128 | Nearest multiple to round the scaled width/height to. 8 = VAE-safe (recommended). |
| enable_megapixels | BOOLEAN | true | True → scale pixels and mask to target megapixels before encoding. False → use pixels and mask unchanged. |
| maskopt | MASK | Optional mask. Scaled with the same method and target MP as pixels. Returns zeros when not connected. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| conditioning | CONDITIONING | — |
| image | IMAGE | — |
| mask | MASK | — |
| latent | LATENT | — |