[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6XFN4W7Q40TFEHZSH3XQQ9N":3,"skill-same:01M6XFN4W7Q40TFEHZSH3XQQ9N":100},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":34,"publishedAt":55,"linkOnly":56,"markdownContent":57,"markdownBody":58,"frontMatter":59,"refName":70,"commitSha":71,"skillDirectory":72,"forksCount":14,"repositoryHtmlUrl":73,"repositoryHomepageUrl":6,"ownerHtmlUrl":74,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":75,"install":76,"resources":89},"01M6XFN4W7Q40TFEHZSH3XQQ9N","comfyui-gateway",null,"REST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).","sapsapshen\u002Fai-memory-router","sapsapshen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F20347959?v=4","01M6XDQEF1DP50DKF37H81J3J5","shenmian","01M6XDQEJPE41Y3DT2763X8ZJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcopilot\u002Fcomfyui-gateway\u002FSKILL.md",[18,23,26,29],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000016","图像与多媒体",{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":30,"categoryName":31,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54],"comfyui gateway","gateway","comfyui","2026","image","rate","URL","caching","delivery","community","image-generation","webhooks","api","base64","code","auth","workflow","typescript","safe","cli","2026-11-10 10:12:30",false,"---\nname: comfyui-gateway\ndescription: REST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\nrisk: safe\nsource: community\ndate_added: '2026-03-06'\nauthor: renat\ntags:\n- comfyui\n- api-gateway\n- image-generation\n- typescript\ntools:\n- claude-code\n- antigravity\n- cursor\n- gemini-cli\n- codex-cli\n---\n\n# ComfyUI Gateway\n\n## Overview\n\nREST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\n\n## When to Use This Skill\n\n- When the user mentions \"comfyui\" or related topics\n- When the user mentions \"comfy ui\" or related topics\n- When the user mentions \"stable diffusion api gateway\" or related topics\n- When the user mentions \"gateway comfyui\" or related topics\n- When the user mentions \"api gateway imagens\" or related topics\n- When the user mentions \"queue imagens\" or related topics\n\n## Do Not Use This Skill When\n\n- The task is unrelated to comfyui gateway\n- A simpler, more specific tool can handle the request\n- The user needs general-purpose assistance without domain expertise\n\n## How It Works\n\nA production-grade REST API gateway that transforms any ComfyUI server into a universal,\nsecure, and scalable service. Supports workflow templates with placeholders, job queuing\nwith priorities, webhook callbacks, result caching, and multiple storage backends.\n\n## Architecture Overview\n\n```\n┌─────────────┐     ┌──────────────────────────────────┐     ┌──────────┐\n│   Clients    │────▶│        ComfyUI Gateway           │────▶│ ComfyUI  │\n│ (curl, n8n,  │     │                                  │     │ Server   │\n│  Claude,     │     │  ┌─────────┐  ┌──────────────┐  │     │ (local\u002F  │\n│  Lovable,    │     │  │ Fastify │  │ BullMQ Queue │  │     │  remote) │\n│  Supabase)   │     │  │ API     │──│ (or in-mem)  │  │     └──────────┘\n│              │◀────│  └─────────┘  └──────────────┘  │\n│              │     │  ┌─────────┐  ┌──────────────┐  │     ┌──────────┐\n│              │     │  │ Auth +  │  │ Storage      │  │────▶│ S3\u002FMinIO │\n│              │     │  │ RateL.  │  │ (local\u002FS3)   │  │     │(optional)│\n│              │     │  └─────────┘  └──────────────┘  │     └──────────┘\n└─────────────┘     └──────────────────────────────────┘\n```\n\n## Components\n\n| Component | Purpose | File(s) |\n|-----------|---------|---------|\n| **API Gateway** | REST endpoints, validation, CORS | `src\u002Fapi\u002F` |\n| **Worker** | Processes jobs, talks to ComfyUI | `src\u002Fworker\u002F` |\n| **ComfyUI Client** | HTTP + WebSocket to ComfyUI | `src\u002Fcomfyui\u002F` |\n| **Workflow Manager** | Template storage, placeholder rendering | `src\u002Fworkflows\u002F` |\n| **Storage Provider** | Local disk + S3-compatible | `src\u002Fstorage\u002F` |\n| **Cache** | Hash-based deduplication | `src\u002Fcache\u002F` |\n| **Notifier** | Webhook with HMAC signing | `src\u002Fnotifications\u002F` |\n| **Auth** | API key + JWT + rate limiting | `src\u002Fauth\u002F` |\n| **DB** | SQLite (better-sqlite3) or Postgres | `src\u002Fdb\u002F` |\n| **CLI** | Init, add-workflow, run, worker | `src\u002Fcli\u002F` |\n\n## Quick Start\n\n```bash\n\n## 1. Install\n\ncd comfyui-gateway\nnpm install\n\n## 2. Configure\n\ncp .env.example .env\n\n## 3. Initialize\n\nnpx tsx src\u002Fcli\u002Findex.ts init\n\n## 4. Add A Workflow\n\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow .\u002Fworkflows\u002Fsdxl_realism_v1.json \\\n  --id sdxl_realism_v1 --schema .\u002Fworkflows\u002Fsdxl_realism_v1.schema.json\n\n## 5. Start (Api + Worker In One Process)\n\nnpm run dev\n\n## Or Separately:\n\nnpm run start:api   # API only\nnpm run start:worker # Worker only\n```\n\n## Environment Variables\n\nAll configuration is via `.env` — nothing is hardcoded:\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `PORT` | `3000` | API server port |\n| `HOST` | `0.0.0.0` | API bind address |\n| `COMFYUI_URL` | `http:\u002F\u002F127.0.0.1:8188` | ComfyUI server URL |\n| `COMFYUI_TIMEOUT_MS` | `300000` | Max wait for ComfyUI (5min) |\n| `API_KEYS` | `\"\"` | Comma-separated API keys (`key:role`) |\n| `JWT_SECRET` | `\"\"` | JWT signing secret (empty = JWT disabled) |\n| `REDIS_URL` | `\"\"` | Redis URL (empty = in-memory queue) |\n| `DATABASE_URL` | `.\u002Fdata\u002Fgateway.db` | SQLite path or Postgres URL |\n| `STORAGE_PROVIDER` | `local` | `local` or `s3` |\n| `STORAGE_LOCAL_PATH` | `.\u002Fdata\u002Foutputs` | Local output directory |\n| `S3_ENDPOINT` | `\"\"` | S3\u002FMinIO endpoint |\n| `S3_BUCKET` | `\"\"` | S3 bucket name |\n| `S3_ACCESS_KEY` | `\"\"` | S3 access key |\n| `S3_SECRET_KEY` | `\"\"` | S3 secret key |\n| `S3_REGION` | `us-east-1` | S3 region |\n| `WEBHOOK_SECRET` | `\"\"` | HMAC signing secret for webhooks |\n| `WEBHOOK_ALLOWED_DOMAINS` | `*` | Comma-separated allowed callback domains |\n| `MAX_CONCURRENCY` | `1` | Parallel jobs per GPU |\n| `MAX_IMAGE_SIZE` | `2048` | Maximum dimension (width or height) |\n| `MAX_BATCH_SIZE` | `4` | Maximum batch size |\n| `CACHE_ENABLED` | `true` | Enable result caching |\n| `CACHE_TTL_SECONDS` | `86400` | Cache TTL (24h) |\n| `RATE_LIMIT_MAX` | `100` | Requests per window |\n| `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit window (1min) |\n| `LOG_LEVEL` | `info` | Pino log level |\n| `PRIVACY_MODE` | `false` | Redact prompts from logs |\n| `CORS_ORIGINS` | `*` | Allowed CORS origins |\n| `NODE_ENV` | `development` | Environment |\n\n## Health & Capabilities\n\n```\nGET \u002Fhealth\n→ { ok: true, version, comfyui: { reachable, url, models? }, uptime }\n\nGET \u002Fcapabilities\n→ { workflows: [...], maxSize, maxBatch, formats, storageProvider }\n```\n\n## Workflows (Crud)\n\n```\nGET    \u002Fworkflows            → list all workflows\nPOST   \u002Fworkflows            → register new workflow\nGET    \u002Fworkflows\u002F:id        → workflow details + input schema\nPUT    \u002Fworkflows\u002F:id        → update workflow\nDELETE \u002Fworkflows\u002F:id        → remove workflow\n```\n\n## Jobs\n\n```\nPOST   \u002Fjobs                 → create job (returns jobId immediately)\nGET    \u002Fjobs\u002F:jobId          → status + progress + outputs\nGET    \u002Fjobs\u002F:jobId\u002Flogs     → sanitized execution logs\nPOST   \u002Fjobs\u002F:jobId\u002Fcancel   → request cancellation\nGET    \u002Fjobs                 → list jobs (filters: status, workflowId, after, before, limit)\n```\n\n## Outputs\n\n```\nGET    \u002Foutputs\u002F:jobId       → list output files + metadata\nGET    \u002Foutputs\u002F:jobId\u002F:file → download\u002Fstream file\n```\n\n## Job Lifecycle\n\n```\nqueued → running → succeeded\n                 → failed\n                 → canceled\n```\n\n1. Client POSTs to `\u002Fjobs` with workflowId + inputs\n2. Gateway validates, checks cache, checks idempotency\n3. If cache hit → returns existing outputs immediately (status: `cache_hit`)\n4. Otherwise → enqueues job, returns `jobId` + `pollUrl`\n5. Worker picks up job, renders workflow template, submits to ComfyUI\n6. Worker polls ComfyUI for progress (or listens via WebSocket)\n7. On completion → downloads outputs, stores them, updates DB\n8. If callbackUrl → sends signed webhook POST\n9. Client polls `\u002Fjobs\u002F:jobId` or receives webhook\n\n## Workflow Templates\n\nWorkflows are ComfyUI JSON with `{{placeholder}}` tokens. The gateway resolves\nthese at runtime using the job's `inputs` and `params`:\n\n```json\n{\n  \"3\": {\n    \"class_type\": \"KSampler\",\n    \"inputs\": {\n      \"seed\": \"{{seed}}\",\n      \"steps\": \"{{steps}}\",\n      \"cfg\": \"{{cfg}}\",\n      \"sampler_name\": \"{{sampler}}\",\n      \"scheduler\": \"normal\",\n      \"denoise\": 1,\n      \"model\": [\"4\", 0],\n      \"positive\": [\"6\", 0],\n      \"negative\": [\"7\", 0],\n      \"latent_image\": [\"5\", 0]\n    }\n  },\n  \"6\": {\n    \"class_type\": \"CLIPTextEncode\",\n    \"inputs\": {\n      \"text\": \"{{prompt}}\",\n      \"clip\": [\"4\", 1]\n    }\n  }\n}\n```\n\nEach workflow has an `inputSchema` (Zod) that validates what the client sends.\n\n## Security Model\n\n- **API Keys**: `X-API-Key` header; keys configured via `API_KEYS` env var as `key1:admin,key2:user`\n- **JWT**: Optional; when `JWT_SECRET` is set, accepts `Authorization: Bearer \u003Ctoken>`\n- **Roles**: `admin` (full CRUD on workflows + jobs), `user` (create jobs, read own jobs)\n- **Rate Limiting**: Per key + per IP, configurable window and max\n- **Webhook Security**: HMAC-SHA256 signature in `X-Signature` header\n- **Callback Allowlist**: Only approved domains receive webhooks\n- **Privacy Mode**: When enabled, prompts are redacted from logs and DB\n- **Idempotency**: `metadata.requestId` prevents duplicate processing\n- **CORS**: Configurable allowed origins\n- **Input Validation**: Zod schemas on every endpoint; max size\u002Fbatch enforced\n\n## Comfyui Integration\n\nThe gateway communicates with ComfyUI via its native HTTP API:\n\n| ComfyUI Endpoint | Gateway Usage |\n|------------------|---------------|\n| `POST \u002Fprompt` | Submit rendered workflow |\n| `GET \u002Fhistory\u002F{id}` | Poll job completion |\n| `GET \u002Fview?filename=...` | Download generated images |\n| `GET \u002Fobject_info` | Discover available nodes\u002Fmodels |\n| `WS \u002Fws?clientId=...` | Real-time progress (optional) |\n\nThe client auto-detects ComfyUI version and adapts:\n- Tries WebSocket first for progress, falls back to polling\n- Handles both `\u002Fhistory` response formats\n- Detects OOM errors and classifies them with recommendations\n\n## Cache Strategy\n\nCache key = SHA-256 of `workflowId + sorted(inputs) + sorted(params) + checkpoint`.\nOn cache hit, the gateway returns a \"virtual\" job with pre-existing outputs — no GPU\ncomputation needed. Cache is stored alongside job data in the DB with configurable TTL.\n\n## Error Classification\n\n| Error Code | Meaning | Retry? |\n|------------|---------|--------|\n| `COMFYUI_UNREACHABLE` | Cannot connect to ComfyUI | Yes (with backoff) |\n| `COMFYUI_OOM` | Out of memory on GPU | No (reduce dimensions) |\n| `COMFYUI_TIMEOUT` | Execution exceeded timeout | Maybe (increase timeout) |\n| `COMFYUI_NODE_ERROR` | Node execution failed | No (check workflow) |\n| `VALIDATION_ERROR` | Invalid inputs | No (fix request) |\n| `WORKFLOW_NOT_FOUND` | Unknown workflowId | No (register workflow) |\n| `RATE_LIMITED` | Too many requests | Yes (wait) |\n| `AUTH_FAILED` | Invalid\u002Fmissing credentials | No (fix auth) |\n| `CACHE_HIT` | (Not an error) Served from cache | N\u002FA |\n\n## Bundled Workflows\n\nThree production-ready workflow templates are included:\n\n## 1. `Sdxl_Realism_V1` — Photorealistic Generation\n\n- Checkpoint: SDXL base\n- Optimized for: Portraits, landscapes, product shots\n- Default: 1024x1024, 30 steps, cfg 7.0\n\n## 2. `Sprite_Transparent_Bg` — Game Sprites With Alpha\n\n- Checkpoint: SD 1.5 or SDXL\n- Optimized for: 2D game assets, transparent backgrounds\n- Default: 512x512, 25 steps, cfg 7.5\n\n## 3. `Icon_512` — App Icons With Optional Upscale\n\n- Checkpoint: SDXL base\n- Optimized for: Square icons, clean edges\n- Default: 512x512, 20 steps, cfg 6.0, optional 2x upscale\n\n## Observability\n\n- **Structured Logs**: Pino JSON logs with `correlationId` on every request\n- **Metrics**: Jobs queued\u002Frunning\u002Fsucceeded\u002Ffailed, avg processing time, cache hit rate\n- **Audit Log**: Admin actions (workflow CRUD, key management) logged with timestamp + actor\n\n## Cli Reference\n\n```bash\nnpx tsx src\u002Fcli\u002Findex.ts init                    # Create dirs, .env.example\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow \u003Cfile>      # Register workflow template\n  --id \u003Cid> --name \u003Cname> --schema \u003Cschema.json>\nnpx tsx src\u002Fcli\u002Findex.ts list-workflows           # Show registered workflows\nnpx tsx src\u002Fcli\u002Findex.ts run                      # Start API server\nnpx tsx src\u002Fcli\u002Findex.ts worker                   # Start job worker\nnpx tsx src\u002Fcli\u002Findex.ts health                   # Check ComfyUI connectivity\n```\n\n## Troubleshooting\n\nRead `references\u002Ftroubleshooting.md` for detailed guidance on:\n- ComfyUI not reachable (firewall, wrong port, Docker networking)\n- OOM errors (reduce resolution, batch, or steps)\n- Slow generation (GPU utilization, queue depth, model loading)\n- Webhook failures (DNS, SSL, timeout, domain allowlist)\n- Redis connection issues (fallback to in-memory)\n- Storage permission errors (local path, S3 credentials)\n\n## Integration Examples\n\nRead `references\u002Fintegration.md` for ready-to-use examples with:\n- curl commands for every endpoint\n- n8n webhook workflow\n- Supabase Edge Function caller\n- Claude Code \u002F Claude.ai integration\n- Python requests client\n- JavaScript fetch client\n\n## File Structure\n\n```\ncomfyui-gateway\u002F\n├── SKILL.md\n├── package.json\n├── tsconfig.json\n├── .env.example\n├── src\u002F\n│   ├── api\u002F\n│   │   ├── server.ts          # Fastify setup + plugins\n│   │   ├── routes\u002F\n│   │   │   ├── health.ts      # GET \u002Fhealth, \u002Fcapabilities\n│   │   │   ├── workflows.ts   # CRUD \u002Fworkflows\n│   │   │   ├── jobs.ts        # CRUD \u002Fjobs\n│   │   │   └── outputs.ts     # GET \u002Foutputs\n│   │   ├── middleware\u002F\n│   │   │   └── error-handler.ts\n│   │   └── plugins\u002F\n│   │       ├── auth.ts        # API key + JWT\n│   │       ├── rate-limit.ts\n│   │       └── cors.ts\n│   ├── worker\u002F\n│   │   └── processor.ts       # Job processor\n│   ├── comfyui\u002F\n│   │   └── client.ts          # ComfyUI HTTP + WS client\n│   ├── storage\u002F\n│   │   ├── index.ts           # Provider factory\n│   │   ├── local.ts           # Local filesystem\n│   │   └── s3.ts              # S3-compatible\n│   ├── workflows\u002F\n│   │   └── manager.ts         # Template CRUD + rendering\n│   ├── cache\u002F\n│   │   └── index.ts           # Hash-based cache\n│   ├── notifications\u002F\n│   │   └── webhook.ts         # HMAC-signed callbacks\n│   ├── auth\u002F\n│   │   └── index.ts           # Key\u002FJWT validation + roles\n│   ├── db\u002F\n│   │   ├── index.ts           # DB factory (SQLite\u002FPostgres)\n│   │   └── migrations.ts      # Schema creation\n│   ├── cli\u002F\n│   │   └── index.ts           # CLI commands\n│   ├── utils\u002F\n│   │   ├── config.ts          # Env loading + validation\n│   │   ├── errors.ts          # Error classes\n│   │   ├── logger.ts          # Pino setup\n│   │   └── hash.ts            # SHA-256 hashing\n│   └── index.ts               # Main entrypoint\n├── config\u002F\n│   └── workflows\u002F             # Bundled workflow templates\n│       ├── sdxl_realism_v1.json\n│       ├── sdxl_realism_v1.schema.json\n│       ├── sprite_transparent_bg.json\n│       ├── sprite_transparent_bg.schema.json\n│       ├── icon_512.json\n│       └── icon_512.schema.json\n├── data\u002F\n│   ├── outputs\u002F               # Generated images\n│   ├── workflows\u002F             # User-added wor\n\n## Best Practices\n\n- Provide clear, specific context about your project and requirements\n- Review all suggestions before applying them to production code\n- Combine with other complementary skills for comprehensive analysis\n\n## Common Pitfalls\n\n- Using this skill for tasks outside its domain expertise\n- Applying recommendations without understanding your specific context\n- Not providing enough project context for accurate analysis\n\n## Related Skills\n\n- `ai-studio-image` - Complementary skill for enhanced analysis\n- `image-studio` - Complementary skill for enhanced analysis\n- `stability-ai` - Complementary skill for enhanced analysis\n","# ComfyUI Gateway\n\n## Overview\n\nREST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\n\n## When to Use This Skill\n\n- When the user mentions \"comfyui\" or related topics\n- When the user mentions \"comfy ui\" or related topics\n- When the user mentions \"stable diffusion api gateway\" or related topics\n- When the user mentions \"gateway comfyui\" or related topics\n- When the user mentions \"api gateway imagens\" or related topics\n- When the user mentions \"queue imagens\" or related topics\n\n## Do Not Use This Skill When\n\n- The task is unrelated to comfyui gateway\n- A simpler, more specific tool can handle the request\n- The user needs general-purpose assistance without domain expertise\n\n## How It Works\n\nA production-grade REST API gateway that transforms any ComfyUI server into a universal,\nsecure, and scalable service. Supports workflow templates with placeholders, job queuing\nwith priorities, webhook callbacks, result caching, and multiple storage backends.\n\n## Architecture Overview\n\n```\n┌─────────────┐     ┌──────────────────────────────────┐     ┌──────────┐\n│   Clients    │────▶│        ComfyUI Gateway           │────▶│ ComfyUI  │\n│ (curl, n8n,  │     │                                  │     │ Server   │\n│  Claude,     │     │  ┌─────────┐  ┌──────────────┐  │     │ (local\u002F  │\n│  Lovable,    │     │  │ Fastify │  │ BullMQ Queue │  │     │  remote) │\n│  Supabase)   │     │  │ API     │──│ (or in-mem)  │  │     └──────────┘\n│              │◀────│  └─────────┘  └──────────────┘  │\n│              │     │  ┌─────────┐  ┌──────────────┐  │     ┌──────────┐\n│              │     │  │ Auth +  │  │ Storage      │  │────▶│ S3\u002FMinIO │\n│              │     │  │ RateL.  │  │ (local\u002FS3)   │  │     │(optional)│\n│              │     │  └─────────┘  └──────────────┘  │     └──────────┘\n└─────────────┘     └──────────────────────────────────┘\n```\n\n## Components\n\n| Component | Purpose | File(s) |\n|-----------|---------|---------|\n| **API Gateway** | REST endpoints, validation, CORS | `src\u002Fapi\u002F` |\n| **Worker** | Processes jobs, talks to ComfyUI | `src\u002Fworker\u002F` |\n| **ComfyUI Client** | HTTP + WebSocket to ComfyUI | `src\u002Fcomfyui\u002F` |\n| **Workflow Manager** | Template storage, placeholder rendering | `src\u002Fworkflows\u002F` |\n| **Storage Provider** | Local disk + S3-compatible | `src\u002Fstorage\u002F` |\n| **Cache** | Hash-based deduplication | `src\u002Fcache\u002F` |\n| **Notifier** | Webhook with HMAC signing | `src\u002Fnotifications\u002F` |\n| **Auth** | API key + JWT + rate limiting | `src\u002Fauth\u002F` |\n| **DB** | SQLite (better-sqlite3) or Postgres | `src\u002Fdb\u002F` |\n| **CLI** | Init, add-workflow, run, worker | `src\u002Fcli\u002F` |\n\n## Quick Start\n\n```bash\n\n## 1. Install\n\ncd comfyui-gateway\nnpm install\n\n## 2. Configure\n\ncp .env.example .env\n\n## 3. Initialize\n\nnpx tsx src\u002Fcli\u002Findex.ts init\n\n## 4. Add A Workflow\n\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow .\u002Fworkflows\u002Fsdxl_realism_v1.json \\\n  --id sdxl_realism_v1 --schema .\u002Fworkflows\u002Fsdxl_realism_v1.schema.json\n\n## 5. Start (Api + Worker In One Process)\n\nnpm run dev\n\n## Or Separately:\n\nnpm run start:api   # API only\nnpm run start:worker # Worker only\n```\n\n## Environment Variables\n\nAll configuration is via `.env` — nothing is hardcoded:\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `PORT` | `3000` | API server port |\n| `HOST` | `0.0.0.0` | API bind address |\n| `COMFYUI_URL` | `http:\u002F\u002F127.0.0.1:8188` | ComfyUI server URL |\n| `COMFYUI_TIMEOUT_MS` | `300000` | Max wait for ComfyUI (5min) |\n| `API_KEYS` | `\"\"` | Comma-separated API keys (`key:role`) |\n| `JWT_SECRET` | `\"\"` | JWT signing secret (empty = JWT disabled) |\n| `REDIS_URL` | `\"\"` | Redis URL (empty = in-memory queue) |\n| `DATABASE_URL` | `.\u002Fdata\u002Fgateway.db` | SQLite path or Postgres URL |\n| `STORAGE_PROVIDER` | `local` | `local` or `s3` |\n| `STORAGE_LOCAL_PATH` | `.\u002Fdata\u002Foutputs` | Local output directory |\n| `S3_ENDPOINT` | `\"\"` | S3\u002FMinIO endpoint |\n| `S3_BUCKET` | `\"\"` | S3 bucket name |\n| `S3_ACCESS_KEY` | `\"\"` | S3 access key |\n| `S3_SECRET_KEY` | `\"\"` | S3 secret key |\n| `S3_REGION` | `us-east-1` | S3 region |\n| `WEBHOOK_SECRET` | `\"\"` | HMAC signing secret for webhooks |\n| `WEBHOOK_ALLOWED_DOMAINS` | `*` | Comma-separated allowed callback domains |\n| `MAX_CONCURRENCY` | `1` | Parallel jobs per GPU |\n| `MAX_IMAGE_SIZE` | `2048` | Maximum dimension (width or height) |\n| `MAX_BATCH_SIZE` | `4` | Maximum batch size |\n| `CACHE_ENABLED` | `true` | Enable result caching |\n| `CACHE_TTL_SECONDS` | `86400` | Cache TTL (24h) |\n| `RATE_LIMIT_MAX` | `100` | Requests per window |\n| `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit window (1min) |\n| `LOG_LEVEL` | `info` | Pino log level |\n| `PRIVACY_MODE` | `false` | Redact prompts from logs |\n| `CORS_ORIGINS` | `*` | Allowed CORS origins |\n| `NODE_ENV` | `development` | Environment |\n\n## Health & Capabilities\n\n```\nGET \u002Fhealth\n→ { ok: true, version, comfyui: { reachable, url, models? }, uptime }\n\nGET \u002Fcapabilities\n→ { workflows: [...], maxSize, maxBatch, formats, storageProvider }\n```\n\n## Workflows (Crud)\n\n```\nGET    \u002Fworkflows            → list all workflows\nPOST   \u002Fworkflows            → register new workflow\nGET    \u002Fworkflows\u002F:id        → workflow details + input schema\nPUT    \u002Fworkflows\u002F:id        → update workflow\nDELETE \u002Fworkflows\u002F:id        → remove workflow\n```\n\n## Jobs\n\n```\nPOST   \u002Fjobs                 → create job (returns jobId immediately)\nGET    \u002Fjobs\u002F:jobId          → status + progress + outputs\nGET    \u002Fjobs\u002F:jobId\u002Flogs     → sanitized execution logs\nPOST   \u002Fjobs\u002F:jobId\u002Fcancel   → request cancellation\nGET    \u002Fjobs                 → list jobs (filters: status, workflowId, after, before, limit)\n```\n\n## Outputs\n\n```\nGET    \u002Foutputs\u002F:jobId       → list output files + metadata\nGET    \u002Foutputs\u002F:jobId\u002F:file → download\u002Fstream file\n```\n\n## Job Lifecycle\n\n```\nqueued → running → succeeded\n                 → failed\n                 → canceled\n```\n\n1. Client POSTs to `\u002Fjobs` with workflowId + inputs\n2. Gateway validates, checks cache, checks idempotency\n3. If cache hit → returns existing outputs immediately (status: `cache_hit`)\n4. Otherwise → enqueues job, returns `jobId` + `pollUrl`\n5. Worker picks up job, renders workflow template, submits to ComfyUI\n6. Worker polls ComfyUI for progress (or listens via WebSocket)\n7. On completion → downloads outputs, stores them, updates DB\n8. If callbackUrl → sends signed webhook POST\n9. Client polls `\u002Fjobs\u002F:jobId` or receives webhook\n\n## Workflow Templates\n\nWorkflows are ComfyUI JSON with `{{placeholder}}` tokens. The gateway resolves\nthese at runtime using the job's `inputs` and `params`:\n\n```json\n{\n  \"3\": {\n    \"class_type\": \"KSampler\",\n    \"inputs\": {\n      \"seed\": \"{{seed}}\",\n      \"steps\": \"{{steps}}\",\n      \"cfg\": \"{{cfg}}\",\n      \"sampler_name\": \"{{sampler}}\",\n      \"scheduler\": \"normal\",\n      \"denoise\": 1,\n      \"model\": [\"4\", 0],\n      \"positive\": [\"6\", 0],\n      \"negative\": [\"7\", 0],\n      \"latent_image\": [\"5\", 0]\n    }\n  },\n  \"6\": {\n    \"class_type\": \"CLIPTextEncode\",\n    \"inputs\": {\n      \"text\": \"{{prompt}}\",\n      \"clip\": [\"4\", 1]\n    }\n  }\n}\n```\n\nEach workflow has an `inputSchema` (Zod) that validates what the client sends.\n\n## Security Model\n\n- **API Keys**: `X-API-Key` header; keys configured via `API_KEYS` env var as `key1:admin,key2:user`\n- **JWT**: Optional; when `JWT_SECRET` is set, accepts `Authorization: Bearer \u003Ctoken>`\n- **Roles**: `admin` (full CRUD on workflows + jobs), `user` (create jobs, read own jobs)\n- **Rate Limiting**: Per key + per IP, configurable window and max\n- **Webhook Security**: HMAC-SHA256 signature in `X-Signature` header\n- **Callback Allowlist**: Only approved domains receive webhooks\n- **Privacy Mode**: When enabled, prompts are redacted from logs and DB\n- **Idempotency**: `metadata.requestId` prevents duplicate processing\n- **CORS**: Configurable allowed origins\n- **Input Validation**: Zod schemas on every endpoint; max size\u002Fbatch enforced\n\n## Comfyui Integration\n\nThe gateway communicates with ComfyUI via its native HTTP API:\n\n| ComfyUI Endpoint | Gateway Usage |\n|------------------|---------------|\n| `POST \u002Fprompt` | Submit rendered workflow |\n| `GET \u002Fhistory\u002F{id}` | Poll job completion |\n| `GET \u002Fview?filename=...` | Download generated images |\n| `GET \u002Fobject_info` | Discover available nodes\u002Fmodels |\n| `WS \u002Fws?clientId=...` | Real-time progress (optional) |\n\nThe client auto-detects ComfyUI version and adapts:\n- Tries WebSocket first for progress, falls back to polling\n- Handles both `\u002Fhistory` response formats\n- Detects OOM errors and classifies them with recommendations\n\n## Cache Strategy\n\nCache key = SHA-256 of `workflowId + sorted(inputs) + sorted(params) + checkpoint`.\nOn cache hit, the gateway returns a \"virtual\" job with pre-existing outputs — no GPU\ncomputation needed. Cache is stored alongside job data in the DB with configurable TTL.\n\n## Error Classification\n\n| Error Code | Meaning | Retry? |\n|------------|---------|--------|\n| `COMFYUI_UNREACHABLE` | Cannot connect to ComfyUI | Yes (with backoff) |\n| `COMFYUI_OOM` | Out of memory on GPU | No (reduce dimensions) |\n| `COMFYUI_TIMEOUT` | Execution exceeded timeout | Maybe (increase timeout) |\n| `COMFYUI_NODE_ERROR` | Node execution failed | No (check workflow) |\n| `VALIDATION_ERROR` | Invalid inputs | No (fix request) |\n| `WORKFLOW_NOT_FOUND` | Unknown workflowId | No (register workflow) |\n| `RATE_LIMITED` | Too many requests | Yes (wait) |\n| `AUTH_FAILED` | Invalid\u002Fmissing credentials | No (fix auth) |\n| `CACHE_HIT` | (Not an error) Served from cache | N\u002FA |\n\n## Bundled Workflows\n\nThree production-ready workflow templates are included:\n\n## 1. `Sdxl_Realism_V1` — Photorealistic Generation\n\n- Checkpoint: SDXL base\n- Optimized for: Portraits, landscapes, product shots\n- Default: 1024x1024, 30 steps, cfg 7.0\n\n## 2. `Sprite_Transparent_Bg` — Game Sprites With Alpha\n\n- Checkpoint: SD 1.5 or SDXL\n- Optimized for: 2D game assets, transparent backgrounds\n- Default: 512x512, 25 steps, cfg 7.5\n\n## 3. `Icon_512` — App Icons With Optional Upscale\n\n- Checkpoint: SDXL base\n- Optimized for: Square icons, clean edges\n- Default: 512x512, 20 steps, cfg 6.0, optional 2x upscale\n\n## Observability\n\n- **Structured Logs**: Pino JSON logs with `correlationId` on every request\n- **Metrics**: Jobs queued\u002Frunning\u002Fsucceeded\u002Ffailed, avg processing time, cache hit rate\n- **Audit Log**: Admin actions (workflow CRUD, key management) logged with timestamp + actor\n\n## Cli Reference\n\n```bash\nnpx tsx src\u002Fcli\u002Findex.ts init                    # Create dirs, .env.example\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow \u003Cfile>      # Register workflow template\n  --id \u003Cid> --name \u003Cname> --schema \u003Cschema.json>\nnpx tsx src\u002Fcli\u002Findex.ts list-workflows           # Show registered workflows\nnpx tsx src\u002Fcli\u002Findex.ts run                      # Start API server\nnpx tsx src\u002Fcli\u002Findex.ts worker                   # Start job worker\nnpx tsx src\u002Fcli\u002Findex.ts health                   # Check ComfyUI connectivity\n```\n\n## Troubleshooting\n\nRead `references\u002Ftroubleshooting.md` for detailed guidance on:\n- ComfyUI not reachable (firewall, wrong port, Docker networking)\n- OOM errors (reduce resolution, batch, or steps)\n- Slow generation (GPU utilization, queue depth, model loading)\n- Webhook failures (DNS, SSL, timeout, domain allowlist)\n- Redis connection issues (fallback to in-memory)\n- Storage permission errors (local path, S3 credentials)\n\n## Integration Examples\n\nRead `references\u002Fintegration.md` for ready-to-use examples with:\n- curl commands for every endpoint\n- n8n webhook workflow\n- Supabase Edge Function caller\n- Claude Code \u002F Claude.ai integration\n- Python requests client\n- JavaScript fetch client\n\n## File Structure\n\n```\ncomfyui-gateway\u002F\n├── SKILL.md\n├── package.json\n├── tsconfig.json\n├── .env.example\n├── src\u002F\n│   ├── api\u002F\n│   │   ├── server.ts          # Fastify setup + plugins\n│   │   ├── routes\u002F\n│   │   │   ├── health.ts      # GET \u002Fhealth, \u002Fcapabilities\n│   │   │   ├── workflows.ts   # CRUD \u002Fworkflows\n│   │   │   ├── jobs.ts        # CRUD \u002Fjobs\n│   │   │   └── outputs.ts     # GET \u002Foutputs\n│   │   ├── middleware\u002F\n│   │   │   └── error-handler.ts\n│   │   └── plugins\u002F\n│   │       ├── auth.ts        # API key + JWT\n│   │       ├── rate-limit.ts\n│   │       └── cors.ts\n│   ├── worker\u002F\n│   │   └── processor.ts       # Job processor\n│   ├── comfyui\u002F\n│   │   └── client.ts          # ComfyUI HTTP + WS client\n│   ├── storage\u002F\n│   │   ├── index.ts           # Provider factory\n│   │   ├── local.ts           # Local filesystem\n│   │   └── s3.ts              # S3-compatible\n│   ├── workflows\u002F\n│   │   └── manager.ts         # Template CRUD + rendering\n│   ├── cache\u002F\n│   │   └── index.ts           # Hash-based cache\n│   ├── notifications\u002F\n│   │   └── webhook.ts         # HMAC-signed callbacks\n│   ├── auth\u002F\n│   │   └── index.ts           # Key\u002FJWT validation + roles\n│   ├── db\u002F\n│   │   ├── index.ts           # DB factory (SQLite\u002FPostgres)\n│   │   └── migrations.ts      # Schema creation\n│   ├── cli\u002F\n│   │   └── index.ts           # CLI commands\n│   ├── utils\u002F\n│   │   ├── config.ts          # Env loading + validation\n│   │   ├── errors.ts          # Error classes\n│   │   ├── logger.ts          # Pino setup\n│   │   └── hash.ts            # SHA-256 hashing\n│   └── index.ts               # Main entrypoint\n├── config\u002F\n│   └── workflows\u002F             # Bundled workflow templates\n│       ├── sdxl_realism_v1.json\n│       ├── sdxl_realism_v1.schema.json\n│       ├── sprite_transparent_bg.json\n│       ├── sprite_transparent_bg.schema.json\n│       ├── icon_512.json\n│       └── icon_512.schema.json\n├── data\u002F\n│   ├── outputs\u002F               # Generated images\n│   ├── workflows\u002F             # User-added wor\n\n## Best Practices\n\n- Provide clear, specific context about your project and requirements\n- Review all suggestions before applying them to production code\n- Combine with other complementary skills for comprehensive analysis\n\n## Common Pitfalls\n\n- Using this skill for tasks outside its domain expertise\n- Applying recommendations without understanding your specific context\n- Not providing enough project context for accurate analysis\n\n## Related Skills\n\n- `ai-studio-image` - Complementary skill for enhanced analysis\n- `image-studio` - Complementary skill for enhanced analysis\n- `stability-ai` - Complementary skill for enhanced analysis\n",{"name":5,"risk":53,"tags":60,"tools":62,"author":68,"source":44,"date_added":69,"description":7},[37,61,45,52],"api-gateway",[63,64,65,66,67],"claude-code","antigravity","cursor","gemini-cli","codex-cli","renat","2026-03-06","main","7a38d8e7073e61c16eda85681cb32fb68a8657a5","skills-store\u002Fcopilot\u002Fcomfyui-gateway","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router","https:\u002F\u002Fgithub.com\u002Fsapsapshen","2026-04-14 21:12:12",{"source":8,"skillName":5,"commands":77,"prompt":87,"zipAvailable":88},[78,81,84],{"tool":79,"command":80},"npx","npx skills add sapsapshen\u002Fai-memory-router --skill comfyui-gateway",{"tool":82,"command":83},"bunx","bunx skills add sapsapshen\u002Fai-memory-router --skill comfyui-gateway",{"tool":85,"command":86},"pnpm","pnpm dlx skills add sapsapshen\u002Fai-memory-router --skill comfyui-gateway","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcopilot\u002Fcomfyui-gateway\u002FSKILL.md",true,[90,96],{"path":91,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":94,"sourceHtmlUrl":95},"references\u002Fintegration.md","REFERENCE","参考文档",48284,"https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcopilot\u002Fcomfyui-gateway\u002Freferences\u002Fintegration.md",{"path":97,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":98,"sourceHtmlUrl":99},"references\u002Ftroubleshooting.md",29528,"https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcopilot\u002Fcomfyui-gateway\u002Freferences\u002Ftroubleshooting.md",[101,123,148,158,171,187],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":110,"publishedAt":55},"01M71ATQRKG48SH06FQ697T5G9","wechat-search","Search WeChat Official Account articles using OpenClaw's web search and fetch capabilities with compliance-focused design.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fwechat-search-release\u002FSKILL.md",[107],{"categoryNo":108,"categoryName":109,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000037","律师与法务",[111,112,113,114,115,116,117,118,119,120,121,122],"wechat search","wechat","search","capabilities","openclaw","design","web search","compliance","web","official","fetch","with",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":55},"01M71ATNAVGZB35PFYM2GC5N00","trend-tap","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend tap', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-tap\u002FSKILL.md",[],[130,131,132,133,134,135,113,136,137,138,139,140,141,142,143,144,145,146,147,47],"trend","trend tap","tap","api keys","Bash","time","trending","hacker","aggregator","do","when","brew","live","data","google","install","read","across",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":55},"01M71ATJ9AM5KM15AA8PS302EB","trend-radar","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend pulse', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-radar\u002FSKILL.md",[],[155,156,130,141,142,143,144,134,113,146,157,147,47,140,138,137,136,145,135,133],"trend radar","radar","pulse",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":164,"publishedAt":55},"01M71ATGF095N3EJM9G8SD0BB5","tech-news-daily","每日科技新闻汇——从全球多个 RSS 源抓取最新科技新闻，翻译（英→中）、去重、排版成每日简报。当用户询问科技新闻、科技新鲜事、每日科技、技术动态、Daily Tech News 或类似表达时触发此技能。","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftech-news-daily\u002FSKILL.md",[],[165,166,167,168,169,170],"news","tech","tech news daily","daily","rss","翻译",{"skillNo":172,"name":173,"nameZh":6,"description":174,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":175,"categories":176,"keywords":180,"publishedAt":55},"01M71ATFAEAMQ17M70NQNY7SR8","summarize","Summarize URLs or files with the summarize CLI (web, PDFs, images, audio, YouTube).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsummarize\u002FSKILL.md",[177],{"categoryNo":178,"categoryName":179,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000021","资料检索与研究",[173,119,181,54,182,122,141,183,184,185,132,186,145],"Audio","youtube","images","https","files","pdfs",{"skillNo":188,"name":189,"nameZh":6,"description":190,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":191,"categories":192,"keywords":193,"publishedAt":55},"01M71ATDNS3R0M4H936PACQAWZ","sonoscli","Control Sonos speakers (discover\u002Fstatus\u002Fplay\u002Fvolume\u002Fgroup).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsonoscli\u002FSKILL.md",[],[189,194,195,196,145,197,184,198,199,200,201,202],"status","play","go","latest","github","discover","control","cmd","volume"]