[PR #22093] [CLOSED] fix(config): RAG_OPENAI env vars now correctly inherit OPENAI_API values #42106

Closed
opened 2026-04-25 14:06:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22093
Author: @giulio-leone
Created: 3/1/2026
Status: Closed

Base: mainHead: fix/rag-openai-env-inheritance


📝 Commits (1)

  • 347e127 fix(config): RAG_OPENAI env vars now inherit from OPENAI_API env vars

📊 Changes

1 file changed (+6 additions, -2 deletions)

View changed files

📝 backend/open_webui/config.py (+6 -2)

📄 Description

Summary

Fixes #22084

RAG_OPENAI_API_BASE_URL and RAG_OPENAI_API_KEY are supposed to fall back to OPENAI_API_BASE_URL and OPENAI_API_KEY when not explicitly set. However, the fallback references Python variables that have already been reset to defaults earlier in config.py:

  • OPENAI_API_BASE_URL is reset to "https://api.openai.com/v1" (line 1144)
  • OPENAI_API_KEY is reset to "" (line 1134)

By the time the RAG config is defined (~line 3067), both variables contain default/empty values regardless of what the user set via environment variables.

Root Cause

config.py reassigns OPENAI_API_KEY and OPENAI_API_BASE_URL to extract the "official" OpenAI endpoint from the multi-provider arrays. This means the original user-supplied values are lost from the Python variables, even though they're still available in os.environ.

Fix

Read the original environment variables directly via os.environ.get() instead of referencing the already-reset Python variables:

# Before (broken): uses reset Python variables
os.getenv("RAG_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL)
os.getenv("RAG_OPENAI_API_KEY", OPENAI_API_KEY)

# After (fixed): reads original env vars directly
os.getenv("RAG_OPENAI_API_BASE_URL", 
          os.environ.get("OPENAI_API_BASE_URL", "").rstrip("/") or "https://api.openai.com/v1")
os.getenv("RAG_OPENAI_API_KEY", os.environ.get("OPENAI_API_KEY", ""))

Behavior

Scenario Before After
Only OPENAI_API_BASE_URL set Falls back to https://api.openai.com/v1 Inherits user value
Only OPENAI_API_KEY set Falls back to "" Inherits user value
Both RAG_OPENAI_* explicitly set Uses RAG values Uses RAG values
Nothing set Uses defaults Uses defaults

Testing

  • Verified Python syntax parses correctly
  • The fix is minimal (2 lines changed) and only affects the default value resolution for RAG OpenAI config

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22093 **Author:** [@giulio-leone](https://github.com/giulio-leone) **Created:** 3/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/rag-openai-env-inheritance` --- ### 📝 Commits (1) - [`347e127`](https://github.com/open-webui/open-webui/commit/347e12750225955ea02d4b88388f7a0269538cae) fix(config): RAG_OPENAI env vars now inherit from OPENAI_API env vars ### 📊 Changes **1 file changed** (+6 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/config.py` (+6 -2) </details> ### 📄 Description ## Summary Fixes #22084 `RAG_OPENAI_API_BASE_URL` and `RAG_OPENAI_API_KEY` are supposed to fall back to `OPENAI_API_BASE_URL` and `OPENAI_API_KEY` when not explicitly set. However, the fallback references Python variables that have already been **reset to defaults** earlier in `config.py`: - `OPENAI_API_BASE_URL` is reset to `"https://api.openai.com/v1"` (line 1144) - `OPENAI_API_KEY` is reset to `""` (line 1134) By the time the RAG config is defined (~line 3067), both variables contain default/empty values regardless of what the user set via environment variables. ## Root Cause `config.py` reassigns `OPENAI_API_KEY` and `OPENAI_API_BASE_URL` to extract the "official" OpenAI endpoint from the multi-provider arrays. This means the original user-supplied values are lost from the Python variables, even though they're still available in `os.environ`. ## Fix Read the original environment variables directly via `os.environ.get()` instead of referencing the already-reset Python variables: ```python # Before (broken): uses reset Python variables os.getenv("RAG_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL) os.getenv("RAG_OPENAI_API_KEY", OPENAI_API_KEY) # After (fixed): reads original env vars directly os.getenv("RAG_OPENAI_API_BASE_URL", os.environ.get("OPENAI_API_BASE_URL", "").rstrip("/") or "https://api.openai.com/v1") os.getenv("RAG_OPENAI_API_KEY", os.environ.get("OPENAI_API_KEY", "")) ``` ## Behavior | Scenario | Before | After | |---|---|---| | Only `OPENAI_API_BASE_URL` set | Falls back to `https://api.openai.com/v1` ❌ | Inherits user value ✅ | | Only `OPENAI_API_KEY` set | Falls back to `""` ❌ | Inherits user value ✅ | | Both `RAG_OPENAI_*` explicitly set | Uses RAG values ✅ | Uses RAG values ✅ | | Nothing set | Uses defaults ✅ | Uses defaults ✅ | ## Testing - Verified Python syntax parses correctly - The fix is minimal (2 lines changed) and only affects the default value resolution for RAG OpenAI config --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:06:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#42106