Better OpenRouter
Hosted image models inside your graph, billed per image — Better OpenRouter
- prompt_images
- IMAGE
- STRING
This node is how you pull a hosted image model into a ComfyUI graph without renting a GPU or downloading a checkpoint. Better OpenRouter calls OpenRouter's dedicated image API (POST /api/v1/images) straight from the canvas and hands you back a normal IMAGE tensor you can wire into anything else. One node, one API key, and a dropdown full of models that would each take you a day to run locally - openai/gpt-image-2, google/gemini-3.1-flash-image, bytedance-seed/seedream-4.5, black-forest-labs/flux.2-pro, whatever OpenRouter lists that week.
Reach for it when the local stack is the wrong tool. GPT-image's text rendering is famously better than anything a LoRA-based local setup reliably produces, and if you're on 4GB VRAM, "make the cloud do it" is a legitimate strategy instead of fighting a quantized model for twenty minutes. The catch is obvious: every generation costs real money. This is a paid API node, not a free local node - don't wire a random-seed loop into it and walk away.
How it works
The model dropdown is populated live from OpenRouter's /images/models discovery endpoint, so it reflects what OpenRouter actually offers rather than a stale hardcoded list. If your key is missing or the listing call fails, the node falls back to a bundled set of defaults and still runs. Each execution builds a request with your prompt, sizing, and format settings, posts it to the image endpoint, decodes the returned base64 b64_json straight into a ComfyUI tensor, and skips the whole download-a-temp-file dance.
Reference images - your ComfyUI IMAGE output for img2img or editing - get sent as PNG data URIs under OpenRouter's input_references field. The number of references a model accepts is up to that model. One genuinely nice touch: the STRING output reports what happened, including the API cost when OpenRouter sends it back, so you can see "Reported cost: $0.0123" without opening a browser.
The inputs that matter
promptandmodel- the only required ones. Model is a slug likeopenai/gpt-image-2.api_key- leave blank and it readsOPENROUTER_API_KEYfrom your environment. Setting it inline on the node is handy for testing, less great for shared workflows.prompt_images- wire in reference images for editing; how many it accepts depends on the model.width/height- set both together (each > 0) and they're sent as thesizeparameter, which takes precedence overaspect_ratioandresolution. It's an either/or situation; the node errors if you set one without the other.output_format(png/jpeg/webp),background(transparent/opaque), andn(1–10 images) are the other ones worth touching.output_compressiononly applies to JPEG/WebP - set it on PNG and it errors on purpose.
Everything else - aspect_ratio, resolution, quality, seed - is best-effort. Providers that don't support a control just ignore it, and the node logs a warning if the image comes back at a different size than you asked for, which happens more than you'd like across a multi-provider router.
Outputs: IMAGE (the generated tensor) and STRING (the status note with model name and cost). If the provider returns nothing, you get a blank placeholder image plus an explanatory note in STRING, so the graph doesn't silently break.
Install
Easiest is ComfyUI Manager - search "Better-Gemini". Or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/ttulttul/Better-Gemini
Then restart ComfyUI. There are no model files to download - the one real dependency, google-genai, is for the sibling Gemini node; OpenRouter itself is called with plain stdlib urllib, so no extra install is needed to use this node. Note this pack uses ComfyUI's V3 extension loader, so it needs a reasonably current ComfyUI, not a years-old build.
Set your key however your OS does env vars:
export OPENROUTER_API_KEY="sk-or-..."
Where people get burned
- No key. The error is clear: "No API key provided. Set
OPENROUTER_API_KEYor passapi_key." Check which one you're actually missing. - SVG output. OpenRouter can return SVG, and this node deliberately doesn't expose it because ComfyUI
IMAGEis raster. If you get an SVG error, pick a raster model or force PNG/JPEG/WebP. - Transparent + JPEG. The node rejects
background=transparentwith JPEG output because JPEG can't do alpha - use PNG or WebP. - Re-running re-bills you. The
cache_outputstoggle saves identical requests under.cache/so repeat runs don't hit the API again - genuinely worth flipping on while you iterate, because it's the difference between a debugging session and a surprise invoice. - Model-specific limits. Requesting
n=10or a 4K resolution is only honored when the selected model supports it. When in doubt, setautoand let OpenRouter route.
This is the node to grab when you want a hosted model's output inside your local workflow - the one the sibling Gemini and Grok nodes don't cover. Just keep one eye on that cost string.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | Text prompt for image generation or reference-guided editing. | |
| model | COMBO | openai/gpt-image-2 | OpenRouter image model slug. The dropdown is populated from OpenRouter's dedicated image-model discovery API. |
| api_keyopt | STRING | Optional. If empty, uses env var OPENROUTER_API_KEY. | |
| prompt_imagesopt | IMAGE | Optional reference images for image-to-image generation. The number accepted depends on the selected model. | |
| aspect_ratioopt | COMBO | auto | Requested aspect ratio. Supported values depend on the selected model; explicit width and height take precedence. |
| resolutionopt | COMBO | auto | Requested resolution tier. Supported tiers depend on the selected model; explicit width and height take precedence. |
| widthopt | INT | 00–8192 | Optional explicit output width. Set height too; this is sent as the OpenRouter size parameter. |
| heightopt | INT | 00–8192 | Optional explicit output height. Set width too; this is sent as the OpenRouter size parameter. |
| qualityopt | COMBO | auto | Requested image quality. Providers without this control may ignore it. |
| output_formatopt | COMBO | auto | Raster output format. SVG is not exposed because ComfyUI IMAGE is raster. |
| backgroundopt | COMBO | auto | Requested background behavior. Transparent output requires a model and format that support alpha. |
| output_compressionopt | INT | -1-1–100 | JPEG/WebP compression from 0 to 100. Use -1 to leave it unset; PNG ignores it. |
| nopt | INT | 11–10 | Number of images to request (up to 10). Individual models may allow fewer. |
| seedopt | INT | 00–18446744073709550000 | Best-effort seed where the selected model supports it. Set 0 for unset. |
| cache_outputsopt | BOOLEAN | false | Cache model outputs under .cache and reuse them for identical OpenRouter requests. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| STRING | STRING | — |