Extensions/Workflow to API Converter Endpoint
ComfyUI Extension

Workflow to API Converter Endpoint

Adds a global /workflow/convert API endpoint to convert non-API workflow formats to API format for ComfyUI execution

By SethRobinson·Created 12 months ago·Updated 5 months ago· 51
SethRobinson/comfyui-workflow-to-api-converter-endpoint
Nodes1
On cloudLocal install
Categoryapi
Stars51
Updated5 months ago
Readme

ComfyUI Workflow Converter Endpoint

Overview

A ComfyUI custom node that adds a /workflow/convert endpoint to convert non-API workflow formats to API format. The "Save (API)" client-end Javascript logic has been converted to python so it can run server-side.

Why is this needed?

Ok, here's the deal, you export your workflow, and from your own custom app you call ComfyUI's prompt endpoint to execute it. Well, joke's on you because it gets an error. Why? You can't run workflows directly, you need to choose "Export (API)" which is an option you'll only see if you've enabled developer mode for some reason.

So you think, cool, I'll just use that. Well, it works, but later you decide you need to edit your workflow a bit and you drag and drop your "API" version into ComfyUI and low and behold, it's a skeleton of a real workflow, it's missing stuff! You you better hope you saved a copy of the ORIGINAL full workflow.

So this solution allows you to only work with "full workflows", you just have your app do the extra step of converting the workflow to an "API" version before using it. In my app, I check filedates and cache it out.

The result? I no longer have to manually save two versions of my workflows to use with the API, just the "full".

(Want an example? My Unity-based AI Tools project requires it. It's a project that controls ComfyUI and LLM servers to do fun stuff)

-Seth

Disclaimer

How robust is this? It handled all my workflows perfectly (even large 200 KB ones using Flux, Wan 2.2, etc) but your results may vary, no promises.

Features

  • Converts non-API workflows to the exact format produced by ComfyUI's "Save (API)" function
  • Uses ComfyUI's actual node registry for accurate conversion
  • Properly handles list and dictionary widget, subgraphs (including nested), etc
  • Preserves Unicode characters (Chinese, Japanese, emojis, etc.) correctly
  • Returns something that is ready to send to the /prompt endpoint, same as the original Javascript based web Export (API) option would've created
  • Hardening: Limits requests to max 1 MB workflow size, recursion depth limit is 100, no traceback exposure to clients

Version History

V2.3.0 - Fixed combo widget values with wrong capitalization being rejected by ComfyUI's validator (e.g. "True" vs "true"). Combo values are now normalized against the node's allowed options via case-insensitive matching. (thanks to ha7v for reporting issue #13)

V2.2.0 - Now properly ignoring the new 'reroute' nodes, fixed issue with tuples

V2.1.0 - Fixed missing default values for required inputs (e.g., device field in LTXAVTextEncoderLoader). The converter now includes default values from node INPUT_TYPES() for inputs not explicitly set in the workflow, matching the official "Save (API)" output.

V2.09 - Fixed subgraph input slot mapping (inputs at different positions in outer node vs subgraph definition), fixed output node exclusion when node class unavailable, added support for COMFY_DYNAMICCOMBO_V3 widgets with dynamic sub-inputs (e.g., ResizeImageMaskNode)

V2.08 - Fixed GetNode/SetNode routing issue that I had with a very complex workflow with lots of subgraphs and FastGroupBypassers that results in a failed conversion

V2.07 - Fixed subgraph internal link IDs conflicting with workflow link IDs, causing missing input connections in rare cases

V2.06 - Security hardening: added request size limit (1 MB), input validation, recursion depth limits, and removed traceback exposure to clients

V2.05 - Added marker node for ComfyUI Manager workflow dependency detection

V2.04 - Fixed conversion of bypassed passthrough nodes for real

V2.03 - Fixed conversion of bypassed kjnodes (WidgetToString, Number to Int, Text to Number) - no more "Exception when validating node" errors for bypassed nodes, target nodes now fall back to widget values when sources are bypassed (thanks to LORDofDOOM for PR #5)

V2.02 - Fixed bug with subgraphs (thanks to v3i1y for reporting this bug), now also shows version # to the ComfyUI log when used

Installation

Method 1: Install via ComfyUI Manager (Recommended)

Open ComfyUI Manager and click the "Custom Nodes Manager" button. Search for "Workflow to API Converter Endpoint" and click "Install".

Note: If you're using the new Node Manager (the default with the Windows build), you might not see it. In that case, you can enable the "legacy" custom node manager and it will show up - see screenshot below:

Legacy Custom Node Manager in ComfyUI

Method 2: Manual Git Clone

This works too - you can run this directly on the machine, or in the "Terminal" of ComfyUI

cd ComfyUI/custom_nodes
git clone https://github.com/SethRobinson/comfyui-workflow-to-api-converter-endpoint

After Installation

Restart ComfyUI and the /workflow/convert endpoint will be automatically available.

Usage

The endpoint is automatically available after installation. No workflow changes needed.

Optional: You can add the "Workflow to API Converter (Marker)" node to your workflow. This helps ComfyUI Manager detect the dependency when sharing workflows with others.

Send a POST request to /workflow/convert with a non-API workflow JSON (for example, one you exported from ComfyUI using "Save" not "Save (API)") to get back the API format:

import json
import requests

# Load a non-API workflow JSON from disk
with open("workflow.json", "r", encoding="utf-8") as f:
    workflow = json.load(f)

# Convert to API format
response = requests.post("http://localhost:8188/workflow/convert", json=workflow)
response.raise_for_status()
api_format = response.json()

# Optionally modify parameters in api_format here (e.g., seed, model, etc.)

# Execute the API-format workflow
execute_response = requests.post("http://localhost:8188/prompt", json={"prompt": api_format})
execute_response.raise_for_status()

Using curl

  • Convert a non-API workflow.json to API format and save as api_workflow.json (bash/zsh):
curl -s -X POST "http://localhost:8188/workflow/convert" \
  -H "Content-Type: application/json" \
  --data-binary @workflow.json > api_workflow.json

Credits

Created by Seth A. Robinson

This project was developed with assistance from AI tools for code generation and documentation.