Skip to main content

LibreChat is joining ClickHouse. Learn more

LibreChat

Deploy the Gateway

Prerequisites, Docker Compose and source setup, and verification for the channel gateway, in organization workspace or manual connection mode.

The channel gateway is a separate service that connects LibreChat to Slack. This guide is for the operator who runs LibreChat. Once the gateway is ready, administrators and agent owners continue in the Slack guides.

Beta and opt-in

Agent Channels ship with LibreChat v0.8.9 and later. Use the same release for LibreChat and the gateway. A deployment that does not use channels needs none of this.

Choose a mode

Organization workspacesManual connection
Gateway processesOne shared gateway for every registered Slack appOne gateway per connection
Slack transportWebhook, so the gateway needs a public HTTPS addressSocket Mode (no inbound traffic) or webhook
Slack credentialsEntered by administrators in LibreChatEntered by the agent owner in the Agent Builder, plus an app-level token in the gateway for Socket Mode
Turned on bySLACK_WORKSPACES_ENABLED=trueendpoints.agents.channels in librechat.yaml

Socket Mode means the gateway opens an outbound connection to Slack, so nothing needs to reach it from the internet. Webhook means Slack sends HTTPS requests to the gateway, which needs a public address.

Pick organization workspaces unless you cannot expose a public HTTPS endpoint. It needs no per-connection deployment work, and administrators manage everything from the UI. Using Kubernetes? Read this page for the prerequisites, then follow Kubernetes and Helm.

Prerequisites

Checklist

  • A transaction-capable MongoDB deployment, such as a replica set. See the database requirement.
  • The Remote Agents use permission granted to every role that will use the bot, in the Admin Panel or with interface.remoteAgents. The default USER role does not have it.
  • Agents API key authentication left enabled (the default), because the gateway runs each request with a short-lived bound key.
  • A private CHANNEL_SERVICE_TOKEN of at least 32 characters, identical in LibreChat and the gateway. Generate one with openssl rand -hex 32.
  • DOMAIN_CLIENT set to LibreChat's public address, so account-link and review links open the right site.
  • For organization workspaces: public HTTPS addresses for LibreChat and for the gateway's Slack callbacks.

The service token only lets the gateway call LibreChat's private channel API. It cannot be used as a browser session or as a general Agents API key, and it should never appear in client code, Slack messages, or logs.

Database requirement

Channels write connections, runs, and delivery receipts together, so the database must support transactions and partial indexes. Stored background Responses have the same requirement.

DatabaseCan run Agent Channels?
MongoDB replica set, including a single-member local replica setYes
MongoDB AtlasYes
Standalone MongoDBNo. LibreChat runs normally, but channels and stored background Responses are unavailable.
FerretDB 2.7No
Amazon DocumentDB 4.0No. Partial indexes are not supported.

Other MongoDB-compatible engines need to be validated first. When transactions are unavailable, channel requests fail with transactions_unavailable and the Agent Builder explains the requirement. Transactional reads always go to the primary, even if your connection prefers secondaries.

For Docker Compose, the docker-compose.mongo-replica.yml overlay turns the bundled MongoDB into a single-member replica set. Read Existing local data before applying it to a database that already holds data.

Organization workspaces

One shared gateway serves every Slack app your administrators register. No per-workspace process, token, or deployment change is needed after this one-time setup.

  1. SlackSends events and button clicks over HTTPS
  2. HTTPS proxyRoutes /slack/events/ and /slack/interactions/ to the gateway
  3. Channel gatewayPort 8080 in the container, 127.0.0.1:3081 on the host
  4. LibreChat APIServes the app and the Slack OAuth callback

Set the environment. Add these values to LibreChat's .env, replacing the localhost defaults. Keep the file out of version control.

DOMAIN_SERVER=https://chat.example.com
DOMAIN_CLIENT=https://chat.example.com
CHANNEL_SERVICE_TOKEN=<output of openssl rand -hex 32>
LIBRECHAT_IMAGE_TAG=v0.8.9
# Optional: a separate public origin for Slack callbacks
# SLACK_GATEWAY_URL=https://slack.example.com

DOMAIN_SERVER, DOMAIN_CLIENT, and SLACK_GATEWAY_URL must be public HTTPS URLs without surrounding whitespace, including any base path. LibreChat refuses to start with localhost or private addresses in this mode. Without SLACK_GATEWAY_URL, Slack callbacks use DOMAIN_SERVER.

Start LibreChat and the gateway. From the LibreChat directory, with librechat.yaml prepared as usual:

docker compose -f docker-compose.yml -f docker-compose.channels.yml \
  -f docker-compose.slack-workspaces.yml -f docker-compose.mongo-replica.yml \
  --profile channels up -d api meilisearch channel-gateway

Omit docker-compose.mongo-replica.yml if you use an external transaction-capable database, and supply its connection through your usual Compose override. Use the same files and project name for every later command.

Route the Slack callbacks. Configure your HTTPS proxy to forward /slack/events/ and /slack/interactions/ to the gateway, keeping the full path. Everything else, including the OAuth callback at /api/channels/workspaces/oauth/callback, goes to LibreChat.

chat.example.com {
  handle /slack/events/* {
    reverse_proxy 127.0.0.1:3081
  }
  handle /slack/interactions/* {
    reverse_proxy 127.0.0.1:3081
  }
  handle {
    reverse_proxy 127.0.0.1:3080
  }
}
location /slack/events/ {
  proxy_pass http://127.0.0.1:3081;
}
location /slack/interactions/ {
  proxy_pass http://127.0.0.1:3081;
}
location / {
  proxy_pass http://127.0.0.1:3080;
}

The shared overlay publishes the gateway on 127.0.0.1:3081; set CHANNEL_GATEWAY_PORT to change it. A proxy on the same Compose network can use http://channel-gateway:8080 instead. If you uncomment SLACK_GATEWAY_URL to use a separate hostname (such as https://slack.example.com), forward /slack/events/ and /slack/interactions/ on that hostname to the gateway while keeping /api/channels/workspaces/oauth/callback and app traffic on DOMAIN_SERVER. Keep the gateway's health and metrics paths private.

Check readiness, as described in Verify the gateway. Then hand over to an administrator to connect a Slack workspace.

Manual connection

Each manual connection gets its own gateway process, bound to that connection's ID. The connection is created by an agent owner first, so setup goes back and forth once between you and them.

Enable Channels in librechat.yaml. Both settings default to false:

endpoints:
  agents:
    remoteApi:
      background:
        enabled: true
    channels:
      enabled: true
      transport: socket_mode # or webhook
      # Required for webhook: the gateway's public HTTPS origin
      # gatewayUrl: https://gateway.example.com

With socket_mode, the gateway opens an outbound connection to Slack and needs no public URL. With webhook, set gatewayUrl to an HTTPS origin without credentials, query, or fragment; the generated Slack manifest points there.

Start LibreChat. Set CHANNEL_SERVICE_TOKEN and LIBRECHAT_IMAGE_TAG in .env, then start the application:

docker compose -f docker-compose.yml -f docker-compose.channels.yml \
  -f docker-compose.mongo-replica.yml up -d --pull always api meilisearch

Have the agent owner create the connection. They follow Manual connection and send you the Connection ID. For Socket Mode, they also give you the Slack app-level token (xapp-, with connections:write).

Configure and start the gateway. Add the connection to .env:

CHANNEL_ID=<connection ID from the Agent Builder>
CHANNEL_TENANT_ID=_
# Socket Mode only
SLACK_APP_TOKEN=xapp-...

Leave CHANNEL_TENANT_ID as _ unless you run LibreChat in multi-tenant mode, in which case use the connection's exact tenant ID. Then start the gateway:

docker compose -f docker-compose.yml -f docker-compose.channels.yml \
  -f docker-compose.mongo-replica.yml --profile channels up -d --pull always channel-gateway

For webhook transport, route these paths to the gateway through your HTTPS proxy. In this mode the overlay publishes no host port, so run the proxy on the same Compose network and forward to http://channel-gateway:8080, or add a ports entry for channel-gateway in your Compose override. The IDs are URL-encoded:

https://gateway.example.com/slack/events/<tenantId>/<connectionId>
https://gateway.example.com/slack/interactions/<tenantId>/<connectionId>

Check readiness as described in Verify the gateway.

The gateway fetches the bot token and signing secret from LibreChat, so they never go in its environment. The bundled channel-gateway service serves one manual connection. Each additional connection needs its own gateway process with its own CHANNEL_ID (and SLACK_APP_TOKEN for Socket Mode), for example run from source or as a service you define in your own Compose override. If you expect several bots, organization workspaces serve all of them from one gateway.

Run from source

The gateway can also run as a plain Node.js 24 process. It talks to LibreChat over HTTP and never connects to MongoDB.

npm ci
npm run build:packages
npm run build --workspace @librechat/channel-gateway
node --env-file=/secure/channel-gateway.env packages/channel-gateway/dist/main.cjs
LIBRECHAT_INTERNAL_URL=http://127.0.0.1:3080
CHANNEL_SERVICE_TOKEN=<same value as LibreChat>
CHANNEL_TENANT_ID=_
CHANNEL_ID=<connection ID>
SLACK_TRANSPORT=socket_mode
SLACK_APP_TOKEN=xapp-...

For organization workspaces, leave CHANNEL_ID, SLACK_APP_TOKEN, and SLACK_TRANSPORT out (or set SLACK_TRANSPORT=webhook); an empty CHANNEL_ID selects shared mode, which requires webhook transport and fails startup if SLACK_TRANSPORT=socket_mode is set. npm run backend:dev starts only LibreChat, not the gateway. If you reuse LibreChat's .env, set PORT=8080 explicitly so the gateway does not try to take LibreChat's port.

Existing local data

The replica overlay can convert the bundled MongoDB in place, but treat it like any database migration:

  1. Back up the database.
  2. Stop LibreChat, every gateway, and then MongoDB.
  3. Keep the existing data-node directory and its volume. Do not delete them.
  4. Start again with the same data directory and the replica overlay.
  5. Check that existing users and conversations are intact before enabling the gateway, and keep the overlay on every future restart.

Initialization only configures an unconfigured local rs0 member at mongodb:27017, keeps existing documents, and refuses to change a different replica configuration. A single-member replica set enables transactions but provides no high availability. For production, follow MongoDB's standalone to replica set conversion with your usual security and backup practices. Never run the local initializer against an external database.

Gateway settings

VariableDefaultPurpose
CHANNEL_SERVICE_TOKENRequiredShared secret for the private channel API. At least 32 characters, same value in LibreChat.
LIBRECHAT_INTERNAL_URLhttp://localhost:3080How the gateway reaches LibreChat. Inside a container, localhost is the container itself; the Compose overlay uses http://api:3080.
CHANNEL_IDEmpty (shared mode)Manual mode: the connection ID from the Agent Builder. Not a Slack channel ID or agent ID.
CHANNEL_TENANT_ID_ in the Compose overlayManual mode: the connection's exact tenant. Use _ for single-tenant deployments.
SLACK_TRANSPORTFrom LibreChatOptional check: webhook or socket_mode. Startup fails if it differs from librechat.yaml.
SLACK_APP_TOKENNoneManual Socket Mode only: the app-level token for the same Slack app.
PORT8080HTTP port.
LISTEN_HOST0.0.0.0Listen address. Use 127.0.0.1 for a host-only process.
APP_TITLELibreChatName in buttons such as Open in LibreChat. 1-40 characters, without <, >, or |.
API_CALL_TIMEOUT_MS10000Timeout for each call to LibreChat or Slack.
AGENT_INVOKE_TIMEOUT_MS120000Timeout for starting a background Response. The agent run itself can take longer.

Behavior settings such as native agent sessions, lifecycle reactions, and the signature window live under endpoints.agents.channels in librechat.yaml; the gateway loads them from LibreChat at startup. The old SLACK_NATIVE_SESSIONS, SLACK_LIFECYCLE_REACTIONS, and SLACK_SIGNATURE_TOLERANCE_SECS variables stop the gateway with an error. See the full channels configuration reference.

Verify the gateway

The gateway exposes these endpoints on its port:

EndpointPublic?Purpose
/slack/events/...Yes, for webhook transportSlack event callbacks
/slack/interactions/...Yes, for webhook transportSlack button and form callbacks
/livezNoThe process is alive.
/readyz, /healthzNoStartup finished and the Slack transport is ready. Returns 503 until then.
/metricsNoPrometheus metrics.

Check the containers and their logs with the same Compose files you started them with:

docker compose -f docker-compose.yml -f docker-compose.channels.yml \
  -f docker-compose.slack-workspaces.yml -f docker-compose.mongo-replica.yml \
  --profile channels ps -a
docker compose -f docker-compose.yml -f docker-compose.channels.yml \
  -f docker-compose.slack-workspaces.yml -f docker-compose.mongo-replica.yml \
  --profile channels logs --tail=100 api mongodb-init channel-gateway

For a manual connection, leave out docker-compose.slack-workspaces.yml. mongodb-init exiting with status 0 is expected. The API and gateway should be running and healthy.

ProblemLikely cause
Gateway calls to LibreChat return 401CHANNEL_SERVICE_TOKEN differs between the two, or LIBRECHAT_INTERNAL_URL points at another instance.
Gateway stays unreadyThe transport does not match librechat.yaml, the manual connection is not active, or the Socket Mode token belongs to another app. Restart the gateway after changing the transport or the Slack app.
LibreChat fails with "Invalid shared Slack setup"A domain or gateway URL is not public HTTPS.

The final check is end to end: link an account in Slack and send the bot a new request. See Use agents in Slack.

Stop or remove the gateway

Stop it with the same Compose files and stop channel-gateway. To turn channels off entirely, clear the API's effective SLACK_WORKSPACES_ENABLED override first (drop -f docker-compose.slack-workspaces.yml when using the shared Compose overlay, and remove SLACK_WORKSPACES_ENABLED=true from .env or your process environment if set there), set endpoints.agents.channels.enabled: false in librechat.yaml if you enabled it manually, and recreate or restart the api service. Keep the replica set: stopping the gateway does not require converting or deleting any data.

Next steps

How is this guide?