Nodes/ComfyUI-KLingAI-API/Image Expander
ComfyUI Node

Image Expander

KLing's generative outpainting, one edge at a time

By KlingAIResearch·Created 2 years ago·Updated 10 months ago· 174
Image Expander
  • client
  • image
  • image
up_expansion_ratio0.00
down_expansion_ratio0.00
left_expansion_ratio0.00
right_expansion_ratio0.00
prompt
image_num1

This is KLing's answer to Photoshop's generative expand, or the outpainting workflows people build locally with a big canvas and an inpainting checkpoint - except here it's a single API call. Feed it an image and tell it how far to push each edge, and KLing's model fills in the newly exposed canvas convincingly, matching the lighting, perspective, and content of the original. Reach for it when you need to reframe a shot - turn a square product photo into a 16:9 banner, or pull a subject out from a tight crop - without hand-building an outpainting graph.

How it works

Instead of a single "expand" percentage, you set four independent ratios - one per edge - so you can push a canvas out asymmetrically: extend the sky above a landscape without touching the ground, or widen both sides evenly for a banner crop while leaving top and bottom untouched. KLing's servers handle the actual generation of the new content; there's no local diffusion pass, no mask painting, no separate outpaint checkpoint to manage.

The inputs and outputs that matter

Required:

  • image - the source you're expanding.
  • up_expansion_ratio, down_expansion_ratio, left_expansion_ratio, right_expansion_ratio - each 0–2, default 0. Zero means "don't touch this edge"; higher values push that edge out further, up to 2x the original dimension on that side.

Optional:

  • prompt - steer what fills the new area. Leave it blank and KLing infers content from the existing image; fill it in when you want the expanded region to contain something specific rather than just a plausible continuation of the scene.
  • image_num (0–9) - how many candidate expansions come back in one call, useful when you want a few options to pick from rather than committing to the first result.

Output is a single image per generated candidate, ready for a Preview/Save Image node or further compositing.

Installing it

ComfyUI Manager: search ComfyUI-KLingAI-API, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/KwaiVGI/ComfyUI-KLingAI-API
cd ComfyUI-KLingAI-API && pip install -r requirements.txt

No local model download - you need a Client node upstream with a valid KLing AI API key, region-matched via area to your account.

Common issues

The ratios are the thing to get right first: leave all four at 0 and you've asked the model to do nothing, which is an easy mistake when copy-pasting a workflow and forgetting to set the edges you actually want expanded. It's also worth expanding in modest steps rather than maxing every ratio to 2 in one shot - a huge expansion in a single call gives the model more blank canvas to invent content for, and the seams between real and generated content tend to get more visible the further you push it. If the newly generated area doesn't match the lighting or perspective of the original well, a short, specific prompt describing what should logically continue into that space (rather than leaving it blank) usually helps more than re-rolling with image_num. And as with every node here, the failure underneath any of this not working at all is almost always the Client upstream - bad key, wrong area, or an empty KLing account balance.

CategoryKLingAI

Inputs (8)

NameTypeDefaultDescription
clientKLING_AI_API_CLIENT
imageIMAGE
up_expansion_ratioFLOAT0.000–2
down_expansion_ratioFLOAT0.000–2
left_expansion_ratioFLOAT0.000–2
right_expansion_ratioFLOAT0.000–2
promptoptSTRING
image_numoptINT10–9

Outputs (1)

NameTypeDescription
imageIMAGE