Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Stable Diffusion

How to set up and configure the Stable Diffusion tool

Stable Diffusion is a built-in agent tool that connects LibreChat to an AUTOMATIC1111 Stable Diffusion WebUI API. For a dockerized Stable Diffusion deployment, you can also use stable-diffusion-webui-docker.

With the docker deployment you can skip step 2 and step 3, use the setup instructions from their repository instead.

  • Note: you need a compatible GPU ("CPU-only" is possible but very slow). Nvidia is recommended, but there is no clear resource on incompatible GPUs. Any decent GPU should work.

1. Follow download and installation instructions

Follow the setup steps from the stable-diffusion-webui readme.

2. Edit your run script settings

Windows

  • Edit your webui-user.bat file by adding the following line before the call command:

  • set COMMANDLINE_ARGS=--api

    • Your .bat file should like this with all other settings default
    @echo off
    
    set PYTHON=
    set GIT=
    set VENV_DIR=
    set COMMANDLINE_ARGS=--api
    
    call webui.bat

Others (not tested but should work)

  • Edit your webui-user.sh file by adding the following line:

  • export COMMANDLINE_ARGS="--api"

    • Your .sh file should like this with all other settings default
    
    export COMMANDLINE_ARGS="--api"
    
    #!/bin/bash
    #########################################################
    # Uncomment and change the variables below to your need:#
    #########################################################
    
    # ...rest

3. Run Stable Diffusion (either .sh or .bat file according to your operating system)

4. Set the Stable Diffusion URL in LibreChat

Note: The default port for Gradio is 7860. If you changed it, please update the value accordingly.

Docker Install

  • Use SD_WEBUI_URL=http://host.docker.internal:7860 in the .env file
  • Or http://host.docker.internal:7860 from the webui

Local Install

  • Use SD_WEBUI_URL=http://127.0.0.1:7860 in the .env file
  • Or http://127.0.0.1:7860 from the webui

Restart LibreChat after changing .env.

DeploymentCommand
Dockerdocker compose down && docker compose up -d
LocalStop the server, then run npm run backend again

Add the Tool to an Agent

In LibreChat, select Agents, create or edit an agent, open the agent's Tools list, select Stable Diffusion, and save the agent. See the Agents section for more information.

How is this guide?