Skip to main content
This guide shows how to deploy a ComfyUI server on Beam using Pod. We’ll set up a server to generate images with Flux1 Schnell, but you can easily adapt it to use other models like Stable Diffusion v1.5.

View the Code

See the code for this example on Github.

Setting Up the ComfyUI Server

  1. Create the Deployment Script Create a file named app.py with the following code. This script sets up a Beam Pod with ComfyUI, installs dependencies, downloads the Flux1 Schnell model, and launches the server.
  2. Start ComfyUI
    This deploys the ComfyUI server to Beam. After deployment, you’ll see a URL (e.g., https://pod-12345.apps.beam.cloud) where your server is hosted.
    ComfyUI takes a minute or two to start after deploying it for the first time.
  3. Accessing the Server
    • Open the URL from your terminal in a browser to access the ComfyUI interface.
    • Use the web UI to load workflows or generate images.

Using Different Models

You can swap the Flux1 Schnell model for another, such as Stable Diffusion v1.5, by updating the model variables in app.py. Here’s how:
  1. Update the Model Variables Define the organization, repository, weights file, and commit ID for your desired model. For example, to use Stable Diffusion v1.5:
  2. Apply to the Image Commands The rest of the script uses these variables, so no further changes are needed to the image section:
  3. Find Model Details To use any other model:
    • Visit Comfy-Org Hugging Face and find your desired model.
    • Update ORG_NAME, REPO_NAME, WEIGHTS_FILE, and COMMIT with values from the model’s repository. Check the “Files and versions” tab for the weights file and commit hash.

Running Workflows as APIs

You can also expose ComfyUI workflows as APIs using Beam’s ASGI support. This allows you to programmatically generate images by sending requests with prompts. Below is an example of how to set this up:
  1. Create the API Script
  2. Prepare a Workflow File
    • Create a workflow_api.json file in the same directory as app.py. This file should contain your ComfyUI workflow, which you can export from the ComfyUI web interface.
    • You can also store your workflow_api.json file in your Volume and use it like WORKFLOW_FILE = Path("/your_volume/workflow_api.json")
  3. Deploy the API
  4. Use the API Send a POST request to the /generate endpoint with a JSON payload containing a prompt:
    The response will include a public URL to the generated image: