OpenAI API key env variable does not take effect #929

Closed
opened 2025-11-11 14:33:53 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @nopoz on GitHub (May 15, 2024).

Bug Report

Description

If you've manually set the OpenAI API Key before and then erased it in the UI, the config.json looks like this:

{
	"ollama": {
		"base_urls": [
			"http://ollama:11434"
		]
	},
	"openai": {
		"api_base_urls": [
			"https://api.openai.com/v1"
		],
		"api_keys": [
			""
		]
	}
}

If you then set the "OPENAI_API_KEY" environment variable in Docker compose, it will not overwrite the existing config.json api_keys empty value "".

Steps to Reproduce:
Enter an OpenAI API Key in the webui save, then delete it. Enter OPENAI_API_KEY in docker compose environment variables restart the container, launch web ui and check "Settings -> Connections -> OpenAI API". The API key is blank and no OpenAI models have been loaded.

Compose Example:

version: '3.3'
services:
    ollama-webui:
        container_name: ollama-webui
        environment:
        - OLLAMA_BASE_URL=http://ollama:11434
        - USE_CUDA_DOCKER=True
        - PORT=${WEB_UI_PORT}
        - OPENAI_API_KEY=${OPENAI_API_KEY}
        - OPENAI_API_BASE_URL=https://api.openai.com/v1
        depends_on:
          - ollama
        volumes:
          - "ollama-webui:/app/backend/data"
        ports:
            - ${WEB_UI_PORT}:${WEB_UI_PORT}
        restart: unless-stopped
        image: ghcr.io/open-webui/open-webui:git-db158fc-cuda
        deploy:
          resources:
            reservations:
              devices:
                - driver: nvidia
                  count: all
                  capabilities: [gpu]

Verifying "OPENAI_API_KEY" env variable inside container:

$ docker exec -t -i ollama-webui /bin/bash
root@d8a96155eab8:/app/backend# env
OPENAI_API_KEY=<redacted>

The Browser Debug network request when loading the settings page:

request:
https://<my host>/openai/api/keys

response:
{"OPENAI_API_KEYS":[""]}

Workaround:

Manually edit out the OpenAI configuration from config.json and restart the container.

Example config.json:

{
	"ollama": {
		"base_urls": [
			"http://ollama:11434"
		]
	}
}

Expected Behavior:
For the environment variable to be ingested into the config by open-webui and overwrite whatever is currently configured in config.json.

Actual Behavior:
OpenAI API key is blank in the UI.

Environment

  • Open WebUI Version: v0.1.124

  • Ollama (if applicable): n/a

  • Operating System: Docker

  • Browser (if applicable): Firefox 124.0.1

Reproduction Details

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • [n/a] I have included the Docker container logs.

Logs and Screenshots

Browser Console Logs:
see above

Docker Container Logs:
n/a

Screenshots (if applicable):
n/a

Installation Method

Docker

Additional Information

see above

Originally created by @nopoz on GitHub (May 15, 2024). # Bug Report ## Description If you've manually set the OpenAI API Key before and then erased it in the UI, the config.json looks like this: ``` { "ollama": { "base_urls": [ "http://ollama:11434" ] }, "openai": { "api_base_urls": [ "https://api.openai.com/v1" ], "api_keys": [ "" ] } } ``` If you then set the "OPENAI_API_KEY" environment variable in Docker compose, it will not overwrite the existing config.json api_keys empty value `""`. **Steps to Reproduce:** Enter an OpenAI API Key in the webui save, then delete it. Enter OPENAI_API_KEY in docker compose environment variables restart the container, launch web ui and check "Settings -> Connections -> OpenAI API". The API key is blank and no OpenAI models have been loaded. Compose Example: ``` version: '3.3' services: ollama-webui: container_name: ollama-webui environment: - OLLAMA_BASE_URL=http://ollama:11434 - USE_CUDA_DOCKER=True - PORT=${WEB_UI_PORT} - OPENAI_API_KEY=${OPENAI_API_KEY} - OPENAI_API_BASE_URL=https://api.openai.com/v1 depends_on: - ollama volumes: - "ollama-webui:/app/backend/data" ports: - ${WEB_UI_PORT}:${WEB_UI_PORT} restart: unless-stopped image: ghcr.io/open-webui/open-webui:git-db158fc-cuda deploy: resources: reservations: devices: - driver: nvidia count: all capabilities: [gpu] ``` Verifying "OPENAI_API_KEY" env variable inside container: ``` $ docker exec -t -i ollama-webui /bin/bash root@d8a96155eab8:/app/backend# env OPENAI_API_KEY=<redacted> ``` The Browser Debug network request when loading the settings page: request: `https://<my host>/openai/api/keys` response: `{"OPENAI_API_KEYS":[""]}` **Workaround:** Manually edit out the OpenAI configuration from config.json and restart the container. Example config.json: ``` { "ollama": { "base_urls": [ "http://ollama:11434" ] } } ``` **Expected Behavior:** For the environment variable to be ingested into the config by open-webui and overwrite whatever is currently configured in config.json. **Actual Behavior:** OpenAI API key is blank in the UI. ## Environment - **Open WebUI Version:** v0.1.124 - **Ollama (if applicable):** n/a - **Operating System:** Docker - **Browser (if applicable):** Firefox 124.0.1 ## Reproduction Details **Confirmation:** - [X] I have read and followed all the instructions provided in the README.md. - [X] I am on the latest version of both Open WebUI and Ollama. - [X] I have included the browser console logs. - [n/a] I have included the Docker container logs. ## Logs and Screenshots **Browser Console Logs:** see above **Docker Container Logs:** n/a **Screenshots (if applicable):** n/a ## Installation Method Docker ## Additional Information see above
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#929