How to Run ComfyUI on Vast.ai and Generate AI Images
ComfyUI is a powerful, node-based graphical user interface (GUI) designed for building complex generative-AI workflows. Unlike simpler interfaces, ComfyUI allows you to visualize and control every step of the image generation process. It is highly versatile, supporting everything from basic text-to-image and image-to-image to advanced inpainting, upscaling, animation, and video generation.
While ComfyUI is exceptionally efficient, running modern AI models like Stable Diffusion XL (SDXL) or Flux requires significant GPU power and VRAM. For many developers and enthusiasts, renting a cloud GPU is more practical than investing thousands in local hardware. Using ComfyUI on Vast.ai offers several key benefits:
- No Upfront Hardware Costs: Rent high-end NVIDIA GPUs like the RTX 4090 or A100 only when you need them.
- Scalable VRAM: Choose a GPU with the exact amount of memory your specific workflow requires.
- High Performance: Run demanding batches and high-resolution upscales faster than on typical consumer laptops.
- Portability: Save your ComfyUI workflows as JSON files or within the metadata of your generated images to use anywhere.
Want to follow along?
Browse available GPUs on Vast.ai and launch a ComfyUI-ready instance.
DevOps Depo may receive a referral credit if you create an account through this link, at no additional cost to you.
What you need
Before you begin, ensure you have the following:
- A Vast.ai account with a small amount of added credit.
- A modern web browser (Chrome, Firefox, or Edge).
- A general idea of which AI image model you want to use (e.g., Stable Diffusion 1.5, SDXL, or Flux).
- Enough instance storage to hold the ComfyUI installation, your chosen models, and your generated outputs.
The Vast.ai template system simplifies the process by providing prebuilt configurations that include ComfyUI and its dependencies.
Step 1: Choose the right GPU
Selecting the right GPU is primarily a balance between VRAM (Video RAM) requirements and hourly cost. AI models are loaded entirely into VRAM during generation, so if your model is larger than your GPU's memory, the workflow will fail.
| Intended Workload | Suggested VRAM Starting Point |
|---|---|
| Basic SD 1.5 workflows | 8–12 GB |
| SDXL workflows | 12–16 GB |
| Larger Flux-style workflows | 24 GB or more |
| Video, large batches or advanced workflows | 24–48 GB or more |
Note: These are general starting points. Actual requirements vary based on resolution, custom nodes, and specific model quantization.
When browsing the Vast.ai marketplace, look beyond the hourly price. Consider the Reliability rating, Download/Upload speeds (important for fetching large models), and the Total cost (which includes storage and bandwidth).
Step 2: Find a ComfyUI template
Instead of installing everything manually, use a pre-configured Docker template. This ensures that CUDA drivers and Python dependencies are correctly set up for the GPU.
- Sign in to your Vast.ai account.
- Go to the Templates section in the sidebar.
- Search for
ComfyUI. - Look for a reputable template (often from the Vast.ai team or a well-known community member).
- Review the template description: Pay attention to the default ports, login credentials (if any), and where the models are stored.
- Click the template to use it as your search filter, then compare the available machines.
Step 3: Allocate storage
AI models are massive. A single SDXL checkpoint can be 6GB, and a full set of Flux models can easily exceed 20GB. When you rent an instance, you must specify the Disk Space allocation.
Remember to leave room for:
- Base checkpoints, LoRAs, and ControlNet models.
- Text encoders (CLIP/T5) and VAEs.
- The ComfyUI environment itself.
- Your generated images and high-resolution videos.
Warning: The storage size you select at launch often cannot be increased later without destroying and recreating the instance. For a beginner using SDXL, 50GB to 100GB is a safe starting range, but always adjust based on your specific needs.
Step 4: Start and open ComfyUI
Once you click RENT, Vast.ai will begin pulling the Docker image. This can take several minutes depending on the host's internet speed. Wait until the instance status changes to "Running".
To access the interface, find your instance in the "Instances" tab and click the OPEN or CONNECT button. Most templates are configured to redirect you automatically to the ComfyUI web interface.
Security Tip: Never expose an unauthenticated ComfyUI interface to the open internet. Most Vast.ai templates use a secure proxy or SSH tunneling to keep your instance safe. Treat ComfyUI custom nodes like any other executable software—only install what you trust.
Step 5: Understand the ComfyUI interface
ComfyUI works by connecting "Nodes" together. Here are the core concepts you'll see in almost every workflow:
- Load Checkpoint: Selects your main AI model.
- CLIP Text Encode: Where you type your Positive and Negative prompts.
- Empty Latent Image: Sets the resolution and batch size.
- KSampler: The engine that generates the image. This is where you set "Steps", "CFG", and the "Sampler".
- VAE Decode: Translates the mathematical "latent" data into a visible image.
- Save Image: Displays the result and writes it to the server's output folder.
Step 6: Install or locate a model
Some templates come with models pre-installed, but usually, you'll need to download your own. ComfyUI expects files in specific subfolders under models/:
ComfyUI/
└── models/
├── checkpoints/ <-- Main models (e.g., .safetensors)
├── loras/ <-- Style/character modifiers
├── controlnet/ <-- Composition tools
└── vae/ <-- Color/detail decoders
To install a model, you can use the terminal (via SSH) to wget or curl the file directly from a source like Hugging Face or CivitAI into the correct folder. After adding a file, click Refresh in the ComfyUI menu (or press r) to make it appear in the loader nodes.
Step 7: Load a basic workflow
The easiest way to start is by loading a default workflow. You can:
- Click Load Default in the ComfyUI menu.
- Drag and drop a ComfyUI-generated PNG into the window (it will automatically load the workflow used to create that image).
- Click Load and select a JSON workflow file you've downloaded.
Ensure your workflow has the basic connections: Model -> CLIP -> Sampler -> VAE -> Save Image.
Step 8: Generate the first image
Let's try a test prompt to ensure everything is working correctly:
Positive Prompt:
A detailed cinematic photograph of a futuristic research station on a mountain at sunrise, dramatic clouds, natural lighting, high detail
Settings:
- Resolution: 1024x1024 (for SDXL) or 512x512 (for SD 1.5).
- Steps: 20 to 30.
- CFG Scale: 7.0.
- Sampler: euler_ancestral (a good reliable default).
Click Queue Prompt. You will see the nodes highlight in green as they process. Once finished, your image will appear in the "Save Image" node.
Step 9: Save outputs and workflows
Because cloud instances are temporary, you must download what you want to keep:
- Images: Right-click the generated image and select "Save Image".
- Workflows: Click the Save button in the menu to export your node graph as a JSON file.
Pro Tip: Save your JSON workflows separately. While ComfyUI embeds metadata in PNGs, that data is often stripped if you upload the image to social media or Discord.
Step 10: Stop or delete the instance
To manage your budget, you must understand the difference between stopping and deleting:
- Stop Instance: Pauses the hourly GPU charge, but you will still be charged a small fee for Storage. Use this if you plan to return soon.
- Delete Instance: Stops all charges immediately but permanently deletes all files (models, images, and custom nodes) inside the instance.
Always download your outputs and save your JSON workflows before clicking the trash icon!
Installing Custom Nodes Safely
Custom nodes add incredible functionality like video generation (AnimateDiff) or advanced upscalers. Most users install the ComfyUI Manager to handle this. If your template doesn't include it, you can usually enable it by running:
python main.py --enable-manager
Safety Warning: Custom nodes can execute code on your instance. Only install nodes from trusted, active repositories. Installing too many nodes at once can lead to dependency conflicts and prevent ComfyUI from starting. Install one at a time and test your workflow before adding more.
Troubleshooting
ComfyUI does not open
Check the "Logs" button in Vast.ai. If the Docker image is still downloading or the startup script is installing dependencies, the interface won't be ready. Wait a few more minutes.
CUDA Out of Memory (OOM)
Your GPU has run out of VRAM. Try reducing your image resolution, lowering the batch size, or using a "quantized" version of the model which uses less memory.
Red Nodes or Missing Nodes
This happens when you load a workflow that requires custom nodes you haven't installed yet. Use the ComfyUI Manager's "Install Missing Custom Nodes" feature to fix this.
Cost Optimization
- Start with one GPU: You rarely need multi-GPU setups for ComfyUI unless you are doing massive video renders.
- Monitor your balance: Set a billing alert in your Vast.ai account settings to avoid unexpected charges.
- Avoid Redundant Downloads: If you use the same 20GB of models every day, it might be cheaper to keep a "stopped" instance with persistent storage than to re-download them every time.
Final Thoughts
Deploying ComfyUI on Vast.ai gives you the power of a professional AI workstation without the high price tag. By following this guide, you can jump from basic image generation to building complex, high-performance AI tools in the cloud.
Build your first cloud ComfyUI workstation:
Compare available GPU offers on Vast.ai and select the VRAM, storage, and reliability level that fits your workflow.