comfy-api-proxy-go

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT

README

comfy-api-proxy-go

Go Reference CI Release

The Comfy API v2 in front of your own ComfyUI, as one Go binary, plus a Go SDK for it.

Code written for Comfy Cloud runs against a ComfyUI on your own GPU by changing its base URL. The proxy turns each v2 call (jobs, live events, assets) into calls on ComfyUI's native API. It is a Go port of Comfy-Org's Python comfy-api-proxy, and that project's own HTTP test suite passes against it, 82 of 82.

[!IMPORTANT] Independent project. Not an official ComfyUI or Comfy Org project, and not affiliated with or endorsed by Comfy Org. Comfy and ComfyUI are trademarks of Comfy Org.

Documentation: comfy-proxy.regiellis.com, with search and an llms.txt. The source is in docs/.

Why

ComfyUI has no official Go SDK and no Go proxy. A Go program that drives ComfyUI otherwise runs a Python service beside it, or speaks ComfyUI's native HTTP and WebSocket API directly, which has no job ids, no stable output ids, and no error envelope. This project is for Go developers who would rather stay in Go: the proxy deploys as a single static file, and the SDK gives a Go program the job model Comfy Cloud's clients use, against a local ComfyUI or Comfy Cloud alike.

Install

Download a binary for Linux, macOS, or Windows from Releases, or:

go install github.com/regiellis/comfy-api-proxy-go/cmd/comfy-api-proxy@latest

The binary is static (no libc, no Python). See Install.

Quick start

With ComfyUI on its default 127.0.0.1:8188:

comfy-api-proxy                                   # serves http://127.0.0.1:8189
curl -s http://127.0.0.1:8189/api/v2/health
jq '{workflow: .}' workflow.json | curl -s -X POST http://127.0.0.1:8189/api/v2/jobs \
  -H 'Content-Type: application/json' --data @-

workflow.json is ComfyUI's Export (API). Quick start follows the job to its downloaded output.

From Go

// wf is ComfyUI's Export (API), loaded with sdk.WorkflowFromJSON.
client, err := sdk.New(sdk.WithBaseURL("http://127.0.0.1:8189"))
if err != nil {
	log.Fatal(err)
}
job, err := client.Run(ctx, wf, sdk.SubmitOptions{}) // submit and wait
if err != nil {
	log.Fatal(err)
}
for _, out := range job.Outputs() {
	if err := out.ToFile(ctx, out.Name(), nil); err != nil {
		log.Fatal(err)
	}
}

The same client talks to Comfy Cloud and Comfy Router. See Go SDK and Comfy Cloud and Router.

What it does

  • Jobs and live events: submit, read, list, and cancel, with a Server-Sent Events stream per job bridged from ComfyUI's WebSocket.
  • Assets: uploads stream to disk while hashed, deduplicated by hash, with guarded model placement into ComfyUI's folders.
  • Safe by default: loopback only, a token for any other bind, cross-site browser requests blocked. See Remote access.
  • Operations: flags, environment, or a TOML file, a background start/stop/status, and optional SQLite state.

Compared with the Python proxy

Same wire contract and security model. On one machine, the Go proxy served 6 to 12 times the requests per second, started in 6 ms against 80 ms, and held 64 MB uploads in 19 MB of memory where the Python proxy peaked at 298 MB. Per core, its uploads are slower. Benchmarks has the method and every number, and Differences lists each behavior change and why.

Development

Go 1.26 and Task. The conformance and e2e suites also need uv. They fetch Comfy-Org's Python proxy and SDK at pinned commits.

task build          # bin/comfy-api-proxy
task check          # lint, Go tests, the Python proxy's suite against this binary, e2e
task bench          # this proxy against the Python reference
task site           # the docs site on this machine

License

MIT. The Python proxy and Python SDK it ports are Comfy-Org's, also MIT-licensed.

Directories

Path Synopsis
cmd
comfy-api-proxy command
Command comfy-api-proxy serves the Comfy API v2 in front of a self-hosted ComfyUI.
Command comfy-api-proxy serves the Comfy API v2 in front of a self-hosted ComfyUI.
comfy-demo command
Command comfy-demo runs one workflow through the Go SDK against a Comfy API v2 deployment and downloads its outputs.
Command comfy-demo runs one workflow through the Go SDK against a Comfy API v2 deployment and downloads its outputs.
proxybench command
Command proxybench measures the Go proxy against the Python reference on this machine: throughput and latency per endpoint, startup time, and memory, with both proxies in front of the same upstream.
Command proxybench measures the Go proxy against the Python reference on this machine: throughput and latency per endpoint, startup time, and memory, with both proxies in front of the same upstream.
internal
comfy
Package comfy is the HTTP client for ComfyUI's native API.
Package comfy is the HTTP client for ComfyUI's native API.
config
Package config resolves the proxy's settings from defaults, a TOML file, COMFY_PROXY_* environment variables, and flags, in that order of precedence.
Package config resolves the proxy's settings from defaults, a TOML file, COMFY_PROXY_* environment variables, and flags, in that order of precedence.
httpx
Package httpx holds the response helpers every v2 handler shares.
Package httpx holds the response helpers every v2 handler shares.
proxy
Package proxy implements the Comfy API v2 surface over one ComfyUI.
Package proxy implements the Comfy API v2 surface over one ComfyUI.
server
Package server owns the listener and the HTTP server lifecycle.
Package server owns the listener and the HTTP server lifecycle.
service
Package service runs the proxy in the background: start spawns a detached copy of this binary, records its PID and address, and waits for it to bind; stop and status find it again through that record.
Package service runs the proxy in the background: start spawns a detached copy of this binary, records its PID and address, and waits for it to bind; stop and status find it again through that record.
state
Package state is the --state-dir SQLite store behind the proxy's in-memory indexes: job records, Idempotency-Key claims, the asset index, and the output-id signing secret.
Package state is the --state-dir SQLite store behind the proxy's in-memory indexes: job records, Idempotency-Key claims, the asset index, and the output-id signing secret.
ui
Package ui renders everything the CLI prints.
Package ui renders everything the CLI prints.
Package sdk is a Go client for the Comfy API v2: Comfy Cloud, or any deployment that speaks the same contract, such as comfy-api-proxy in front of a self-hosted ComfyUI.
Package sdk is a Go client for the Comfy API v2: Comfy Cloud, or any deployment that speaks the same contract, such as comfy-api-proxy in front of a self-hosted ComfyUI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL