Nodes/ComfyUI Safebooru Top Tags/Fetch Danbooru Sequential Top Tags
ComfyUI Node

Fetch Danbooru Sequential Top Tags

Turn a seed into a ready-made Danbooru prompt — no API key required

By TZFC·Created 2 months ago·Updated 2 months ago· 1
Fetch Danbooru Sequential Top Tags
    • combined_prompt
    • current_post_tags
    base_prompt
    danbooru_username
    danbooru_api_key
    include_generaltrue
    include_artisttrue
    include_characterfalse
    include_seriesfalse
    include_metafalse
    replace_underscorestrue
    seed0

    The name sounds like it needs an API key and a Terms of Service waiver. It doesn't. DanbooruSequentialTopTags walks the tags attached to Danbooru's highest-ranked posts, one seed at a time, and hands you a prompt ready to drop into a CLIPTextEncode. If you've ever wanted to generate from the tags real people actually curated onto good art - without typing a single tag yourself - this is the shortest path there is.

    For anime SDXL models, tags are the interface. Illustrious, NoobAI, and (mostly) Pony were trained on Danbooru's exact vocabulary, so a correct tag beats a sentence for controlling pose, clothing, and character identity. Pulling human-curated tags off top-scored posts is a surprisingly strong starting prompt, which is exactly the trick this node exploits.

    How it works

    Under the hood it's simple. The node hits Danbooru's JSON API:

    https://danbooru.donmai.us/posts.json?limit=200&tags=order:rank&page=N
    

    order:rank returns posts sorted by score, 200 at a time. The clever part is the seed. Your first run records the seed as initial_seed, and every run after that computes actual_index = abs(seed - initial_seed). In other words, the seed is an index into that top-post list: bump it by one and you get the next post's tags. The node caches fetched posts in a class-level queue and pulls more pages as you advance, with a guard so a wild seed jump doesn't trigger hundreds of page fetches - it modulo-wraps instead. IS_CHANGED returns NaN, so the node always re-executes instead of caching.

    Then it slices the post's tag_string_* fields according to your toggles, swaps underscores for spaces, joins everything with commas, and prepends it to your base_prompt.

    The inputs that matter

    Most of the ten inputs you'll leave alone. The ones you'll actually touch:

    • seed - the position in Danbooru's top-post ranking. Step it by 1 for the next post; that's the whole "sequential" in the name.
    • include_general / include_artist / include_character / include_series / include_meta - which tag categories to keep (general, artist, character, copyright/series, meta). Artist tags shift style toward that artist, which is a fun lever. General on, character/series/meta off is the sane default.
    • replace_underscores - leave on. Danbooru tags like blue_eyes become blue eyes, which is how the anime models actually learned them.
    • base_prompt - prepended after the fetched tags. Since earlier tags get stronger attention, the fetched tags lead the prompt. Quality tags like masterpiece end up at the back, which is fine.

    danbooru_username and danbooru_api_key are optional - if both are filled they're appended as login/api_key params, but anonymous access works fine.

    Two outputs: combined_prompt (fetched tags + your base_prompt) goes straight into a CLIPTextEncode's positive text; current_post_tags is the raw tags alone if you want to log or post-process them.

    Installing it

    ComfyUI Manager → search "comfyui-safebooruTop" (shown as "ComfyUI Safebooru Top Tags"), or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TZFC/comfyui-safebooruTop
    

    Then restart ComfyUI. That's it - the only dependency is requests, which you already have. No models, no weights, no downloads.

    Where people get burned

    The one real gotcha I verified myself: Danbooru's API currently sits behind a Cloudflare JS challenge, and scripted requests can get back an HTML challenge page instead of JSON. The node does .json() on whatever it receives, so that silently fails - the except breaks, and you get your base_prompt back with no tags. Check the console for [Danbooru Node Error] and retry; the challenge is often IP- or UA-dependent, so it may just work for you.

    Two quieter quirks. The tag cache is a class-level list that persists for the whole ComfyUI session, so multiple instances of the node share the same queue, and it resets on restart. And remember Danbooru is uncensored - "top posts" skew NSFW. That's the point for a lot of people, but if it isn't, the sibling node in this pack (SafebooruSequentialTopTags) pulls from the SFW mirror instead.

    Also, one fair warning: this pack is tiny and brand new - a single-node hobby tool from user TZFC, one star, no README. It works, and the source is small enough to read in a minute if something surprises you. Just don't expect active maintenance.

    Categoryutils

    Inputs (10)

    NameTypeDefaultDescription
    base_promptSTRING
    danbooru_usernameSTRING
    danbooru_api_keySTRING
    include_generalBOOLEANtrue
    include_artistBOOLEANtrue
    include_characterBOOLEANfalse
    include_seriesBOOLEANfalse
    include_metaBOOLEANfalse
    replace_underscoresBOOLEANtrue
    seedINT00–18446744073709550000

    Outputs (2)

    NameTypeDescription
    combined_promptSTRING
    current_post_tagsSTRING