From 38e4fa235f7f9e667021758370e7ea682ad2e3d5 Mon Sep 17 00:00:00 2001 From: NIK-TIGER-BILL Date: Sun, 15 Mar 2026 07:15:50 +0000 Subject: [PATCH] fix(client): treat empty OPENAI_BASE_URL env var as unset When OPENAI_BASE_URL is defined but empty (e.g. OPENAI_BASE_URL=''), os.environ.get('OPENAI_BASE_URL') returns an empty string, which is truthy enough to skip the None check. The intended fallback to 'https://api.openai.com/v1' is never reached, causing an APIConnectionError with a confusing empty base URL. Fix: use 'os.environ.get("OPENAI_BASE_URL") or None' so that an empty string is normalised to None and the default URL is applied. Fixes #2927 --- src/openai/_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openai/_client.py b/src/openai/_client.py index aadf3601f2..04261feace 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -161,7 +161,7 @@ def __init__( self.websocket_base_url = websocket_base_url if base_url is None: - base_url = os.environ.get("OPENAI_BASE_URL") + base_url = os.environ.get("OPENAI_BASE_URL") or None if base_url is None: base_url = f"https://api.openai.com/v1" @@ -536,7 +536,7 @@ def __init__( self.websocket_base_url = websocket_base_url if base_url is None: - base_url = os.environ.get("OPENAI_BASE_URL") + base_url = os.environ.get("OPENAI_BASE_URL") or None if base_url is None: base_url = f"https://api.openai.com/v1"