Nodes/Anima-Tools/Anima Danbooru Random Image
ComfyUI Node

Anima Danbooru Random Image

A Random Danbooru Image That Hands You Its Own Prompt

By nregret·Created 5 months ago·Updated a day ago· 411
Anima Danbooru Random Image
    • image
    • artist
    • character
    • copyright
    • general
    • prompt
    • meta
    ◄query_tagsrating:general►
    ◄seed-1►
    ◄sizesample►
    ◄tag_charactertrue►
    ◄tag_copyrighttrue►
    ◄tag_generaltrue►
    ◄tag_artistfalse►
    ◄tag_metafalse►
    ◄block_tags►
    ◄use_default_blocklisttrue►
    ◄max_attempts3►
    ◄login►
    ◄api_key►
    ◄cache_dir►
    ◄timeout20.00►
    ◄id_ceiling12500000►

    Most ComfyUI nodes are plumbing. This one is a prompting shortcut, and I mean that as a compliment: it pulls one random Danbooru post matching your query and hands back the image and that post's own tags, already formatted the way Anima wants to read them.

    Why you'd wire this up

    Danbooru tags are the working vocabulary of the whole anime model stack, and the part most people never learn. The board averages roughly thirty human tags per image - that density is why models trained on it respond to dutch angle and looking at viewer while shrugging at your carefully written sentence. Anima takes natural language and tags, but it learned this dataset, so real tags land harder than a paraphrase.

    Which makes reading real prompts the cheapest way to get better at writing them. Run it a dozen times with query_tags set to something you're studying. The image output is a genuine IMAGE, so it drops into img2img as reference, and seed = -1 gives a fresh post every queue.

    How the random part works

    The trap most "random image" scripts fall into is randomising a page number. Danbooru serves newest-first, so every upload batch shifts every page backwards and your reproducible seed stops reproducing anything within weeks.

    This node samples the post id space instead. A fixed seed derives an id anchor - sha1("danbooru-seed:<seed>:<attempt>") modulo id_ceiling - then asks for the nearest matching post at or below it. Ids only grow and are never reused, so the anchor can't get shoved off its spot. The window widens 200 → 2,000 → 20,000 → 200,000 before trying the next anchor. seed = -1 skips all of it for the site's own random draw. Animated and video posts get filtered client-side, deliberately not via -animated in your query, since that would burn a tag slot.

    The inputs worth setting

    Ten required widgets, but five are just "which tag groups do you want".

    • query_tags - your Danbooru search, default rating:general.
    • seed - -1 for a fresh draw each queue, a fixed number for reproducible.
    • size - stay on sample; original is often a 5 MB+ file you're only decoding as reference. Cache is keyed by size and md5.
    • tag_character / tag_copyright / tag_general - on by default, and the useful spine of a prompt.
    • tag_artist - off; enable it for style hunting. Artists come out @-prefixed, which is Anima's own convention.
    • tag_meta - leave off. highres, character_request, that sort of upload bookkeeping, and it pollutes a prompt.
    • block_tags / use_default_blocklist - defaults already drop artist_name, watermark, english_text. Wildcards work: *censor* kills both censored and bar censor.

    Outputs

    image, then artist / character / copyright / general as separate group strings, then prompt (all groups joined) and meta (JSON with id, md5, rating, score, source, image URL, cache hit - handy for logging).

    One caveat: prompt runs artist → character → copyright → general → meta, which isn't Anima's documented order (quality tags, count, character, series, artist, general). Mostly harmless for a DiT; if you want the card's recipe, wire the group outputs into a Text Concatenate yourself. The tags do arrive lowercase, underscores swapped for spaces, @ on artists - that is the card's rule set.

    Tag limits will bite you first

    Anonymous and free accounts get two tags. rating:* and id:* don't count against that; random:1, order:* and any -negation do.

    The escape hatch is nicer than it sounds: rating:general,sensitive,explicit is one OR term to Danbooru and costs zero slots. The node protects those inner commas instead of splitting them, so 1girl solo, rating:g,s,e works on a free account while 1girl solo random:1 gets a 422.

    Install

    Manager → Custom Nodes Manager, search Anima Tools, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nregret/Comfyui-Anima-Tools.git
    

    No model files, nothing to pip install - pyproject.toml declares dependencies = [], there's no requirements.txt, and the HTTP calls are stdlib urllib.

    When it doesn't work

    The first run hangs for a full timeout. On some networks danbooru.donmai.us resolves to garbage, and the built-in Cloudflare fallback is only tried after the normal request fails. Drop timeout to 6–10 to skip most of the wait.

    A fixed seed errors instead of producing anything. Check id_ceiling - default 12,500,000 needs to sit just above the site's current largest post id. Set it huge "for safety" and nearly every seed lands in empty space and spins. A fixed seed also only reaches posts that existed when you picked it; new uploads need -1.

    Changing the query doesn't re-roll. Intentional - unchanged inputs with a fixed seed return a cached result.

    Only animated posts match? It retries, then tells you. Loosen the query.

    Keep credentials out of the workflow. Leave login/api_key blank and use DANBOORU_LOGIN / DANBOORU_API_KEY. A key unlocks censored tags and favourites; it does not raise the tag limit.

    Otherwise the node is polite to a fault - robots.txt disallows /*.json, so a run is one search plus one image fetch.

    CategoryAnima/Danbooru

    Inputs (16)

    NameTypeDefaultDescription
    query_tagsSTRINGrating:general—
    seedINT-1-1–2147483647—
    sizeCOMBOsample5 options: sample, original, 720x720, 360x360, 180x180
    tag_characterBOOLEANtrue—
    tag_copyrightBOOLEANtrue—
    tag_generalBOOLEANtrue—
    tag_artistBOOLEANfalse—
    tag_metaBOOLEANfalse—
    block_tagsSTRING—
    use_default_blocklistBOOLEANtrue—
    max_attemptsoptINT31–10—
    loginoptSTRING—
    api_keyoptSTRING—
    cache_diroptSTRING—
    timeoutoptFLOAT20.001–120—
    id_ceilingoptINT125000001–2147483647—

    Outputs (7)

    NameTypeDescription
    imageIMAGE—
    artistSTRING—
    characterSTRING—
    copyrightSTRING—
    generalSTRING—
    promptSTRING—
    metaSTRING—