feat: preconfigure OpenAI-compatible providers from env vars

Open WebUI already speaks to any OpenAI-compatible endpoint, but reaching
one means an admin knowing the base URL exists and typing it into
Admin > Settings > Connections. Nothing in the product hints that the
endpoint is reachable at all.

Add a small registry of OpenAI-compatible providers Open WebUI ships the
base URL for. Setting a provider's API key env var seeds a ready-to-use
connection on first start; adding another provider is one dict entry.
Melious is the first entry (MELIOUS_API_KEY / MELIOUS_API_BASE_URL), and
its endpoint joins the URL suggestions in the Add Connection modal.

The loader normalizes keys to the URL count the same way
normalize_openai_api_keys does, and skips any base URL already present,
so an explicit OPENAI_API_BASE_URLS entry always wins. With no provider
key set the resulting config is byte-identical to today's default.

Follows the load_oauth_providers() idiom already in config.py.
This commit is contained in:
s.agrawal 2026-08-19 20:32:13 +05:30
parent 01f4282f1f
commit 02cde198c3
4 changed files with 58 additions and 0 deletions

View file

@ -5,6 +5,10 @@ OLLAMA_BASE_URL='http://localhost:11434'
OPENAI_API_BASE_URL=''
OPENAI_API_KEY=''
# Preconfigured OpenAI-compatible providers: setting the key seeds the connection on first start
# MELIOUS_API_KEY=''
# MELIOUS_API_BASE_URL='https://api.melious.ai/v1'
# AUTOMATIC1111_BASE_URL="http://localhost:7860"
# For production, you should only need one host as

1
.webui_secret_key Normal file
View file

@ -0,0 +1 @@
6zYYvt9FjB3ylojBtc/ovl/cDtWLhQcm

View file

@ -357,6 +357,58 @@ except Exception:
OPENAI_API_BASE_URL = 'https://api.openai.com/v1'
####################################
# OPENAI_COMPATIBLE_PROVIDERS
####################################
# OpenAI-compatible providers Open WebUI ships the base URL for. Setting a provider's API key env
# var seeds a working connection on first start, so admins don't have to look the endpoint up and
# type it in. Each entry may be pointed elsewhere with its own base URL env var (self-hosted or
# regional deployments). Adding another provider is one entry here.
OPENAI_COMPATIBLE_PROVIDERS = {
'melious': {
'name': 'Melious',
'base_url': 'https://api.melious.ai/v1',
'key_env': 'MELIOUS_API_KEY',
'base_url_env': 'MELIOUS_API_BASE_URL',
},
}
def load_openai_compatible_providers(base_urls: list[str], keys: list[str], api_configs: dict) -> None:
"""Seed an OpenAI connection for every preconfigured provider whose API key env var is set.
Mutates the three lists/dicts in place. `base_urls` and `keys` are index-aligned, and
`api_configs` is keyed by that index, so keys are first normalized to the URL count the same
way `normalize_openai_api_keys` does. A base URL already present is left untouched, so an
explicit OPENAI_API_BASE_URLS entry always wins over the preset.
"""
if len(keys) > len(base_urls):
del keys[len(base_urls) :]
else:
keys.extend([''] * (len(base_urls) - len(keys)))
configured_urls = {url.rstrip('/') for url in base_urls}
for provider in OPENAI_COMPATIBLE_PROVIDERS.values():
key = os.getenv(provider['key_env'], '').strip()
if not key:
continue
base_url = (os.getenv(provider['base_url_env'], '').strip() or provider['base_url']).rstrip('/')
if base_url in configured_urls:
log.info('%s is already configured at %s, skipping preset', provider['name'], base_url)
continue
base_urls.append(base_url)
keys.append(key)
api_configs[str(len(base_urls) - 1)] = {'enable': True, 'connection_type': 'external'}
configured_urls.add(base_url)
load_openai_compatible_providers(OPENAI_API_BASE_URLS, OPENAI_API_KEYS, OPENAI_API_CONFIGS)
####################################
# MODELS
####################################

View file

@ -351,6 +351,7 @@
<option value="https://api.groq.com/openai/v1" />
<option value="https://openrouter.ai/api/v1" />
<option value="https://api.x.ai/v1" />
<option value="https://api.melious.ai/v1"></option>
</datalist>
{/if}
</div>