Template Components
The ComfyUI template includes: In the Docker Image:- ComfyUI
- ComfyUI API Wrapper
- Stable Diffusion 1.5 (for benchmarking)
- PyWorker (comfyui-json worker)
- Provisioning Script for custom configuration
- Adds cron job to remove older output files (older than 24 hours) if available disk space is less than 512MB
Before using this template, familiarize yourself with the Serverless Documentation and Getting Started With Serverless guide.
Environment Variables
Required for S3 Storage
The API wrapper manages asset uploads to S3-compatible storage. Configure these variables in your Account Settings:S3_ACCESS_KEY_ID(string): Access key ID for S3-compatible storageS3_SECRET_ACCESS_KEY(string): Secret access key for S3-compatible storageS3_BUCKET_NAME(string): Bucket name for S3-compatible storageS3_ENDPOINT_URL(string): Endpoint URL for S3-compatible storageS3_REGION(string): Optional region for S3-compatible storage
These S3 values can be overridden on a per-request basis in the request payload.
Optional Configuration
WEBHOOK_URL(string): Optional webhook to call after generation completion or failurePYWORKER_REPO(string): Custom PyWorker git repository URL (default: https://github.com/vast-ai/pyworker)PYWORKER_REF(string): Git reference to checkout from PyWorker repositoryBENCHMARK_TEST_WIDTH(int): Image width in pixels for default benchmark only (default: 512)BENCHMARK_TEST_HEIGHT(int): Image height in pixels for default benchmark only (default: 512)BENCHMARK_TEST_STEPS(int): Number of denoising steps for default benchmark only (default: 20)
Benchmarking
When a worker initializes, it runs a benchmark to validate GPU performance and calculate a performance score. This score determines how requests are distributed across workers.Custom Benchmark Workflows
You can provide a custom ComfyUI workflow for benchmarking by creatingworkers/comfyui-json/misc/benchmark.json. Use the placeholder __RANDOM_INT__ in place of static seed values to ensure varied generations.
The
__RANDOM_INT__ placeholder can also be used in any workflow you send to the worker. It will be replaced with a random integer for each generation, allowing for varied outputs without manually specifying different seeds.Default Benchmark
If no custom benchmark is provided, the template uses Stable Diffusion v1.5 with ComfyUI’s default text-to-image workflow. Configure the benchmark complexity using the environment variables listed above. How worker scores work:- Each benchmark has a baseline complexity score of
100(representing 100% of the work) - A worker completing the benchmark in 100 seconds receives a score of
1.0(processes 1% of work per second) - A worker completing in 50 seconds receives a score of
2.0(twice as fast) - Faster workers (higher scores) receive proportionally more requests
Configure your benchmark to match your actual workload complexity. If your typical workflow is more complex than the default SD1.5 benchmark, increase
BENCHMARK_TEST_STEPS proportionally.Endpoints
The ComfyUI template provides endpoints for executing workflows and generating images. After obtaining a worker address from the/route/ endpoint (see route documentation), you can send requests to the following endpoints.
/generate/sync
The primary endpoint for submitting ComfyUI workflows. This endpoint accepts complete, user-defined ComfyUI workflows in JSON format and processes them synchronously.Request Structure
Input
payload:
input:request_id(string): Optional unique identifier for tracking the requestworkflow_json(object): Complete ComfyUI workflow graph in JSON formats3(object): Optional S3 configuration overrideaccess_key_id(string)secret_access_key(string)endpoint_url(string)bucket_name(string)region(string)
webhook(object): Optional webhook configurationurl(string): Webhook URL to call after generationextra_params(object): Additional parameters to include in webhook payload
If the API Wrapper detects that you have used a URL as an input image in your workflow, it will automatically download the image and modify the workflow to use the local path.
Outputs
id(string): Unique identifier for the requeststatus(string): Request status -completed,failed,processing,generating, orqueuedmessage(string): Human-readable status messagecomfyui_response(object): Detailed response from ComfyUI including:prompt: The workflow that was executedoutputs: Generated outputs organized by node IDstatus: Execution status with completion messages and timestampsmeta: Metadata about the executionexecution_details: Progress updates and timing information
output(array): Array of output objects, each containing:filename(string): Name of the generated filelocal_path(string): Path to file on workerurl(string): Pre-signed URL for downloading the generated asset (if S3 is configured)type(string): Output type (e.g., “output”)subfolder(string): Subfolder within output directorynode_id(string): ComfyUI node that produced this outputoutput_type(string): Type of output (e.g., “images”)
timings(object): Timing information for the request
Testing Before Deployment
Although this template is designed for serverless deployment, you can test it as an interactive instance first. To access ComfyUI and the API wrapper:- Start an interactive instance with this template
- Connect via SSH with port forwarding:
- Access ComfyUI at http://localhost:18188
- Access the API Wrapper documentation at http://localhost:18288/docs