Save Latent to S3
Save Latent to S3
- samples
- latent_file_path
ComfyUI already ships a built-in Save Latent node that writes a .latent file to disk. This one does the same thing, then immediately uploads the file to S3 and hands you back the path. If you've ever wanted a generation's compressed latent - not the finished PNG, the actual samples tensor - waiting for you in a bucket so some other service can pick it up and keep going, this is the node.
Why bother keeping the latent at all? A latent is the compressed representation the diffusion model works in, before the VAE decodes it into pixels (the concepts essay in our KB walks through that encode/decode cycle). Save it and you can decode later, or feed it straight into another pipeline. One honest caveat: latents are model-specific. The latent space for SD1.5 has four channels; Flux carries sixteen. A latent saved from one won't load in the other, so this only makes sense when you're reusing it on the same model family.
The inputs that matter
Only two, both required:
- samples (
LATENT) - wire this from your KSampler output. That's the whole point. - filename_prefix (default
latents/ComfyUI) - the key prefix inside the bucket. Change it per project so outputs don't all pile under one folder.
It returns latent_file_path (STRING), the S3 path of the uploaded .latent file. Wire that into a text logger or just read it in the UI. The node numbers files like ComfyUI's image saver (_00001, _00002...) so nothing gets silently overwritten.
How it works
The node saves the latent locally first - into your normal ComfyUI output folder - using the same save_torch_file path the core Save Latent uses, then uploads that file to S3 through the pack's shared client. This is where the config lives, and it's all environment variables, not node inputs:
CSAPI_REGION
CSAPI_ID
CSAPI_KEY
S3_BUCKET_NAME
S3_ENDPOINT_URL
S3_OUTPUT_DIR
S3_INPUT_DIR
The client reads a .env file too (the pack pulls in python-dotenv), so you can drop those in one if that's your setup. Note that the S3 client is built when the module loads - if those vars are missing when ComfyUI starts, you'll get connection failures at save time. Set them, then start ComfyUI. And S3_ENDPOINT_URL means S3-compatible services like MinIO work as well as real AWS.
Installing
Same story as the rest of this pack: open ComfyUI Manager, search ComfyUI Secure API Call, install, restart. Or clone it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Mattabyte/ComfyUI-SecureApiCall
Then restart ComfyUI. Dependencies are light - boto3, python-dotenv, Pillow - and there are no model downloads.
The gotchas
Most of your time here will be spent on environment variables, because the node has no inline credentials fields. That's deliberate: the same pack ships a warning about secrets leaking into ComfyUI's workflow metadata (the whole "workflow included in the PNG" culture means whatever you type into a node ends up embedded in your output files). With S3, the creds live in your environment instead of the graph - annoying to set up once, way safer after.
If uploads fail, check that all five S3 vars are set before ComfyUI boots, that the bucket exists, and that the IAM user can actually write to it. If you're hitting a local MinIO or a dev endpoint, make sure S3_ENDPOINT_URL points at it or boto3 will try to reach real AWS and get nowhere.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| samples | LATENT | — | |
| filename_prefix | STRING | latents/ComfyUI | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent_file_path | STRING | — |