Chat apps
Open WebUI and LibreChat are self-hosted chat apps that give a company a ChatGPT style window for its own staff. Both speak the OpenAI format, so they can use the gateway as their only model provider. That gives the app every model the gateway serves under one key, one budget and one set of guardrails, with each conversation on the Logs page, and the app never holds a provider key. When the admin adds a model on the gateway it shows up in the app's model list without touching the app.
A real-world scenario
A 300 person company runs Open WebUI for its staff and a LibreChat instance for the support team. Each app used to hold three provider keys, and nobody could say what the support team spent. The admin creates one gateway key per app with a monthly budget and the models each app may offer, and points both apps at the gateway. Each app now lists exactly the models its key allows, the support team's spend shows under its own key on Usage, every message is on Logs with the person who sent it, and when a provider has an outage the gateway falls back to another one while the chat keeps working.
Before you start
- A running gateway that the chat app's server can reach, for example
https://gateway.example.com. The app's server calls the gateway, not the person's browser, so the address must resolve from where the app runs. - An admin account in the chat app, and access to its environment or configuration file.
- A virtual key for the app, made in the next section.
Make a key for the app
- In the Admin UI open Virtual Keys (
/ui/api-keys) and click + Create New Key. - Under Key Ownership pick Service Account and a Team, because the key belongs to the app, not to a person. Set Service Account ID to the app, such as
open-webui-prod, and leave Key Type on AI APIs. - In Models, pick the chat models the app should offer, plus the cheap model the app uses for background tasks such as conversation titles and tags, plus the embedding model if the app's document search should go through the gateway. A missing background model makes titles fail with 403 while chat works.
- Open Optional Settings. Set Max Budget (USD) and Reset Budget, for example 2000 USD monthly for a company chat app, and Requests per minute Limit (RPM) sized for your busiest hour. Leave Tags empty unless the gateway has an Enterprise license, because key tags need one and without it the key is not created (
Only premium users can add tags to keys). The key name already keeps this tool's spend apart in Usage. - Click Create Key and copy the key. It is shown once.
The same key from the API:
curl -X POST https://gateway.example.com/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "open-webui-prod", "key_type": "llm_api", "team_id": "<team id>", "models": ["claude-sonnet-5-5", "gpt-6.1-sol", "claude-haiku-5-5", "text-embedding-3-large"], "max_budget": 2000, "budget_duration": "30d", "rpm_limit": 600}'
One key serves every person using the app. To see spend per person as well, have the app forward who is asking, as described under spend per person.
Steps
-
Check the key from the machine the app runs on, with the same address the app will use.
curl https://gateway.example.com/v1/models -H "Authorization: Bearer $SPANWAY_API_KEY" -
Enter the base URL with
/v1,https://gateway.example.com/v1, and the key in the app, as shown for each app below. Both apps add/chat/completionsand/modelsto the address themselves, so never paste the full route. -
Open a new chat, pick a model from the list and send a message.
-
Open Logs (
/ui/logs), click Filters, pick the key in Key Alias and click Apply Filters. The message is a row, often with one or two background calls next to it.
Open WebUI
- Sign in to Open WebUI as an admin and open Admin Panel, then Settings, then Connections.
- Under Manage OpenAI API Connections, click Add Connection.
- Set URL to
https://gateway.example.com/v1and API Key to the virtual key. Leave Model IDs empty to list every model the key may use, or enter names to offer only some of them. - Click Verify Connection next to the URL. Open WebUI calls
/v1/modelson the gateway and reportsServer connection verified. - Click Save. The gateway's models appear in the model picker of a new chat.
When Open WebUI runs in Docker, the same connection can be set in its container environment. OPENAI_API_BASE_URL and OPENAI_API_KEY set the connection, and ENABLE_OLLAMA_API=false hides the empty local model section.
services:
open-webui:
environment:
OPENAI_API_BASE_URL: "https://gateway.example.com/v1"
OPENAI_API_KEY: "${SPANWAY_API_KEY}"
ENABLE_OLLAMA_API: "false"
Open WebUI copies these values into its own database on the first start, and from then on the values in Admin Panel win. A later change to the environment has no effect until you change the connection in the panel too, or start Open WebUI with ENABLE_PERSISTENT_CONFIG=false. If the gateway runs on the Docker host and Open WebUI in a container, use http://host.docker.internal:4000/v1, because localhost inside the container is the container itself.
Background calls. Open WebUI asks a model for a title, tags and follow up suggestions after a chat starts, so one message can show as two to four rows on Logs. Under Admin Panel, Settings, Interface, set the external task model to a cheap gateway model such as claude-haiku-5-5, and turn off the generations you do not need.
Document search. Under Admin Panel, Settings, Documents, choose OpenAI as the embedding engine with the same URL and key, and a gateway embedding model such as text-embedding-3-large, so document embeddings go through the gateway and its budget too.
LibreChat
LibreChat adds the gateway as a custom endpoint in its librechat.yaml file. The name must not be one of LibreChat's built in endpoint names, which are openAI, azureOpenAI, google, anthropic, assistants, azureAssistants, agents and bedrock.
-
Put the key in LibreChat's
.envfile.SPANWAY_API_KEY=sk-your-virtual-key -
Add the endpoint to
librechat.yaml.version: 1.3.19endpoints:custom:- name: "Spanway"apiKey: "${SPANWAY_API_KEY}"baseURL: "https://gateway.example.com/v1"models:default: ["claude-sonnet-5-5", "gpt-6.1-sol"]fetch: truetitleConvo: truetitleModel: "claude-haiku-5-5"modelDisplayLabel: "Spanway"headers:x-spanway-end-user-id: "{{LIBRECHAT_USER_EMAIL}}" -
With Docker, mount the file into the
apiservice indocker-compose.override.yml.services:api:volumes:- type: bindsource: ./librechat.yamltarget: /app/librechat.yaml -
Restart LibreChat so it reads the file, with
docker compose down && docker compose up -d. -
Open a new chat and pick Spanway in the endpoint selector. The model list holds the names the key may use.
models.fetch: true loads the model list from the gateway's /v1/models, and models.default is the list LibreChat shows when the fetch fails. titleModel sends the title request to a cheap model, and titleConvo: false stops it. apiKey: "user_provided" lets each person paste their own gateway key instead of the shared one, which gives each person their own budget, but then every person needs a key. dropParams removes a parameter LibreChat sends by default, such as frequency_penalty, when a model behind a name rejects it, and addParams adds one, such as reasoning_effort.
Spend per person
Both apps send every request with the app's key, so by default Logs and Usage show the app, not the person. Have the app forward who is asking, and the gateway records it as the end user. It then shows in the End User column and filter on Logs, and Customers can give each person a budget of their own.
-
LibreChat sends the header from the
headersblock above.x-spanway-end-user-idis read by the gateway with no extra setting. -
Open WebUI sends its user headers when its container has
ENABLE_FORWARD_USER_INFO_HEADERS=true. Tell the gateway which one holds the person.general_settings:user_header_mappings:- header_name: X-OpenWebUI-User-Emailspanway_user_role: customer
A forwarded email is personal data, so it is stored in the spend log as the end user id. Forward a user id instead of an email when your privacy rules prefer it, see what Spanway stores.
Expected result
The app lists the gateway's models in its model picker, filtered to what the key may call, and answers stream in word by word. On the gateway side:
- Logs has a row per message, plus rows for titles, tags or follow ups, each with the model, tokens and cost. With per person headers the End User column shows who sent it.
- Virtual Keys, the key's Overview tab, shows the app's spend against its budget, and Usage groups it by the tag.
- Each answer carries
x-spanway-call-id, the id to search for on Logs, andx-spanway-model-group,x-spanway-model-idandx-spanway-routing-reasonsay which deployment served it. The apps do not show response headers, so read them on Logs or withcurl -i, see routing headers.
What works through the gateway
| Feature | How it behaves | Known limits |
|---|---|---|
| Streaming | Both apps stream by default, and the gateway streams from every provider. | A proxy in front of the gateway that buffers responses makes answers arrive all at once. |
| Images | Image uploads reach vision models from every provider. | A model without vision answers with a provider 400, which the app shows as the reply. |
| Tools and agents | Open WebUI tools in native function calling mode and LibreChat agents send tool calls that the gateway translates for every provider that supports tools. | A model without tool support fails the tool call. Both apps also have their own MCP client, and can instead reach tools the admin registered on the MCP gateway. |
| Reasoning | Reasoning models work. LibreChat passes reasoning_effort through addParams. | How much of the reasoning text the app shows depends on the app and the provider. |
| Document search | Embeddings go through the gateway when the app's embedding engine points at it. | With a local embedding engine those calls never reach the gateway. |
| Guardrails | A guardrail that blocks a prompt answers with an error, which the app shows as a failed reply. | An AWS Bedrock guardrail can answer with its block message as a normal reply instead, when it is set with disable_exception_on_block: true, see guardrails. |
Errors
Both apps show the gateway's error text in the chat, in place of the reply or in an error banner, and Open WebUI shows connection problems as a red notice when you verify or save the connection. The client error reference lists every gateway error.
| Case | What the app shows | Cause | Fix |
|---|---|---|---|
| 401 | Authentication Error, Invalid proxy server token passed, or No api key passed in., and Verify Connection fails with 401 | The key is wrong, blocked or deleted, or LibreChat did not read ${SPANWAY_API_KEY} from .env. | Paste the key again, check it with the curl in step 1, and restart LibreChat after editing .env. |
| 403 model not allowed | The requested model '<model>' is not available for this API key, or the model name is invalid. | The model was picked from a stale list, or the title or task model is not on the key. | Add the model to the key in Virtual Keys, or pick another one. Check the title and task model names. |
| 400 unknown model | Invalid model name passed in model=<name> | A name typed in Model IDs or models.default does not exist on the gateway. | Copy names from GET /v1/models, which are case sensitive, or use fetch: true in LibreChat. |
| 400 parameter not supported | does not support parameters: <names>, for model=<model> | The app sent a parameter the provider behind the name does not take. | Remove it with dropParams in LibreChat, or ask the admin to turn on drop params. |
| 422 budget | Budget has been exceeded! with the current cost and maximum | The app's budget is spent, and every person using it is blocked. | Raise Max Budget (USD) or wait for the reset. Give heavy users their own budgets under spend per person. |
| 429 rate limit | Rate limit exceeded for <scope>: <value>. | The app is over the key's RPM or TPM limit, often at the start of the work day. | Raise Requests per minute Limit (RPM), and turn off background generations you do not need. |
| 404 wrong path or doubled /v1 | Not Found, and the model list stays empty | The URL is the full route, such as /v1/chat/completions, or carries /v1 twice. | Use https://gateway.example.com/v1 exactly. |
| Connection refused | Verify Connection fails, or the reply shows a connection error naming ECONNREFUSED or Cannot connect to host | The app runs in Docker and the URL says localhost, or the gateway is down. | Use host.docker.internal or the gateway's service name, and check curl https://gateway.example.com/health/liveliness. |
| TLS or CA error | CERTIFICATE_VERIFY_FAILED in Open WebUI, UNABLE_TO_GET_ISSUER_CERT_LOCALLY or SELF_SIGNED_CERT_IN_CHAIN in LibreChat | The gateway's certificate comes from a company authority the container does not trust. | Mount the company root certificate into the container and set SSL_CERT_FILE and REQUESTS_CA_BUNDLE for Open WebUI, or NODE_EXTRA_CA_CERTS for LibreChat. |
Troubleshooting
- Run the curl from step 1 inside the app's container, for example with
docker compose exec, so it uses the same network and certificates as the app. If it fails, fix the address, network or TLS first. - Open Logs, filter by Key Alias, and find the message by its time or by End User. No row means the request never reached the gateway. A row shows the status, the error text and the deployment the router picked.
- Check the app's own log. For Open WebUI set
GLOBAL_LOG_LEVEL=DEBUGon the container and readdocker logsfor the container. For LibreChat readdocker compose logs api, and keepDEBUG_LOGGING=truein.envfor the full request detail. - When the request reaches the gateway but the reason is unclear, run a test gateway with
--detailed_debug, see troubleshooting.
Rotate or remove the key
Open the key in Virtual Keys and click Regenerate Key with a Grace Period such as 24h, which needs an Enterprise license. Without one, create a new key and delete the old one after the switch. Then put the new key in the app. In Open WebUI edit the connection under Admin Panel, Settings, Connections and click Save, because a changed OPENAI_API_KEY alone is ignored after the first start. In LibreChat change SPANWAY_API_KEY in .env and restart with docker compose down && docker compose up -d.
To stop the app at once, click Block Key in the key's actions menu, and Unblock Key to undo it. To remove it, click Delete Key and type the alias. Remove the connection from the app as well, so it stops trying.
Related
- Connect any client for base URLs and key headers.
- Make a key for a tool for the admin side in full.
- Customers for a budget per person behind a shared app key.
- Client error reference for every gateway error.
- Chat UI for the chat window built into the gateway itself.
- Agent frameworks and n8n for the other kinds of tools.