CivitDL Web API is a RESTful wrapper for the original CivitDL CLI tool, designed to simplify the downloading and management of models from Civitai. By using this API, you can automate and efficiently handle model downloads, making it particularly useful for projects like sd-forge-docker that integrate with Stable Diffusion WebUI.
Follow these steps to install and set up the API:
-
Clone the repository:
git clone https://github.com/sammrai/civitdl-webapi.git cd civitdl-webapi
-
Start the Docker container:
docker-compose up -d
-
Access the API:
Openhttp://localhost:7681
in your browser or use a tool likecurl
to interact with the API.
The API supports the following environment variables, which can be configured in docker-compose.yml
:
Variable | Description | Default Value |
---|---|---|
CIVITAI_TOKEN |
(Optional) Your Civitai API token for authentication. Required for downloading certain restricted models. | Not set |
MODEL_ROOT_PATH |
Directory where models will be stored. | /data |
Note:
CIVITAI_TOKEN
is not mandatory but is highly recommended for accessing models that require authentication. Without it, some models may not be downloadable.
Downloaded models are organized into directories based on their type. If MODEL_ROOT_PATH=/data
, the structure will be:
- LoRA models:
/data/models/Lora
- VAE models:
/data/models/VAE
- Checkpoint models:
/data/models/Stable-diffusion
- Textual Inversion models:
/data/embeddings
This structure ensures efficient model organization and easy management.
For detailed OpenAPI specifications, please refer to the following links:
Downloads a specific model from Civitai.
curl -s -X POST "http://localhost:7681/models/439889"
{
"model_id": 30410,
"version_id": 93602,
"model_dir": "/data/models/Lora/Pokemon - Selene-mid_30410-vid_93602",
"filename": "Selene-10-mid_30410-vid_93602.safetensors",
"model_type": "lora"
}
Downloads a specific model from Civitai.
curl -s -X POST "http://localhost:7681/models/30410/versions/36664"
{
"model_id": 30410,
"version_id": 36664,
"model_dir": "/data/models/Lora/Pokemon - Selene-mid_30410-vid_36664",
"filename": "SeleneLora-10-mid_30410-vid_36664.safetensors",
"model_type": "lora"
}
Retrieves a list of all models stored in the system.
curl -X GET "http://localhost:7681/models/"
[
{
"model_id": 30410,
"version_id": 93602,
"model_dir": "/data/models/Lora/Pokemon - Selene-mid_30410-vid_93602",
"filename": "Selene-10-mid_30410-vid_93602.safetensors",
"model_type": "lora"
},
{
"model_id": 30410,
"version_id": 36664,
"model_dir": "/data/models/Lora/Pokemon - Selene-mid_30410-vid_36664",
"filename": "SeleneLora-10-mid_30410-vid_36664.safetensors",
"model_type": "lora"
}
]
The following volume is defined in docker-compose.yml
to persist downloaded models:
./data:/data
โ Maps the localdata
directory to the containerโs/data
directory, ensuring models remain available even if the container is restarted.
This project is powered by CivitDL.