> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/integration-examples/chat/librechat.md).

# LibreChat

Use Cortecs models in a self-hosted LibreChat deployment

[LibreChat](https://www.librechat.ai/) is an open-source, self-hosted chat platform. Because Cortecs provides an OpenAI-compatible API, you can add Cortecs as a custom endpoint while keeping LibreChat as your chat interface.

{% hint style="info" %}
Before you begin, create a Cortecs API key by following the [Member quickstart](/member-quickstart.md) and choose a model from the [model catalog](https://cortecs.ai/serverlessModels).
{% endhint %}

## 1. Add your Cortecs API key

Add the following variable to the `.env` file used by the LibreChat API service:

```bash
CORTECS_API_KEY=your_cortecs_api_key
```

Keep the key in an environment variable. Do not add the key itself to `librechat.yaml` or commit it to source control.

## 2. Configure the Cortecs endpoint

Create or edit `librechat.yaml` in the LibreChat project root. Keep any existing top-level settings and add the Cortecs configuration below.

```yaml
version: 1.3.13
cache: true

interface:
  agents: false
  modelSelect: false

endpoints:
  custom:
    - name: "Cortecs"
      apiKey: "${CORTECS_API_KEY}"
      baseURL: "https://api.cortecs.ai/v1"
      models:
        default:
          - "<MODEL_ID>"
        fetch: false
      titleConvo: true
      titleModel: "<MODEL_ID>"
      modelDisplayLabel: "Cortecs"

modelSpecs:
  prioritize: true
  enforce: true
  list:
    - name: "cortecs-chat"
      label: "Cortecs"
      default: true
      showOnLanding: true
      preset:
        endpoint: "Cortecs"
        model: "<MODEL_ID>"
```

Replace each `<MODEL_ID>` with the same exact ID from the [model catalog](https://cortecs.ai/serverlessModels).

Use `https://api.cortecs.ai/v1` as the base URL. LibreChat appends `/chat/completions` when it sends a message, so do not include that path in `baseURL`.

The example creates a focused chat setup in which Cortecs is selected by default. If your LibreChat release requires a different configuration version, keep the `version` value from its `librechat.example.yaml` file.

## 3. Mount the configuration

For Docker Compose deployments, create or edit `docker-compose.override.yml` and mount the configuration into the API container:

```yaml
services:
  api:
    volumes:
      - ./librechat.yaml:/app/librechat.yaml:ro
```

For other deployment methods, follow LibreChat's [custom configuration guide](https://www.librechat.ai/docs/configuration/librechat_yaml) to make the file available to the API service.

## 4. Restart LibreChat

If the file was already mounted, restart the API service:

```bash
docker compose restart api
```

If you added the mount for the first time, recreate the containers:

```bash
docker compose down
docker compose up -d
```

Open LibreChat, sign in, and start a new conversation. Cortecs should appear as the selected model.

## Troubleshooting

### Cortecs or its models do not appear

Check that:

* `CORTECS_API_KEY` is available inside the LibreChat API container.
* `librechat.yaml` is mounted at `/app/librechat.yaml` for Docker deployments.
* The model ID exactly matches an ID from the [model catalog](https://cortecs.ai/serverlessModels).
* LibreChat was restarted after the configuration changed.

### Requests return `401` or `403`

Confirm that the API key is valid and that the endpoint references it as `apiKey: "${CORTECS_API_KEY}"`.

### Requests return `404`

Set `baseURL` to `https://api.cortecs.ai/v1`, not the full Chat Completions URL. Also verify the model ID.

### Requests contain unsupported parameters

Custom endpoints use LibreChat's OpenAI parameter set. If an added parameter is not supported by the selected model, remove it and retry with only `model` and `messages`.

For more configuration options, see LibreChat's [custom endpoints documentation](https://www.librechat.ai/en/docs/quick_start/custom_endpoints) and [custom endpoint field reference](https://www.librechat.ai/en/docs/configuration/librechat_yaml/object_structure/custom_endpoint).
