ComfyUI Node

Image to Base64 URL Node

Turn an image into a base64 data URL your APIs can eat

By AhBumm·Created 2 years ago·Updated 3 months ago· 11
Image to Base64 URL Node
  • image
  • base64_url

Image to Base64 URL is the plumbing node every API workflow eventually needs. Most OpenAI-compatible APIs - vision models doing captioning, image-editing endpoints, providers that accept reference images - don't want a ComfyUI tensor. They want a string: a base64 payload wrapped in a data: URI. This node does exactly that conversion, and it's the quiet workhorse of this pack.

If you've ever stared at an API error complaining about "image" when you were sure you'd attached an image, this is the missing step. The tensor on the wire isn't an image to a remote server; the data URL is.

How it works

You feed it a single IMAGE input and get one string out, named base64_url. Under the hood it's simple: the node grabs the first frame of your image batch, converts it to RGB via PIL, saves it to a temporary PNG file, base64-encodes the bytes, and wraps them in a data: URI.

One quirk worth knowing, because it's exactly the kind of thing that bites people later: the code saves a PNG but labels the data URI as data:image/jpeg;base64,.... The MIME type and the actual bytes disagree. In practice most endpoints sniff the payload and don't care - but if you hit a picky API that validates the content type strictly, this mismatch is what it's complaining about. Re-encoding the image to real JPEG first (any standard image conversion node) is the workaround.

The other thing to remember: only the first image of a batch is converted. Feed it a stack of images and the rest get silently ignored. For a single reference image - the normal use case - that's fine.

When you'd reach for it

The pack itself shows the pattern in its README's workflow diagrams: ComfyUI IMAGE → Image to Base64 URL → API or remote result. Concretely:

  • Vision / captioning - send a reference image to one of the pack's vision LLM nodes that expects base64 image input.
  • Image-editing APIs - many text-to-image endpoints with image input (the Flux-with-image-input node in this same pack, the HyprLab node's image_input) want a base64 string rather than a tensor.
  • Logging or remote services - any time you need to hand an image to something over HTTP.

The natural reverse is the pack's Base64 URL to Image node, which turns a data URL back into a tensor when an API returns base64 instead of a file URL. If the API hands you a plain URL instead, the pack's Load Image from URL (BillBum) covers that side.

Installing it

This is one of four nodes in the ComfyUI_BillBum_Nodes pack, and they all install together. ComfyUI Manager → search billbum → install, or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/AhBumm/ComfyUI_BillBum_APIset_Nodes.git
pip install -r requirements.txt

The requirements (openai, requests, pillow, numpy, tenacity, tiktoken, urlextract) are all lightweight, and there are no model downloads. Restart ComfyUI and you'll find it under BillBum Image Processing.

Troubleshooting

  • API says the image is invalid - check the data:image/jpeg vs. actual PNG mismatch above; it's the most likely culprit with strict endpoints.
  • Wrong image got sent - remember only frame [0] of a batch is used. If your workflow is feeding batched images upstream, reorder or separate them first.
  • Huge base64 strings - that's normal, base64 inflates file size by ~33%. If a request is timing out, downscale the image before converting; the node doesn't resize for you.

It's a boring node - one input, one string out - but if you run any of these API packs, you'll end up grateful it's there.

CategoryBillBum Image Processing

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
base64_urlSTRING