Nodes/Better-Gemini/Better OpenRouter
ComfyUI Node

Better OpenRouter

Hosted image models inside your graph, billed per image — Better OpenRouter

By ttulttul·Created 8 months ago·Updated a day ago· 1
Better OpenRouter
  • prompt_images
  • IMAGE
  • STRING
prompt
modelopenai/gpt-image-2
api_key
aspect_ratioauto
resolutionauto
width0
height0
qualityauto
output_formatauto
backgroundauto
output_compression-1
n1
seed0
cache_outputsfalse

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

  • prompt and model - the only required ones. Model is a slug like openai/gpt-image-2.
  • api_key - leave blank and it reads OPENROUTER_API_KEY from 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 the size parameter, which takes precedence over aspect_ratio and resolution. It's an either/or situation; the node errors if you set one without the other.
  • output_format (png/jpeg/webp), background (transparent/opaque), and n (1–10 images) are the other ones worth touching. output_compression only 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_KEY or pass api_key." Check which one you're actually missing.
  • SVG output. OpenRouter can return SVG, and this node deliberately doesn't expose it because ComfyUI IMAGE is raster. If you get an SVG error, pick a raster model or force PNG/JPEG/WebP.
  • Transparent + JPEG. The node rejects background=transparent with JPEG output because JPEG can't do alpha - use PNG or WebP.
  • Re-running re-bills you. The cache_outputs toggle 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=10 or a 4K resolution is only honored when the selected model supports it. When in doubt, set auto and 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.

Categoryapi node/image/BetterOpenRouter

Inputs (15)

NameTypeDefaultDescription
promptSTRINGText prompt for image generation or reference-guided editing.
modelCOMBOopenai/gpt-image-2OpenRouter image model slug. The dropdown is populated from OpenRouter's dedicated image-model discovery API.
api_keyoptSTRINGOptional. If empty, uses env var OPENROUTER_API_KEY.
prompt_imagesoptIMAGEOptional reference images for image-to-image generation. The number accepted depends on the selected model.
aspect_ratiooptCOMBOautoRequested aspect ratio. Supported values depend on the selected model; explicit width and height take precedence.
resolutionoptCOMBOautoRequested resolution tier. Supported tiers depend on the selected model; explicit width and height take precedence.
widthoptINT00–8192Optional explicit output width. Set height too; this is sent as the OpenRouter size parameter.
heightoptINT00–8192Optional explicit output height. Set width too; this is sent as the OpenRouter size parameter.
qualityoptCOMBOautoRequested image quality. Providers without this control may ignore it.
output_formatoptCOMBOautoRaster output format. SVG is not exposed because ComfyUI IMAGE is raster.
backgroundoptCOMBOautoRequested background behavior. Transparent output requires a model and format that support alpha.
output_compressionoptINT-1-1–100JPEG/WebP compression from 0 to 100. Use -1 to leave it unset; PNG ignores it.
noptINT11–10Number of images to request (up to 10). Individual models may allow fewer.
seedoptINT00–18446744073709550000Best-effort seed where the selected model supports it. Set 0 for unset.
cache_outputsoptBOOLEANfalseCache model outputs under .cache and reuse them for identical OpenRouter requests.

Outputs (2)

NameTypeDescription
IMAGEIMAGE
STRINGSTRING