Danbooru Random Image
Pull a random tagged image straight off Danbooru
- image
- mask
The name is a lie in the best way: this node doesn't call any AI API and needs no key by default - it queries Danbooru's public API for a random post matching your tags, downloads the image, and hands it to ComfyUI as a tensor. For anyone doing img2img from anime reference art, style transfer, or training-data browsing, it's a one-node pipeline from "I want a random character with blue hair" to a usable IMAGE and MASK sitting in your graph.
Why you'd reach for it
Danbooru is the anime imageboard whose exhaustive tag taxonomy became the prompt vocabulary for the whole anime SDXL ecosystem (Illustrious, NoobAI, Pony all descend from its labels). When you're doing reference-driven work, pulling a genuinely random post that matches 1girl blue_hair is faster and more varied than manually curating a folder. The mask output is the sleeper feature: for transparent PNGs it returns the alpha channel as a MASK, and for opaque images it returns a full-white mask - so you can feed either into inpainting or compositing without extra work.
How it works
Your include_tags and exclude_tags multiline fields are parsed into a tag query - commas and newlines become spaces, spaces become underscores, and exclude tags get prefixed with - (Danbooru's exclusion syntax). One of your allowed ratings is picked at random and added as a positive tag so the query isn't negative-only, then the API's random=true parameter does the random selection server-side. The node tries up to ten results, skips unsupported file types (it accepts jpg/jpeg/png/webp), downloads, converts to a 0-1 float tensor, and builds the mask.
Ratings are worth understanding before you touch it: Danbooru uses g (general), s (sensitive), q (questionable), and e (explicit). Defaults allow g and s and exclude q and e - but the toggles are right there in the node, and the board (and thus this node) is entirely capable of explicit content if you flip them. If you want a zero-surprise experience, leave e and q off. You can also drop a login,api_key line into nodes/API.txt for authenticated access.
The inputs that matter
- include_tags / exclude_tags (multiline STRING) - your query. This is the whole point.
- seed (INT) - reproducibility of the random pick.
- include_rating_g / s / q / e (BOOLEAN) - which content ratings are allowed. g and s default on; q and e default off, and you should probably leave it that way unless you know what you're asking for.
- image (IMAGE) / mask (MASK) - the outputs. Wire image into your img2img/preview path.
Installing it
This one has real network dependencies. The node uses requests and Pillow, and the pack has no requirements.txt:
cd ComfyUI/custom_nodes
git clone https://github.com/LaVie024/comfyui-lopi999-nodes
pip install requests pillow
Restart ComfyUI. Manager's "comfyui-lopi999-nodes" search works too.
Common issues
If the node errors with a 422, Danbooru is telling you the tag query is invalid - usually too many tags or a negative-only query, and the error message says as much. No network or a blocked connection means the download fails outright; this node is useless offline. And remember the sandbox warning that applies to all custom nodes: this one ships network code, so grab it from the official repo and be mindful of what you wire into it. Danbooru's rating system also means "random" can surface content you didn't expect - the rating toggles are your filter, and the safe mirror (donmai.moe) exists for a reason.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| include_tags | STRING | — | |
| exclude_tags | STRING | — | |
| seed | INT | 0 | — |
| include_rating_g | BOOLEAN | true | — |
| include_rating_s | BOOLEAN | true | — |
| include_rating_q | BOOLEAN | false | — |
| include_rating_e | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |