Skip to content

musemod/comfyui-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

112 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ComfyUI API - Portfolio Website

This is a fork from comfyui-api which acts as a wrapper that facilitates using ComfyUI as a stateless API, either by receiving images in the response, or by sending completed images to a webhook. Currently, this project runs locally, so I am not using any webhook features.

This project is a simple in-progress portfolio website that recreates portions of my current website using Typescript, Fastify, React, HTML, CSS. My primary goal was running ComfyUI as a backend, using a custom JSON workflow with locally-run Flux model based on ComfyUI MileHighStyler, with an Image Generator page as a React frontend.

Since I do not include my original handdrawn artwork in this Github repo, I include a video walkthrough of the website, along with a demo of the Image Generator page on YouTube: https://youtu.be/MPYkVqzZrsQ?si=qWhEI2W99cT8E3Sk.

Prerequisites

  • Node.js 20.18 or higher
  • npm or yarn
  • ComfyUI installed and configured locally
  • If you want to test the sample workflows (under comfyui-api/workflows), have Flux and SD 1.5 models already downloaded

Getting Started

  1. git clone https://github.com/musemod/Portfolio-comfyui.git
  2. npm install
  3. Configure environment variables
    • Set up .env (look at env.example)
    • Update paths and settings in .env (see src/config.ts for all options)
    • Ensure your ComfyUI paths are correctly set
  4. npm run dev command: This launches both the backend API and React frontend concurrently. See frontend at http://localhost:5173/. You can check backend health and endpoints at http://localhost:3000/docs.

Adding Custom Workflows

To add your own ComfyUI workflows, you can add them in the comfyui-api/workflows folder. See original comfyui-api for more information on how to correctly add your own JSON ComfyUI workflows.

Deployment Considerations

If I were to deploy this website publicly, several architectural changes would be necessary:

1. Migration from Local ComfyUI to Managed Inference

Running ComfyUI locally with Flux models is not viable for a public deployment due to GPU resource constraints and scalability requirements. I would migrate the image generation functionality to use a managed inference provider:

  • Hugging Face SDK for Inference (with API) / Serverless Inference - Provides on-demand access to thousands of models including Flux variants, with pay-per-use pricing and automatic scaling
  • Replicate - Offers simple API access to community models with built-in queue management

This approach eliminates the need to manage GPU infrastructure while maintaining the ability to use custom workflows through providers that support them.

Technical Tradeoffs

As a small personal website demonstrating capability, the bare minimum protections against bad actors would include:

  1. Simple rate limiting with reasonable defaults (e.g., 10 requests per hour per IP)
  2. Basic authentication using a single shared secret for the image generator page (simple but effective for low-traffic sites)
  3. Prompt validation to reject obviously malicious inputs (excessive length, suspicious patterns)
  4. Read-only mode for the rest of the portfolio content with no authentication required
  5. Environment-based feature flags to quickly disable generation if abuse occurs
  6. Containerization for consistent deployment across environments
  7. Model preloading so users don't have to wait for models to load before their first generation
  8. Monitoring and logging to track usage patterns and detect anomalies
  9. Database for user data, generation history, and rate limit tracking (optional for small scale)
  10. CDN for serving static portfolio assets
  11. Ephemeral image storage with automatic expiration (5-15 minutes). Since users save images directly to their local computers, the server should not persist generated images long-term. This minimizes storage costs, reduces compliance concerns, and aligns with the stateless API philosophy.

These tradeoffs acknowledge that perfect security is impossible and expensive, but reasonable guardrails prevent the most common abuse vectors while maintaining a good user experience.

Acknowledgements

About

A simple API server to make ComfyUI easy to scale horizontally. Get outputs directly in the response, or asynchronously via a variety of storage providers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 85.2%
  • JavaScript 6.5%
  • CSS 6.4%
  • Shell 1.1%
  • Other 0.8%