Getting Started with AnyComfy API
2025/07/28

Getting Started with AnyComfy API

A guide to using the AnyComfy API for image generation

1. Preparation

To run ComfyUI workflows through the API interface, you need to first obtain the corresponding workflow's JSON configuration file (API-compatible format). The following operation process also applies to locally deployed ComfyUI WebUI interfaces.

Getting the Workflow File

Click the "Try ComfyUI on AnyComfy" button to enter the ComfyUI WebUI interface provided by AnyComfy. Homepage

In the ComfyUI WebUI interface, select the workflow you need. Choose Workflow

In the workflow interface, click the "Workflow" button in the upper-left navigation bar, then select the "Export(API)" option. The browser will automatically download a JSON-formatted workflow configuration file. Export Workflow

2. Using POSTMAN to Call the API

Postman is a popular API development and testing tool used for sending HTTP requests, testing API endpoints, and managing interface documentation.

If you haven't installed Postman yet, please visit the "Postman Official Website" to download and install it.

Creating a Request

Open POSTMAN, create a new POST request, and name the request "prompt". Create Request

Configuring Request Parameters

  • Request URL:
https://anycomfy.com/api/prompt
  • Request body format: Select "raw" and "JSON" Configure Request

Setting Request Content

  • Paste the downloaded workflow JSON file content into the "prompt" field
  • Fill in your API key in the "api_key" field
{
    "prompt": {"Your workflow content"},
    "api_key": "Your API key"
}

Example workflow used in this guide:

(You only need to replace the "Your API key" part with your actual API key)

{
  "prompt": {
    "8": {
      "inputs": {
        "samples": [
          "40",
          0
        ],
        "vae": [
          "10",
          0
        ]
      },
      "class_type": "VAEDecode",
      "_meta": {
        "title": "VAE Decode"
      }
    },
    "10": {
      "inputs": {
        "vae_name": "ae.safetensors"
      },
      "class_type": "VAELoader",
      "_meta": {
        "title": "Load VAE"
      }
    },
    "11": {
      "inputs": {
        "clip_name1": "t5xxl_fp8_e4m3fn.safetensors",
        "clip_name2": "clip_l.safetensors",
        "type": "flux",
        "device": "default"
      },
      "class_type": "DualCLIPLoader",
      "_meta": {
        "title": "DualCLIPLoader"
      }
    },
    "17": {
      "inputs": {
        "scheduler": "normal",
        "steps": 25,
        "denoise": 1,
        "model": [
          "46",
          0
        ]
      },
      "class_type": "BasicScheduler",
      "_meta": {
        "title": "BasicScheduler"
      }
    },
    "38": {
      "inputs": {
        "model": [
          "46",
          0
        ],
        "conditioning": [
          "42",
          0
        ]
      },
      "class_type": "BasicGuider",
      "_meta": {
        "title": "BasicGuider"
      }
    },
    "39": {
      "inputs": {
        "filename_prefix": "ComfyUI",
        "images": [
          "8",
          0
        ]
      },
      "class_type": "SaveImage",
      "_meta": {
        "title": "Save Image"
      }
    },
    "40": {
      "inputs": {
        "noise": [
          "45",
          0
        ],
        "guider": [
          "38",
          0
        ],
        "sampler": [
          "47",
          0
        ],
        "sigmas": [
          "17",
          0
        ],
        "latent_image": [
          "44",
          0
        ]
      },
      "class_type": "SamplerCustomAdvanced",
      "_meta": {
        "title": "SamplerCustomAdvanced"
      }
    },
    "42": {
      "inputs": {
        "guidance": 3.5,
        "conditioning": [
          "43",
          0
        ]
      },
      "class_type": "FluxGuidance",
      "_meta": {
        "title": "FluxGuidance"
      }
    },
    "43": {
      "inputs": {
        "text": "best quality,a cute anime girl,sunshine,soft features,swing,a blue white edged dress,solo,flower,blue eyes,blush,blue flower,long hair,barefoot,sitting,looking at viewer,blue rose,blue theme,rose,light particles,pale skin,blue background,off shoulder,full body,smile,collarbone,long hair,blue hair,vines,plants,",
        "clip": [
          "11",
          0
        ]
      },
      "class_type": "CLIPTextEncode",
      "_meta": {
        "title": "CLIP Text Encode (Prompt)"
      }
    },
    "44": {
      "inputs": {
        "width": 1024,
        "height": 1024,
        "batch_size": 1
      },
      "class_type": "EmptySD3LatentImage",
      "_meta": {
        "title": "EmptySD3LatentImage"
      }
    },
    "45": {
      "inputs": {
        "noise_seed": 1114957019097397
      },
      "class_type": "RandomNoise",
      "_meta": {
        "title": "RandomNoise"
      }
    },
    "46": {
      "inputs": {
        "max_shift": 1.15,
        "base_shift": 0.5,
        "width": 1024,
        "height": 1024,
        "model": [
          "48",
          0
        ]
      },
      "class_type": "ModelSamplingFlux",
      "_meta": {
        "title": "ModelSamplingFlux"
      }
    },
    "47": {
      "inputs": {
        "sampler_name": "euler"
      },
      "class_type": "KSamplerSelect",
      "_meta": {
        "title": "KSamplerSelect"
      }
    },
    "48": {
      "inputs": {
        "unet_name": "flux1-dev.safetensors",
        "weight_dtype": "default"
      },
      "class_type": "UNETLoader",
      "_meta": {
        "title": "Load Diffusion Model"
      }
    }
  },
  "api_key": "Your API key"
}

Input Request

Sending Request and Viewing Response

Click the "Send" button in the upper-right corner to send the request, and you can view the API response in the response area.

The images field in the API response contains an array of base64-encoded image data, which you need to decode to get the actual image files. Response Result

After decoding the returned base64 encoding, the final image obtained is as follows: Decoded Image

3. Calling the API via Python Code

You can also call this API interface programmatically. Below is our reference example code.

Environment Setup

requests is a popular Python HTTP library used for sending HTTP requests.

If you haven't installed requests yet, please use the following command to install it:

pip install requests

Or install using conda:

conda install requests

Python Example Code

Next, you need to prepare a workflow configuration file using the method described above, then name it "prompt.json".

Then, create a Python file in the same directory, for example "test_api.py", and copy the example code below:

test_api.py
import requests
import json

# Configuration section
url = "https://anycomfy.com/api/prompt"
api_key = "xxxxxxxx"  # Replace with your API key
json_file_path = "prompt.json"  # Ensure the file exists

# Read local JSON file
try:
    with open(json_file_path, "r", encoding="utf-8") as f:
        prompt_data = json.load(f)
except FileNotFoundError:
    print(f"Error: File {json_file_path} not found.")
    exit(1)
except json.JSONDecodeError:
    print(f"Error: File {json_file_path} is not a valid JSON format.")
    exit(1)

# Construct request payload
payload = {
    "prompt": prompt_data,
    "api_key": api_key
}

# Send POST request
try:
    response = requests.post(url, json=payload)
except requests.exceptions.ConnectionError:
    print("Connection failed, please check your internet connection or confirm if anycomfy.com is accessible.")
    exit(1)

# Output response results
print("Status code:", response.status_code)
print("Response content:")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except json.JSONDecodeError:
    print(response.text)

Project Structure

prompt.json
test_api.py

Execution Results

Run the Python file in the console:

python test_api.py

If everything goes well, you will see output similar to the following:

Status code: 200
Response content:
{
  "images": ["base64-encoded image data"],
  "elapsed": 1.183,
  "cost": 0.01
}
  • images: Array containing base64-encoded image data
  • elapsed: Task execution time (in seconds)
  • cost: Number of credits consumed

Python Output

4. Important Notes

  1. Please keep your API key secure
  2. Ensure the workflow file format is correct
  3. Pay attention to credit consumption from API calls
  4. Consider adding retry mechanisms when network connections are unstable

Newsletter

Join the community

Subscribe to our newsletter for the latest news and updates