Skip to main content

LibreChat Configuration

Now that we've got LibreChat up and running, let's dive into the configuration and setup of the chatbot. The LibreChat developers have built a robust platform that allows for a variety of customizations and integrations. In this guide, we will walk through the steps to configure LibreChat to suit your needs. I will focus primarily on enabling the OpenAI API integration and setting up authentication for the chatbot, but a future guide will delve into more advanced configurations and integrations.

Table of Contents​

  1. Clone the LibreChat Repository

  2. LibreChat Configuration and Environment Files

Clone the LibreChat Repository​

The first step in configuring LibreChat is to clone the project repository from GitHub. This will give you access to the source code and allow you to make any necessary changes to the configuration files. To clone the repository, follow these steps:

Steps to Clone the LibreChat Repository​

  1. SSH into your DigitalOcean Droplet using the following command:

    ssh root@<your-droplet-ip>
  2. Ensure you are using non-root user:

    su - <yourusername>
  3. If you are in the root directory, navigate to the home directory:

    cd ~
  4. Run the following command to clone the LibreChat repository:

    sudo git clone https://github.com/danny-avila/LibreChat.git
  5. Navigate to the LibreChat directory:

     cd LibreChat

LibreChat Configuration and Environment Files​

The LibreChat project uses environment files to store configuration settings and sensitive information. A sample file is included that we can alter to suit our needs. In this section, we will walk through the process of creating the necessary environment files and configuring LibreChat to use the OpenAI API.

Steps to Configure LibreChat YAML File​

  1. From inside the LibreChat directory, run the following to open the file in the nano text editor:

    nano librechat.yaml
  2. The LibreChat developers have included a sample configuration file that we can use as a template. Copy the following to the librechat.yaml file:

     # For more information, see the Configuration Guide:
    # https://docs.librechat.ai/install/configuration/custom_config.html
    # Configuration version (required)

    version: 1.0.5

    # This setting caches the config file for faster loading across app lifecycle
    cache: true
  3. Exit the Nano editor using Ctrl + X and save the changes by typing Y and pressing Enter.

Steps to Configure the Environment File (.env)​

The developers have provided us with a sample .env file that is pre-loaded with a lot of possible settings. Our configuration will consist of uncommenting a number of lines here and adding in a few values.

  1. From inside the LibreChat directory, run the following to copy the sample .env file to a new file that will be used for our production environment:

     sudo cp .env.example .env
  2. We need to generate some keys for our authentication and encryption. The developers of LibreChat have provided a Replit that will generate these keys for us. You can access the Replit here.

  3. Click to Fork the file which will convert the replit to your own version with varialbes that will generate unique keys for you. Click the green Run button. You'll see a number of keys generated in the console:

    • CREDS_IV - This is the initialization vector for the encryption
    • CREDS_KEY - This is the key for the encryption
    • JWT_SECRET - This is the secret for the JSON Web Token
    • JWT_REFRESH_SECRET - This is the secret for the refresh token

    Replit

  4. With these keys generated, we can now add them to the .env file. Open the file in the Nano text editor:

    nano .env
    warning

    Make sure you use sudo to open the file in the Nano editor. Failure to do so will result in the file opening in read-only mode and you won't be able to save your changes.

    Feel free to browse this file. It's pretty extensive and has a lot of options. We'll be focusing on a few of these.

  5. Search for the line with CREDS_IV. This Key and the CREDS_KEY are around 150 lines down in the Plugins section of the file. Uncomment this line if it's not already uncommented or replace existing value and paste in the value generated from the Replit.

  6. Copy and paste the CREDS_KEY value from the Replit into the .env file as well. This is the encryption key and is right above the CREDS_IV value in the file

  7. Do the same for the JWT_SECRET and JWT_REFRESH_SECRET values. These are located in the Registration and Login section of the file.

Registration Options - Closed or Open Registration?​

LibreChat ships with a robust authentication / login method where registrations can be turned off or on. Option one below, "Disabled", will walk through the steps to ensure no outside registrations to your app can occur. This method is good for when you have a set list of users that are pre-approved to use the chatbot all of whom are using a single API key.

note

The following steps will require that you have an OpenAI API key. If you don't have one, you can sign up for a free account on the OpenAI website.

Select the Method that Suits Your Needs in the Tabs Below​

Registration Enabled​

The cleverness of the LibreChat devs have provided that you needn't run the app in a closed environment. They've baked in a "BYOK" (Bring your own Keys) method that allows anyone to acces your app and create an account. This is the default setting for the app.

Once logged in they can take their own API keys for whichever services you've enabled on your LibreChat app and set them up in their own account. No need to worry about sharing your keys with others and crying over your credit card bill when you've had 4000 people sign up and run up a bill on your account.

tip

You can set usage limits with OpenAI - probably with most other services as well. This will help you keep your costs down and your app secure.

Steps to Enable Registrations​

  1. Open the .env file in the Nano text editor:

    nano .env
  2. Search for the line with ALLOW_REGISTRATION=false and change it to true. This will enable the registration option for the chatbot. Unless you've previously changed this setting, it should be set to true by default.

  3. No need to set your keys here. If you scroll to the OpenAI section, you'll see a line that says OPENAI_API_KEY=user_provided.

There is actually not much to do out of the box for this method. You can simply deploy the app and let users sign up and use their own API keys.

Starting LibreChat​

  1. First let's make sure our Docker engine is up and running. Run the following command to check the status of the container:

    sudo docker ps
  2. Run this to ensure it's running:

    sudo systemctl start docker
  3. Start the app container:

    sudo docker-compose -f ./deploy-compose.yml up -d
  4. Navigate to your app -- in your browser enter the DigitalOcean Droplet IP address and you'll see the login screen. You'll see an option to create a new account.

    Login Screen

  5. Log in with your email and password and you'll be taken to the chatbot. Click the OpenAI button at the top which drops down the list of services you can use. Click on the OpenAI service and and then click the gear icon for settings and you'll see a prompt to enter your API key.

    OpenAI API Key

  6. Enter your API key and select if and when you'd like it to expire and click Save. You're now set up to use the OpenAI service with your chatbot.

    OpenAI API Key

Congratulations! You've now configured LibreChat to suit your needs. You can now use the chatbot with the OpenAI API integration and have set up authentication for the chatbot.

Note that depending on which method you chose, you may need to manage users differently. If you opted for the closed registration method, you'll need to use the provided scripts to add and verify users. If you chose the open registration method, users can create their own accounts and manage their API keys.

If you choose to change this in the future, don't forget that you'll need to redeploy the docker container to apply the changes.

You may have noticed that the app is accessed over HTTP. This poses a few porblems. First, it's not secure. Second, it is the source of an issue that causes our session to expire every 15 minutes or on refresh.

Up next: Get a custom domain, make is secure and fix the session issue.