Skip to content
Haoming edited this page Apr 29, 2025 · 3 revisions

To use IC-Light via API, add an "IC Light" object to the "alwayson_scripts" array in your payload, with the following 13 values:

  • enable: (bool) Enable 💀
  • model_type: (str) The fc/fbc model name on disk (without extension)
  • input_fg: (str) The subject image (for txt2img) or the lighting image (for img2img) in base64 format
  • uploaded_bg: (str) The background image specifically for the fbc mode in txt2img
  • remove_bg: (bool) Enable to remove the background from the input_fg
  • rembg_model: (str) The rembg model name
    • see here for the list of all models
  • foreground_threshold: (int) refer to rembg for what this does...
  • background_threshold: (int) refer to rembg for what this does...
  • erode_size: (int) refer to rembg for what this does...
  • detail_transfer: (bool) Enable to transfer details using DoG
  • detail_transfer_raw: (bool) Enable to use the raw input_fg to transfer details
  • detail_transfer_blur_radius: (int) Blur radius for DoG
  • reinforce_fg: (bool) Enable to additionally paste the input image onto the input_fg, specifically for img2img
Example Script
from PIL import Image
import requests
import base64
import io


def img2base64(image: Image.Image) -> str:
    with io.BytesIO() as output_bytes:
        image.save(output_bytes, format="JPEG", quality=100, optimize=True)
        bytes_data = output_bytes.getvalue()
    return base64.b64encode(bytes_data).decode("utf-8")


image = Image.open("./subject_input.jpg")
subject = img2base64(image)

payload = {
    "prompt": "high quality, best quality, a photo of a gentleman in suit, standing under sunset",
    "negative_prompt": "worst quality, bad quality, low quality",
    "sampler_name": "DPM++ 2M Karras",
    "steps": 32,
    "width": 512,
    "height": 512,
    "cfg_scale": 7.5,
    "alwayson_scripts": {
        "IC Light": {
            "args": [
                True,
                "IC-Light-SD15-FC-fp8",
                subject,
                None,
                True,
                "u2net_human_seg",
                225,
                16,
                16,
                False,
                False,
                3,
                False,
            ]
        }
    },
}

url = "http://127.0.0.1:7860"
response = requests.post(url=f"{url}/sdapi/v1/txt2img", json=payload)
r = response.json()

with open("./api_output.png", "wb") as f:
    f.write(base64.b64decode(r["images"][0]))

Clone this wiki locally