Point NextChat at a custom OpenAI-compatible endpoint.
Updated 2026-07-16
NextChat overrides its API host with one BASE_URL environment variable on server deploys, or an in-app custom endpoint in Settings on the clients. Add catalog ids through CUSTOM_MODELS with the @OpenAI suffix and Claude, Gemini, and DeepSeek appear in the same model picker under one key.
Quick answer: BASE_URL, one key, and a models list.
On a server deploy (Vercel, Docker, or bare Node), three environment variables do the whole job. BASE_URL overrides where API requests go; the README describes it as "override openai api request base url" with a default of https://api.openai.com, and the value is entered without /v1 because NextChat appends the request path itself. OPENAI_API_KEY carries the gateway key. CUSTOM_MODELS controls the model picker: plus adds a model, minus hides one, -all clears the default list, and name=displayName renames an entry. The detail that makes multi-vendor ids work is the provider suffix. NextChat ships separate client code paths for several vendors, so a bare claude id added to CUSTOM_MODELS can surface under the Anthropic path, which expects a different key and request format. Appending @OpenAI to the id, as in +claude-sonnet-4-6@OpenAI, pins the model to the OpenAI-compatible path so the request goes to your BASE_URL in standard chat-completions format regardless of which vendor trained the model.
BASE_URL=https://api.apisrouter.com # no /v1
OPENAI_API_KEY=sk-APIsRouter-...
CUSTOM_MODELS=-all,+claude-sonnet-4-6@OpenAI,+gpt-5.5@OpenAI,+deepseek-v4-pro@OpenAI
DEFAULT_MODEL=claude-sonnet-4-6How NextChat resolves its endpoint.
NextChat (ChatGPTNextWeb on GitHub, roughly 88K stars) is one of the most deployed chat frontends in existence: a light web app with one-click Vercel deployment plus packaged clients for iOS, macOS, Android, Windows, and Linux. Its popularity comes from exactly the mechanism this page uses, everything is a configuration surface, and the endpoint is just another setting. There are two of those surfaces. Server deploys read environment variables at build and boot: BASE_URL decides the host, OPENAI_API_KEY authenticates, and CUSTOM_MODELS shapes the picker for every user of that deployment. The clients and the web UI additionally expose an in-app path: Settings, Model Provider, pick OpenAI, then fill the endpoint and key fields and list extra ids in the custom model names field. The in-app path stores values locally per device, which makes it the right surface for a personal client, while env vars are the right surface for a deployment other people use. Either way, the request that leaves NextChat is a standard chat completion against your endpoint with the model id as a plain string. With a multi-vendor gateway behind BASE_URL, the same deployment serves Claude for long answers, a fast Gemini id for quick questions, and DeepSeek or GLM for bilingual traffic, all through the one key.
Full setup: server deploy or in-app settings.
For a Vercel deploy, set the variables in the project's environment settings and redeploy; Vercel bakes env values in at build, so editing a variable without redeploying changes nothing. For Docker, pass the same variables with -e flags or an env file. The CODE variable is worth setting on any public deployment, it gates access with a password so strangers cannot spend your key. The in-app path needs no deployment at all. In Settings, choose the OpenAI provider, replace the endpoint with https://api.apisrouter.com, paste the key, and add ids in the custom model names field using the same syntax as the env variable. This is how the desktop and mobile clients work with a gateway, and it is also the fastest way to test values before committing them to a server deploy. DEFAULT_MODEL picks what new chats start on, which matters more than it sounds on a shared deployment: most users never change the model, so the default id is where most of the spend lands. Set it deliberately to the model you want carrying casual traffic.
docker run -d -p 3000:3000 \
-e BASE_URL=https://api.apisrouter.com \
-e OPENAI_API_KEY=$APISROUTER_API_KEY \
-e CUSTOM_MODELS="-all,+claude-sonnet-4-6@OpenAI,+claude-haiku-4-5-20251001@OpenAI,+gemini-3.5-flash@OpenAI" \
-e DEFAULT_MODEL=claude-haiku-4-5-20251001 \
-e CODE=your-access-password \
yidadaa/chatgpt-next-webChoosing models for the picker.
Because the whole picker bills through one key, the tuning loop is observational: run a week, read the per-model usage in the console, and reshape CUSTOM_MODELS around what people actually clicked rather than what you predicted.
- Start the list with -all. The stock picker is a long OpenAI-only menu; clearing it and adding four or five deliberate ids gives users a picker where every choice is one you priced.
- The default model carries the deployment. claude-haiku-4-5-20251001 or gemini-3.5-flash as DEFAULT_MODEL keeps the casual majority of turns fast and inexpensive, with stronger ids one click away.
- Long-form work earns a frontier slot. claude-sonnet-4-6 and gpt-5.5 are the picks users reach for when a draft or an analysis matters.
- Bilingual deployments should include deepseek-v4-pro or glm-5.2; NextChat has an enormous Chinese-speaking install base and those ids fit that traffic natively.
- Renames are free documentation: claude-sonnet-4-6=Sonnet (writing) style entries make the picker self-explanatory for non-technical users.
Pay-as-you-go · transparent per-model pricing
Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.
| Model | Official Price | Our Price |
|---|---|---|
| Claude Sonnet 4.6 | $3.00 / $15.00 per M | $2.40 / $12.00 per M |
| Claude Haiku 4.5 20251001 | $1.00 / $5.00 per M | $0.80 / $4.00 per M |
| GPT-5.5 | $5.00 / $30.00 per M | $4.00 / $24.00 per M |
| Gemini 3.5 Flash | $1.50 / $9.00 per M | $1.20 / $7.20 per M |
| GLM-5.2 | $1.14 / $4.00 per M | $1.03 / $3.60 per M |
Failure modes specific to NextChat.
The /v1 mistake runs in the opposite direction from most tools. NextChat appends the request path to BASE_URL itself, so the value belongs without /v1; pasting https://api.apisrouter.com/v1 produces doubled paths that 404. Tools like LibreChat expect the /v1 included, which is exactly why people carry the wrong habit in both directions. A Claude id that errors about keys or headers is the missing @OpenAI suffix. Without it, NextChat can route the id through its native Anthropic path, which never consults BASE_URL for your gateway and expects vendor-format authentication. Pin every gateway id with @OpenAI and the requests all take the compatible path. Env edits that change nothing are a redeploy problem. On Vercel the variables are read at build; on Docker the container needs recreating. The in-app settings, by contrast, apply immediately but only on that device, which is the other half of the same confusion. CODE and OPENAI_API_KEY get swapped surprisingly often. CODE is the access password users type into the UI; the key is what the server spends. If users report an unauthorized page before any chat happens, that is CODE; if chats fail against the endpoint, that is the key.
Who routes NextChat through a gateway.
- People running a personal deployment on Vercel who want one metered key behind it instead of a subscription per vendor.
- Small teams sharing a NextChat instance, using CODE for access control and one gateway key so the usage log doubles as the cost report.
- Desktop and mobile client users pointing the in-app endpoint at a gateway to reach Claude, Gemini, and DeepSeek from one picker on every device.
- Bilingual users mixing GLM and DeepSeek ids with Claude and GPT in one deployment, which native provider silos make awkward.
- Developers without access to a given vendor's billing. Top-up based access with no card requirement removes the per-provider sign-up dependency.
Verify the endpoint and debug the first chat.
Prove the endpoint before deploying: list models with the key and confirm every id you plan to put in CUSTOM_MODELS appears, spelled exactly. The ids are forwarded as strings, so the /v1/models output is the authoritative spelling. Then deploy and send one message per model in the picker. A 404 on everything is the /v1-in-BASE_URL mistake. A 401 is the key, either wrong or not present in the environment the build actually used. An error on Claude ids only is the missing @OpenAI suffix. A picker showing models you never added means CUSTOM_MODELS lost its -all prefix or the variable did not reach the build. Once chats flow, the APIsRouter console shows per-request model, token counts, and spend. For a deployment with more than one user, that view answers the question every NextChat admin eventually asks, which model is quietly eating the balance, with data instead of guesses.
curl -s https://api.apisrouter.com/v1/models \
-H "Authorization: Bearer $APISROUTER_API_KEY" | head -50FAQ
Should NextChat's BASE_URL include /v1?
No. NextChat appends the request path itself, so set BASE_URL=https://api.apisrouter.com without /v1. Including it produces doubled paths that 404. This is the opposite convention from tools like LibreChat, which expect the /v1 in the base URL.
How do I add Claude or Gemini models to NextChat through one endpoint?
Add them in CUSTOM_MODELS with the @OpenAI suffix, for example +claude-sonnet-4-6@OpenAI. The suffix pins the id to the OpenAI-compatible request path so it goes to your BASE_URL, instead of NextChat's native Anthropic or Google client paths.
What is the difference between the env variables and the in-app settings?
Environment variables configure a server deployment for every user and require a redeploy to change. The in-app custom endpoint in Settings stores values locally per device and applies immediately, which suits personal desktop and mobile clients.
How do I remove the default OpenAI model list from the picker?
Start CUSTOM_MODELS with -all, then add ids explicitly: CUSTOM_MODELS=-all,+claude-sonnet-4-6@OpenAI,+gpt-5.5@OpenAI. Users then only see models you deliberately listed and priced.
What does the CODE variable do?
It sets one or more access passwords for the deployment. Visitors must enter a code before chatting, which keeps a public Vercel URL from spending your key. It is unrelated to the API key itself.
Why did changing an environment variable have no effect?
NextChat reads env values at build or container start. On Vercel, edit the variable and redeploy; on Docker, recreate the container. Only the in-app settings apply without a restart, and those live per device.