Azure Blob Storage
This document provides instructions for setting up Azure Blob Storage for LibreChat
On this page
Production Setup
Azure Blob Storage offers scalable, secure object storage for files in LibreChat. Follow these steps to configure your Azure Blob Storage.
1. Create an Azure Storage Account
-
Sign in to Azure:
- Open the Azure Portal and sign in with your Microsoft account.
-
Create a Storage Account:
- Click on "Create a resource" and search for "Storage account".
- Click "Create" and fill in the required details:
- Subscription & Resource Group: Choose your subscription and either select an existing resource group or create a new one.
- Storage Account Name: Enter a unique name (e.g.,
mylibrechatstorage). - Region: Select the region closest to your users.
- Performance & Redundancy: Choose the performance tier and redundancy level that best suit your needs.
- Click "Review + Create" and then "Create". Wait until the deployment completes.
2. Set Up Authentication
You have two options for authenticating with your Azure Storage Account:
Option A: Using a Connection String
-
Navigate to Access Keys:
- In your newly created storage account, go to "Access keys" in the sidebar.
-
Copy Connection String:
- Copy one of the connection strings provided. This string includes the credentials required to connect to your Blob Storage account.
Option B: Using Managed Identity
If your LibreChat application is running on an Azure service that supports Managed Identity (such as an Azure VM, App Service, or AKS), you can use that instead of a connection string.
-
Assign Managed Identity:
- Ensure your Azure resource (VM, App Service, or AKS) has a system-assigned or user-assigned Managed Identity enabled.
-
Grant Storage Permissions:
- In your storage account, assign the Storage Blob Data Contributor (or a similarly scoped role) to your Managed Identity. This allows your application to access Blob Storage without a connection string.
3. Update Your Environment Variables
Create or update your .env file in your project’s root with the following configuration:
- AZURE_STORAGE_CONNECTION_STRING: Set this if you are using Option A.
- AZURE_STORAGE_ACCOUNT_NAME: Set this if you are using Option B (Managed Identity). Do not set both.
- AZURE_STORAGE_PUBLIC_ACCESS: Set to
falseif you do not want your blobs to be publicly accessible by default. Set totrueif you need public access (for example, for publicly viewable images). - AZURE_CONTAINER_NAME: This is the container name your application will use (e.g.,
files). The application will automatically create this container if it doesn’t exist.
4. Configure LibreChat to Use Azure Blob Storage
Update your LibreChat configuration file (librechat.yaml) to specify that the application should use Azure Blob Storage for file handling:
Azure Blob Storage is object storage, not a CDN
Azure Blob Storage stores and serves files directly from origin — it is not a CDN. Images and avatars are best served through a CDN for optimal performance and global delivery. Currently, Firebase is the only CDN-backed storage option.
You can use fileStrategies to route only avatars and images to Firebase while keeping documents on Azure Blob Storage:
Summary
-
Create a Storage Account:
Sign in to the Azure Portal, create a storage account, and wait for deployment to finish. -
Set Up Authentication:
- Option A: Retrieve the connection string from "Access keys" in your storage account.
- Option B: Use Managed Identity by enabling it on your Azure resource and granting it appropriate storage permissions.
- Update Environment Variables:
In your.envfile, set either:
AZURE_STORAGE_CONNECTION_STRING(for Option A), orAZURE_STORAGE_ACCOUNT_NAME(for Option B), along with:AZURE_STORAGE_PUBLIC_ACCESSandAZURE_CONTAINER_NAME.
- Configure LibreChat:
SetfileStrategyto"azure_blob"in yourlibrechat.yamlconfiguration file.
With these steps, your LibreChat application will automatically create the container (if it doesn't exist) and manage file uploads, downloads, and deletions using Azure Blob Storage. Managed Identity provides a secure alternative by eliminating the need for long-term credentials.
Local Development with Azurite
For local development and testing, you can use Azurite, an Azure Storage emulator that provides a local environment for testing your Azure Blob Storage integration without needing an actual Azure account.
1. Set Up Azurite
You can run Azurite in several ways:
Option A: Using VS Code Extension (Recommended for Development)
- Install the Azurite extension for VS Code
- Open the command palette (Ctrl+Shift+P or Cmd+Shift+P)
- Search for and select "Azurite: Start"
This will start Azurite in the background with default settings.
Option B: Using Docker
Option C: Using npm
2. Configure Environment Variables for Local Development
Add the following environment variables to your .env file:
Notes:
- The
AccountKeyvalue is the default development key used by Azurite - The connection uses
httpprotocol instead ofhttpsfor local development - The
BlobEndpointpoints to the local Azurite instance running on port 10000
3. Verify the Connection
To verify that your application can connect to the local Azurite instance:
- Start your LibreChat application
- Attempt to upload a file through the interface
- Check the Azurite logs to confirm the connection and operations
If you're using the VS Code extension, you can view the Azurite logs in the Output panel by selecting "Azurite Blob" from the dropdown.
Note
The default Azurite account key is a fixed value used for development purposes only. Never use this key in production environments. Always ensure that your connection string remains secure and never commit it to a public repository.
How is this guide?