Skip to content

CivitDL Web API โ€“ A RESTful wrapper for CivitDL CLI, streamlining model downloads from Civitai. Ideal for automation and integration with projects like sd-forge-docker and Stable Diffusion WebUI. ๐Ÿš€

Notifications You must be signed in to change notification settings

sammrai/civitdl-webapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

44 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CivitDL Web API

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.

Installation

Follow these steps to install and set up the API:

  1. Clone the repository:

    git clone https://github.com/sammrai/civitdl-webapi.git
    cd civitdl-webapi
  2. Start the Docker container:

    docker-compose up -d
  3. Access the API:
    Open http://localhost:7681 in your browser or use a tool like curl to interact with the API.

Configuration

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.

Model Directory Structure

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.

API Endpoints

For detailed OpenAPI specifications, please refer to the following links:

Download a model by ID

Downloads a specific model from Civitai.

Request:

curl -s -X POST "http://localhost:7681/models/439889"

Response:

{
  "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"
}

Download a model by model ID and version ID

Downloads a specific model from Civitai.

Request:

curl -s -X POST "http://localhost:7681/models/30410/versions/36664"

Response:

{
  "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"
}

List all downloaded models

Retrieves a list of all models stored in the system.

Request:

curl -X GET "http://localhost:7681/models/"

Response:

[
  {
    "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"
  }
]

Persistent Storage

The following volume is defined in docker-compose.yml to persist downloaded models:

  • ./data:/data โ€“ Maps the local data directory to the containerโ€™s /data directory, ensuring models remain available even if the container is restarted.

Acknowledgments

This project is powered by CivitDL.

About

CivitDL Web API โ€“ A RESTful wrapper for CivitDL CLI, streamlining model downloads from Civitai. Ideal for automation and integration with projects like sd-forge-docker and Stable Diffusion WebUI. ๐Ÿš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published