DEV Community

Adding an OpenAI-compatible gateway to LibreChat: the three files and the three usual mistakes

The slow part of a LibreChat setup usually isn't Docker. It's getting a third-party gateway to actually show up in the endpoint picker.

The official docs cover everything, but the pieces live in three different files, so here's the short version. The examples use api.niceai.dev as a sample host. Swap in whatever OpenAI-compatible gateway you use.

Which file does what

  • librechat.yaml : the endpoint itself (name, base URL, models)
  • .env : the API key, referenced from the yaml as ${VAR_NAME}
  • docker-compose.override.yml : Docker only, so the container can see the yaml at all

Forgetting the last one is the classic "I edited the config and nothing changed".

1. Mount the yaml (Docker only)

cp docker-compose.override.yml.example docker-compose.override.yml

Make sure this part is uncommented:

services:
  api:
    volumes:
      - type: bind
        source: ./librechat.yaml
        target: /app/librechat.yaml

2. Add the endpoint

version: 1.3.19 # use the version from your own librechat.example.yaml
cache: true
endpoints:
  custom:
    - name: 'NiceAI'
      apiKey: '${NICEAI_API_KEY}'
      baseURL: 'https://api.niceai.dev/v1'
      models:
        default: ['your-model-id']
        fetch: true
      titleConvo: true
      titleModel: 'current_model'
      modelDisplayLabel: 'NiceAI'

With fetch: true LibreChat pulls the model list from the gateway, so default is only a fallback. To see what the gateway actually returns:

curl https://api.niceai.dev/v1/models \
  -H "Authorization: Bearer $NICEAI_API_KEY"

3. Put the key in .env

NICEAI_API_KEY=sk-...

If every user should bring their own key, use apiKey: 'user_provided' instead. LibreChat then asks for the key in the UI the first time someone picks the endpoint, and nothing goes in .env.

Then recreate the containers so the new mount and env are picked up:

docker compose down && docker compose up -d

The three usual mistakes

/v1 in the wrong place. For a normal OpenAI-compatible endpoint the base URL ends in /v1. If you set provider: 'anthropic' for a gateway that speaks the native Anthropic Messages API, the base URL is the host without /v1, the same shape as https://api.anthropic.com in LibreChat's own example. Mixing the two up is where most 404s come from.

Using provider: anthropic when you don't need it. LibreChat's docs say to use it only for endpoints that really speak Anthropic Messages. If a gateway just serves Claude models over the OpenAI format, leave provider out and keep the /v1 URL.

A model rejects a parameter. If you get a 400 or 422 complaining about something like stop, add dropParams: ['stop'] (or whatever it names) to that endpoint and LibreChat strips it before sending.

If the endpoint shows up but every message 401s, check the API container logs first. It's almost always the key not being read from .env.

Full field reference: https://www.librechat.ai/docs/configuration/librechat_yaml/object_structure/custom_endpoint

The sample host is NiceAI; its docs list the base URL for each protocol (OpenAI /v1, Claude without /v1, Gemini /v1beta): https://wiki.niceai.dev/en/

Written with AI assistance; the config was checked against the current LibreChat docs.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.