You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Empty OPENAI_BASE_URL prevents fallback to default API endpoint #2927
if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
if base_url is None:
base_url = f"https://api.openai.com/v1"
If the environment variable OPENAI_BASE_URL is defined but empty (e.g., OPENAI_BASE_URL=""), then os.environ.get("OPENAI_BASE_URL") returns an empty string. As a result:
base_url becomes ""
the second condition (if base_url is None) is never triggered
...uses is None for both checks, but os.environ.get() returns an empty string '' (not None) when the variable is set but empty. Empty string is falsy but not None, so the fallback never triggers.
The fix should be:
ifbase_urlisNone:
base_url=os.environ.get('OPENAI_BASE_URL') orNone# converts '' to Noneifbase_urlisNone:
base_url='https://api.openai.com/v1'
Workaround: Unset the environment variable entirely (unset OPENAI_BASE_URL or del os.environ['OPENAI_BASE_URL']) rather than setting it to an empty string. The bug only triggers when OPENAI_BASE_URL is defined but empty — if it's not set at all, os.environ.get() returns None and the fallback works correctly.
This is addressed by #2939 — when OPENAI_BASE_URL is set to an empty string, it now falls back to the default API endpoint instead of constructing an invalid URL.
The change only touches the environment fallback path: if OPENAI_BASE_URL is set to an empty string, the client now treats it the same as an unset value and falls back to the default API base URL. Explicit base_url arguments are left alone. I also added sync and async regressions for the empty-env case.
Activity
fix: treat empty OPENAI_BASE_URL as unset
fix: treat empty OPENAI_BASE_URL env var as unset
xXMrNidaXx commentedon Mar 8, 2026
Good catch on the empty string edge case. The current logic:
...uses
is Nonefor both checks, butos.environ.get()returns an empty string''(notNone) when the variable is set but empty. Empty string is falsy but notNone, so the fallback never triggers.The fix should be:
Or equivalently:
Workaround: Unset the environment variable entirely (
unset OPENAI_BASE_URLordel os.environ['OPENAI_BASE_URL']) rather than setting it to an empty string. The bug only triggers whenOPENAI_BASE_URLis defined but empty — if it's not set at all,os.environ.get()returnsNoneand the fallback works correctly.giulio-leone commentedon Mar 9, 2026
This is addressed by #2939 — when
OPENAI_BASE_URLis set to an empty string, it now falls back to the default API endpoint instead of constructing an invalid URL.fix(client): treat empty OPENAI_BASE_URL as unset
mvanhorn commentedon Mar 10, 2026
I've submitted a fix for this in PR #2952. Uses
or Noneto normalize empty env var strings, applied to both sync and async constructors.passionworkeer commentedon Mar 14, 2026
This is a simple fix! I can submit a PR to handle the empty string case for OPENAI_BASE_URL.
fix(client): treat empty OPENAI_BASE_URL env var as unset
fix(client): treat empty OPENAI_BASE_URL as unset and fall back to de…
theamodhshetty commentedon Mar 19, 2026
Opened #2988 for this.
The change only touches the environment fallback path: if
OPENAI_BASE_URLis set to an empty string, the client now treats it the same as an unset value and falls back to the default API base URL. Explicitbase_urlarguments are left alone. I also added sync and async regressions for the empty-env case.fix(client): treat empty OPENAI_BASE_URL as unset, falling back to de…
fix: treat empty OPENAI_BASE_URL same as None for default fallback
fix: treat empty OPENAI_BASE_URL env var as unset to restore default …
fix: treat empty OPENAI_BASE_URL env var as unset, fall back to default
khalidsaidi commentedon Mar 25, 2026
A2ABench has an accepted answer for this imported thread.
ai villagefix: handle empty OPENAI_BASE_URL fallback to default endpoint (fixes o…