# AI Platform
A self-hosted AI platform built with Docker, vLLM, LiteLLM, Open WebUI, and ComfyUI.
The project is designed to provide a production-ready local AI stack that can serve multiple model classes through a unified OpenAI-compatible API, while also supporting a separate image-generation pipeline based on ComfyUI.
The platform is configuration-driven:
- Docker Compose files are generated automatically
- LiteLLM configuration is generated automatically
- GPU allocation and scheduling are derived from model configuration
- ComfyUI model trees are generated from source models
- Workflow catalogs are generated from API workflow exports
All project scripts use `scripts/common.sh` to discover the project root automatically, which keeps the repository portable across different installation paths.
---
# Key Features
## LLM Platform
- Docker-based deployment
- vLLM inference server
- LiteLLM OpenAI-compatible gateway
- Open WebUI integration
- Multiple models served simultaneously
- Automatic model registration
- Automatic Docker Compose generation
- Automatic LiteLLM configuration generation
- Multi-GPU scheduling
- Runtime model overrides
- OpenAI-compatible endpoints
- Support for coding clients
## Image Platform
- Dedicated ComfyUI image platform
- Workflow-based image generation
- Workflow catalog generation
- Workflow routing
- Open WebUI image integration
- Markdown image preview inside Open WebUI
- Nginx image serving
- Source-model to ComfyUI model-tree generation
- Configuration-driven workflow organization
---
# High-Level Architecture
## LLM Stack
```text
Open WebUI
│
▼
LiteLLM
│
▼
vLLM
│
▼
Loaded ModelsOpen WebUI
│
▼
Ani Image Pipe
│
▼
Workflow Router
│
▼
ComfyUI
│
▼
Generated Image
│
▼
Nginx
│
▼
Open WebUI Preview
The LLM platform exposes a single OpenAI-compatible endpoint regardless of how many inference services are active. The image platform is separate, but integrates into Open WebUI through a Function-based pipe.
ai-platform/
├── backups/
├── config/
├── docker/
├── docs/
├── functions/
├── images/
├── logs/
├── models/
├── open-webui/
├── reports/
├── scripts/
└── workflows/
Main configuration files for model selection, overrides, and downloadable models.
Docker Compose files, environment templates, and deployment-specific configuration.
Project documentation, including model configuration, clients, troubleshooting, and the Open WebUI image pipeline.
Canonical source copy of Open WebUI Function code used by the project.
Runtime ComfyUI data directory and generated image outputs.
Local model storage, organized by model category.
Deployment, generation, validation, routing, and platform control scripts.
API-ready ComfyUI workflows, catalog files, router rules, and workflow metadata.
| Service | Purpose | Port |
|---|---|---|
| vLLM | Model inference | Internal |
| LiteLLM | OpenAI-compatible gateway | 4000 |
| Open WebUI | Web interface | 8080 |
| ComfyUI | Image generation / editing | 8188 |
All services communicate through the shared Docker network:
ai-platform
| Alias | Model |
|---|---|
| qwen15 | Qwen2.5-1.5B-Instruct |
| qwen7b | Qwen2.5-7B-Instruct |
git clone https://github.com/ramin40686/self-hosted-ai-platform.git
cd self-hosted-ai-platformcp docker/.env.example docker/.envEdit the local values as needed, including tokens, timezone, and ports.
Edit:
config/enabled-models.conf
Optional overrides:
config/model-overrides.conf
./scripts/register-models.sh./scripts/start-ai-platform.sh./scripts/start-image-platform.shRecommended:
- NVIDIA GPU
- NVIDIA Container Toolkit
- Docker
- Docker Compose
- Git
- Models are stored under
models/ - Runtime ComfyUI data is stored under
images/comfyui/ - Workflow exports are stored under
workflows/Workflows_API/
The platform is driven by configuration files.
| File | Purpose |
|---|---|
config/enabled-models.conf |
Enable or disable models |
config/model-overrides.conf |
Runtime overrides |
config/models-for-download.conf |
Models to download |
config/model-stats.conf |
Local stats and benchmark data |
| File | Purpose |
|---|---|
docker/.env |
Local Docker variables |
docker/compose.inference.yml |
Generated inference services |
docker/compose.litellm.yml |
LiteLLM deployment |
docker/compose.openwebui.yml |
Open WebUI deployment |
docker/compose.images.yml |
ComfyUI deployment |
The LLM platform consists of Open WebUI, LiteLLM, and one or more vLLM inference services.
./scripts/start-ai-platform.sh./scripts/stop-ai-platform.sh./scripts/restart-ai-platform.shBase URL:
http://localhost:4000/v1
Example:
curl http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model":"qwen7b",
"messages":[
{
"role":"user",
"content":"Hello"
}
]
}'The image platform is built around ComfyUI and a source-tree model layout.
Original downloads are stored in:
models/image/source/
generate-comfyui-model-tree.sh creates the ComfyUI runtime model tree by linking the source models into the container’s ComfyUI model folders.
./scripts/start-image-platform.sh./scripts/stop-image-platform.sh./scripts/restart-image-platform.shOpen WebUI includes a custom Function Pipe that routes image-generation prompts to ComfyUI workflows.
The implementation supports:
- text-to-image generation
- automatic workflow routing
- workflow catalog lookup
- image preview in Open WebUI
- public image serving through nginx
- Docker-native execution
Complete documentation:
docs/openwebui-image-pipeline.md
Canonical Function source:
functions/ani_image_pipe.py
The image workflows are indexed through a generated catalog:
workflows/Workflows_API/catalog.yaml
The catalog is built automatically from the API workflows and validated before runtime.
Generate the catalog:
./scripts/build_workflow_catalog.shThe runtime router uses the generated catalog instead of scanning workflow folders at startup.
During catalog generation, an additional metadata report is produced for development and validation.
Default location:
reports/workflow-metadata.json
This file is used for inspection and debugging, not at runtime.
API-ready ComfyUI workflows are stored under:
workflows/Workflows_API/
Typical workflow groups:
text_to_image/image_edit/image_upscaler/remove_background/guided_image_edit/router/
Workflow development cycle:
- Create or export a ComfyUI API workflow
- Place it in the appropriate task directory
- Rebuild the catalog
- Validate the generated output
- Test the workflow through Open WebUI
Workflow-specific details are documented in:
docs/openwebui-image-pipeline.md
docs/image-generation.md
| Script | Purpose |
|---|---|
scripts/common.sh |
Shared runtime utilities |
scripts/download-models.sh |
Download models from Hugging Face |
scripts/register-models.sh |
Generate inference compose and LiteLLM config |
scripts/measure-models.sh |
Benchmark supported models |
scripts/gpu-report.sh |
GPU report |
| Script | Purpose |
|---|---|
scripts/start-ai-platform.sh |
Start LLM services |
scripts/stop-ai-platform.sh |
Stop LLM services |
scripts/restart-ai-platform.sh |
Restart LLM services |
scripts/wait-healthy.sh |
Wait until services are healthy |
| Script | Purpose |
|---|---|
scripts/start-image-platform.sh |
Start ComfyUI platform |
scripts/stop-image-platform.sh |
Stop ComfyUI platform |
scripts/restart-image-platform.sh |
Restart ComfyUI platform |
scripts/generate-comfyui-model-tree.sh |
Build ComfyUI model tree |
| Script | Purpose |
|---|---|
scripts/build_workflow_catalog.sh |
Build and validate workflow catalog |
scripts/extract_comfyui_workflow_catalog.py |
Extract workflow metadata |
scripts/validate_workflow_catalog.py |
Validate workflow catalog |
scripts/router_and_execute.py |
Runtime workflow orchestrator |
scripts/run_workflow_api.py |
Execute ComfyUI workflows |
docker psnvidia-smidf -hdu -sh models/*docker logs -f open-webui
docker logs -f litellm
docker logs -f comfyui./scripts/build_workflow_catalog.sh./scripts/start-image-platform.shCheck:
- Docker logs
- GPU memory
GPU_MEMORY_UTILIZATIONMAX_MODEL_LEN- Model-specific runtime overrides
Check:
- Source model location in
models/image/source/ - ComfyUI logs
- Generated runtime model tree
- The image platform startup script
Rebuild the catalog:
./scripts/build_workflow_catalog.shThen verify:
workflows/Workflows_API/catalog.yaml
Check:
- The Open WebUI Function exists
functions/ani_image_pipe.pymatches the deployed Function- The router returns valid JSON
- ComfyUI is reachable
- Nginx serves generated images
See:
docs/openwebui-image-pipeline.md
The LiteLLM gateway exposes a standard OpenAI-compatible API.
Verified clients include:
- Cursor
- Continue
- Cline
- Aider
- Qwen Code
All clients can connect to:
http://localhost:4000/v1
CHANGELOG.mdHANDOVER.mdREADME.md
docs/enabled-models.mddocs/model-overrides.mddocs/model-stats.mddocs/models-for-download.mddocs/CLIENTS.mddocs/troubleshooting.md
docs/image-generation.mddocs/flux-dev-inpainting.mddocs/flux-kontext-replace.mddocs/openwebui-image-pipeline.md
workflows/Workflows_API/catalog.yamlworkflows/Workflows_API/workflow-metadata.jsonworkflows/Workflows_API/router/
- Docker infrastructure
- vLLM
- LiteLLM
- Open WebUI
- Multiple LLMs
- Automatic model registry
- Automatic Docker Compose generation
- Automatic LiteLLM configuration
- Multi-GPU scheduling
- Coding clients setup
- ComfyUI image platform
- ComfyUI workflow library
- Open WebUI image pipeline
- Embedding server
- Reranker
- RAG pipeline
- Whisper API
- Vision models
- Text-to-speech
- Monitoring
- Reverse proxy
- Authentication
- HTTPS
- Backup automation
- Image edit
- Inpaint
- Outpaint
- Background removal
- Image upscaler
- Guided image editing
- Automatic parameter mapping
- Image upload support
- Progress streaming
- Workflow validation improvements
MIT