Nodes/Comfyui-Gelbooru/Gelbooru (ID)
ComfyUI Node

Gelbooru (ID)

Pull tags and an image off Gelbooru

By 1mckw·Created 2 years ago·Updated 2 months ago· 11
Gelbooru (ID)
    • imgtags
    • imgurl
    • imgid
    • width
    • height
    • source
    • IMAGE
    post_id
    use_last_promptfalse
    return_picturefalse

    You know that feeling: you're browsing Gelbooru, you see a composition you want to riff on, and you think "I wish I had the prompt for this." Gelbooru (ID) is exactly that node. Paste a numeric post ID, and it hands you the post's tags, its direct image URL, dimensions, and source - plus the image itself if you ask. It's the quiet one in the Comfyui-Gelbooru pack (siblings are Gelbooru (Random) and UrlsToImage), but it's the one that feels like magic the first time you wire its tag string straight into a positive prompt and get the character back.

    Why this works at all is worth understanding. Illustrious, NoobAI, and the other Danbooru-trained anime models speak booru tag vocabulary natively - 1girl, long_hair, blue_eyes are literal tokens they were trained on. So a real post's tags are a better prompt than anything you'd freehand. Gelbooru's tags are the same lineage as Danbooru's, just a different board, so the output plugs straight into that ecosystem.

    How it works

    Under the hood it's a single request to Gelbooru's public API - page=dapi&s=post&q=index&id=<id>&json=1. No API key needed, which is a nice contrast to the Random node: the ID lookup endpoint is open. The response tags come space-separated, so the node converts them to comma-separated, and it also grabs file_url, dimensions, and source. The last result is cached to a local gelbooru_prompt_cache.json so use_last_prompt can reuse it without hitting the network again.

    One thing the code handles for you: Gelbooru image URLs are served from a CDN and go stale. If the download fails, the node re-queries the post for a fresh URL and retries before giving up and returning a gray "gelbooru not available" placeholder.

    The inputs and outputs that matter

    Only three inputs, all simple:

    • post_id - the numeric ID, grab it from the post URL on gelbooru.com
    • use_last_prompt - reuse the previous response instead of re-fetching; handy while you tweak the rest of the workflow
    • return_picture - toggle this to also download the image as an IMAGE tensor

    Outputs: imgtags (the comma-separated tag string - wire it into a CLIP Text Encode positive prompt), imgurl, imgid, width, height, source, and IMAGE. With return_picture off, the IMAGE output is a blank 1x1 tensor, so don't feed that into a VAE Encode expecting art.

    Install

    Via ComfyUI Manager, search "Comfyui-Gelbooru". Or the manual way:

    cd ComfyUI/custom_nodes
    git clone https://github.com/1mckw/Comfyui-Gelbooru.git
    

    Then from the ComfyUI root, install its requirements (requests and boto3 - light, no models to download):

    python_embeded\python.exe -m pip install -r custom_nodes\Comfyui-Gelbooru\requirements.txt
    

    Restart ComfyUI and the three "Gelbooru" category nodes appear. (On a normal Python install, swap in python -m pip.)

    Gotchas

    The most common stumble: you get a gray "gelbooru not available" image. That means the file download failed - usually an expired CDN URL or a hotlink-referrer hiccup. Re-run with use_last_prompt off so it re-fetches. Also: an invalid or deleted post ID returns nothing but blank strings, so double-check the ID if your prompt comes out empty. And remember the tags belong in a Danbooru-trained model's prompt - feeding them into Flux or a natural-language model will give you mush.

    CategoryGelbooru

    Inputs (3)

    NameTypeDefaultDescription
    post_idSTRINGNumeric ID of the Gelbooru post to fetch
    use_last_promptBOOLEANfalseReuse the previous API response without making a new request
    return_pictureBOOLEANfalseDownload the post's image and output as IMAGE tensor

    Outputs (7)

    NameTypeDescription
    imgtagsSTRINGAll tags of the fetched post, comma-separated
    imgurlSTRINGDirect file URL of the image
    imgidSTRINGPost ID on the image board
    widthINTWidth of the image in pixels
    heightINTHeight of the image in pixels
    sourceSTRINGSource website URL of the post
    IMAGEIMAGEImage tensor (only populated when return_picture is enabled)