Nodes/ComfyUI-GPT4V-Image-Captioner/GPT4V-Image-Captioner
ComfyUI Node

GPT4V-Image-Captioner

Turn any image into a tag list with one API call

By 438443467·Created 2 years ago·Updated about a year ago· 27
GPT4V-Image-Captioner
  • image
  • prompt
  • full_prompt
api_key
api_url
seed1
modelgpt-4o
img_qualityauto
timeout30
enable_weightfalse
weight1.0
custom_promptAs an AI image tagging expert, please provide precise tags for these images to enhance CLIP model's understanding of the content. Employ succinct keywords or phrases, steering clear of elaborate sentences and extraneous conjunctions. Prioritize the tags by relevance. Your tags should capture key elements such as the main subject, setting, artistic style, composition, image quality, color tone, filter, and camera specifications, and any other tags crucial for the image. When tagging photos of people, include specific details like gender, nationality, attire, actions, pose, expressions, accessories, makeup, composition type, age, etc. For other image categories, apply appropriate and common descriptive tags as well. Recognize and tag any celebrities, well-known landmark or IPs if clearly featured in the image. Your tags should be accurate, non-duplicative, and within a 20-75 word count range. These tags will use for image re-creation, so the closer the resemblance to the original image, the better the tag quality. Tags should be comma-separated. Exceptional tagging will be rewarded with $10 per image.
exclude_words
add_words

The whole reason this pack exists. Feed GPT4V-Image-Captioner an image and it calls a GPT vision model to write you back a comma-separated tag list you can drop straight into a CLIP text encoder - your prompt, generated on the fly. It's the classic "caption a reference image" trick, and it's also a genuinely good way to bulk-caption a training dataset if you're willing to pay the API bill. GPT-4o captioning became a real community practice for SDXL and anime LoRA training around mid-2024 precisely because the tags come out far cleaner and more descriptive than WD14 or BLIP.

How it works

The node never sees a local model - there's nothing to download. It converts your ComfyUI image tensor to base64, then does the fiddly part for you: it picks the closest of ~15 aspect-preserving target resolutions (each roughly a megapixel, e.g. 1024x1024, 896x1152, 1632x640), resizes with Lanczos, center-crops, and re-encodes as JPEG. Then it POSTs to whatever api_url you give it with a standard OpenAI chat-completions payload: the text prompt, the image as a data: URI, and detail set from img_quality. It retries up to five times with backoff on 429/5xx responses, and caps output at 300 tokens.

Two outputs come back: prompt is the processed caption, full_prompt is the raw one. So exclude_words and add_words apply to prompt only - full_prompt is what the model actually said.

The inputs that matter

  • api_key - sk-xxxx. It lives in the node itself; there's no env var or config file.
  • api_url - any OpenAI-compatible endpoint, e.g. https://XXX/v1/chat/completions. That's how you point it at Azure, OpenRouter, or a Chinese mirror.
  • model - gpt-4o (default), gpt-4-vision-preview, gpt-4o-ca, gpt-4-turbo.
  • seed - the caching key. Same seed + same image = no new API call (the README's "seed determines consistency" promise).
  • custom_prompt - the default is a long "AI image tagging expert" instruction in English. Edit it for your style. Note the README talks about "generic" and "figure" prompt types from the upstream project, but this port doesn't expose a prompt_type input - the figure behavior (dropping color/background/watermark words) is something you bake into custom_prompt yourself.
  • exclude_words / add_words - comma-separated words stripped from or appended to the caption.
  • enable_weight / weight - wraps the caption as (tag list=1.00) when on.

Where people get burned

The cache is module-global and only keys on seed + image. Change the seed → new call. Change the model, img_quality, or even custom_prompt without touching the seed → stale cached caption. If your prompt isn't updating, bump the seed. Also, errors come back as the output: a bad URL gives you Error Connecting: ... as your "prompt" string. And keep that API key out of shared workflow files.

Install

ComfyUI Manager → search "GPT4V-Image-Captioner" → Install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/438443467/ComfyUI-GPT4V-Image-Captioner

Restart ComfyUI. requirements.txt is thin (requests, Pillow, torch, scipy, matplotlib, tqdm) - nothing heavy to pull. Set timeout to at least 30s; too low and you'll just get timeout errors on slow mirrors. Since this is the only node the current repo ships, it's the one you can count on finding after a fresh install.

CategorySanmi Nodes/GPT

Inputs (12)

NameTypeDefaultDescription
api_keySTRING例如:sk-xxxx
api_urlSTRING例如:https://XXX/v1/chat/completions
seedINT11–18446744073709550000
modelCOMBOgpt-4o4 options: gpt-4-vision-preview, gpt-4o, gpt-4o-ca, gpt-4-turbo
img_qualityCOMBOauto3 options: auto, high, low
timeoutINT301–999设定超时时间,基于网络情况,必须提供足够的反应时间,过短会无法接受到返回的信息.
enable_weightBOOLEANfalse
weightFLOAT1.00–8.201
custom_promptSTRINGAs an AI image tagging expert, please provide precise tags for these images to enhance CLIP model's understanding of the content. Employ succinct keywords or phrases, steering clear of elaborate sentences and extraneous conjunctions. Prioritize the tags by relevance. Your tags should capture key elements such as the main subject, setting, artistic style, composition, image quality, color tone, filter, and camera specifications, and any other tags crucial for the image. When tagging photos of people, include specific details like gender, nationality, attire, actions, pose, expressions, accessories, makeup, composition type, age, etc. For other image categories, apply appropriate and common descriptive tags as well. Recognize and tag any celebrities, well-known landmark or IPs if clearly featured in the image. Your tags should be accurate, non-duplicative, and within a 20-75 word count range. These tags will use for image re-creation, so the closer the resemblance to the original image, the better the tag quality. Tags should be comma-separated. Exceptional tagging will be rewarded with $10 per image.
exclude_wordsSTRING
add_wordsSTRING
imageIMAGE

Outputs (2)

NameTypeDescription
promptSTRING
full_promptSTRING