/comfy-sdk:comfy-sdkfrom comfy-sdk
Build apps that generate images, video, or audio via Comfy Router using the Python or TypeScript Comfy SDK. Covers client setup, credential management, model discovery, and API patterns for synchronous and async generation.
Ships in comfy-sdk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Steering only. Model names, schemas, prices and default timeouts change: discover them at run time (section 3) or read them off the installed SDK, and never paste one from memory.
https://api.comfy.org) is reached through the
models namespace:
Comfy().models (AsyncComfy().models for asyncio).comfy.models, after comfy.config({ credentials })
or with COMFY_API_KEY set. new Comfy({ apiKey }) is the Comfy Cloud
workflow client and has no .models./api/v2/jobs, run a ComfyUI workflow) is the class client in both SDKs.COMFY_API_KEY. Hosts are separate: COMFY_ROUTER_BASE_URL
redirects Router, COMFY_BASE_URL redirects Cloud. Leave both unset in production.from comfy_sdk import Comfy
client = Comfy() # reads COMFY_API_KEY
result = client.models.run("<provider>/<model>", {<provider's native body>})
import { comfy } from "@comfyorg/sdk";
comfy.config({ credentials: process.env.COMFY_API_KEY });
const { kind, data, requestId } = await comfy.models.run("<provider>/<model>", {<native body>});
COMFY_API_KEY from the process environment; neither loads a
.env file. Your framework does that (python-dotenv, Next.js .env.local,
etc.). An explicit api_key= / credentials argument always wins over the variable.NEXT_PUBLIC_ / VITE_ prefix). Call
Router from a server route and return the result to the page.401 there means the
key, not the model, is wrong.GET /v2/models lists what the credential can run, with billing facts. Paginate
with next_cursor while has_more is true; treat cursors as opaque.GET /v2/models/{provider}/{model}/openapi.json is that model's input/output schema.
The second argument to run / submit is the provider's native body, forwarded
unchanged, so build it from this schema, not from another provider's shape.comfy.models.list() walks the catalog and
comfy.models.schema(model) fetches the document. In Python, if the installed
client.models has no such helper, call the two routes on the Router host
yourself with Authorization: Bearer <COMFY_API_KEY>.provider/model.run, submit or subscriberun blocks until the generation is finished. The wait is server side:
Router holds the connection up to its own deadline, then answers
504 deadline_exceeded. The SDK retries that with the same Idempotency-Key
and Retry-After, collecting the running generation rather than starting a
second one.submit returns a handle with a request_id at once. Use it in any web request
handler, serverless function or job queue that cannot hold a connection for
minutes. Collect later, even from another process, with
models.handle(model, request_id) then get() / status() / cancel().subscribe is submit + poll + collect with a progress callback. Its timeout is
client side only; when it expires it makes one best-effort cancel. A
generation already running at the partner completes and is billed regardless.submit / handle / subscribe need comfy-sdk / @comfyorg/sdk
0.3.0 or newer.models.run(..., timeout=) is seconds and defaults to the SDK's own
run timeout, sized to Router's deadline. Comfy(timeout=...) sizes ordinary API
calls and does not change the run default.{ timeoutMs } is milliseconds; its default is longer than
Router's deadline so a same-key collect still fits. Prefer an AbortSignal to
timeoutMs: null.run signature, DEFAULT_RUN_TIMEOUT_MS) instead of hard-coding a number.submit instead of lowering the timeout.run / submit mints an Idempotency-Key and reuses it for its own
retries, so a retried attempt is charged at most once. Calling run again is a
new key and a new charge: do not wrap it in your own retry loop.idempotency_key= / { idempotencyKey } yourself and keep the body identical;
the same key with a different body is refused 409 invalid_input (use a new key).A Router error response carries Router's wire bucket (also the
X-Comfy-Error-Type header), but where you read it depends on the language and
the call:
comfy_sdk.router_exceptions, all descending from RouterError; read
exc.error_type.comfy.models.run (synchronous): throws ComfyError and its
subclasses (InsufficientCredits, Forbidden, Unauthorized, NotFound),
not routerErrors.*. Read err.code; there is no errorType, and
instanceof routerErrors.RouterError is false.submit / handle / subscribe): a Router error
response throws routerErrors.*, all descending from
routerErrors.RouterError; read err.errorType.Failures on the client side are not Router responses and carry no bucket:
ComfyError (Python and TypeScript). An unreadable reply
is code invalid_response in Python and on the TypeScript queued calls, but
unexpected_response from TypeScript comfy.models.run. A TypeScript queued
call exceeding timeoutMs is request_timeout.httpx.HTTPError in Python, a
native TypeError from fetch in TypeScript.subscribe past its timeout= raises
TimeoutError (a run past its timeout= is a transport read timeout).
A TypeScript caller's own AbortSignal rethrows its abort reason unchanged
(an AbortError by default).So a TypeScript app needs a ComfyError catch on both paths, a
routerErrors.RouterError catch on the queued one, and a final catch for
transport errors and its own aborts; a Python app catches RouterError, then
ComfyError, httpx.HTTPError and TimeoutError.
insufficient_credits (402): stop and tell the user to add credits. Never retry.content_policy_violation: do not resend the same prompt.rate_limited / concurrency_limit_exceeded (429): wait Retry-After, then
resend. Python run does this for you. TypeScript does not retry a 429;
wait err.retryAfter seconds yourself, or tell the user to try again.not_enabled (403): the workspace is not on this model or route yet; terminal.provider_timeout vs deadline_exceeded: both 504; the first is the partner,
the second is Comfy's bound. The SDK retries the second with the same key.RouterError in Python and for Router responses on the TypeScript queued path,
ComfyError from TypeScript run and from SDK-raised client-side failures.COMPLETED with an error_type; get() raises
the typed error, and the event iterator yields it as the last observation.run returns the provider's payload as-is. TypeScript returns
{ kind, data, requestId } (kind is "json" or "binary"; branch on it) and
caps the buffered body (maxBytes).GET /v2/models succeeds.openapi.json.run only where the process can wait minutes; otherwise submit.insufficient_credits surfaced to the user, not retried.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub comfy-org/comfy-skills --plugin comfy-sdkOther plugins' skills for the same job