# NextChat

> Connect NextChat (ChatGPT-Next-Web) to MirAPI via the BASE_URL and OPENAI_API_KEY deploy variables or the custom-endpoint settings page.

NextChat (ChatGPT-Next-Web) is an open-source ChatGPT web client. It speaks the OpenAI protocol, so connecting it to MirAPI works like any other OpenAI-compatible tool: one base URL and one key.

## What you need

| Element | Value |
|---|---|
| Base URL | `https://api.mirapi.ai/v1` |
| API key | Your MirAPI key (`sk-...`) |
| Model | `deepseek-chat` |

NextChat appends `/chat/completions` to the base URL and authenticates with `Authorization: Bearer`. Its custom endpoint expects an OpenAI-compatible API, so only the OpenAI base URL applies here — the Anthropic and Gemini base URLs are not used.

## Configure

### Option A — Deploy variables

Set these in your deployment environment:

```bash
BASE_URL="https://api.mirapi.ai/v1"
OPENAI_API_KEY="sk-..."
```

NextChat reads the key from `OPENAI_API_KEY` and the endpoint from `BASE_URL`. Restart the app after changing them.

### Option B — Settings page

1. Open **Settings → Custom Endpoint (OpenAI)** (newer versions: **Model Provider**).
2. Set the interface address to `https://api.mirapi.ai/v1`.
3. Enter your MirAPI key (`sk-...`) and set the default model to `deepseek-chat`.

## Verify with a message

Send:

```text
Reply with exactly: connected to MirAPI
```

Expect the exact phrase in the reply.

## Tool-specific pitfalls

- **Keep `/v1` in the endpoint** — NextChat appends `/chat/completions`, so `https://api.mirapi.ai/v1` becomes `https://api.mirapi.ai/v1/chat/completions`.
- **The model selector is not fetched from the API.** NextChat shows its built-in list plus `CUSTOM_MODELS`; add `deepseek-chat` with `CUSTOM_MODELS=-all,+deepseek-chat` (or type the exact name) instead of waiting for it to appear.
- **Model names are verbatim** — use the exact id from `GET /v1/models`; the `vendor/` prefix is for browsing and filtering in the console, never in a request.
- **403 with a valid key** means the model is not on the whitelist or the balance is exhausted — top up and retry. `401` means the key is missing, invalid, or unknown.
- **The in-app endpoint wins over `BASE_URL`** — a custom endpoint saved in the browser takes precedence over the deploy variable, so if requests keep going elsewhere, clear or fix it on the settings page first.

## Related links

- [Quickstart](/docs/quickstart)
- [OpenAI compatibility](/docs/openai-compat)
- [Models](/docs/models)
- [Billing](/docs/billing)
- [Errors](/docs/api-reference/errors)