From 0710e0dd8baab0a192c77035ce08bb4e0b30530f Mon Sep 17 00:00:00 2001 From: SparkLabScout Date: Wed, 11 Mar 2026 16:38:16 +0800 Subject: [PATCH] fix: handle empty string in OPENAI_BASE_URL env var When OPENAI_BASE_URL is set to an empty string, the SDK should fall back to the default API endpoint instead of using the empty string as the base URL. Fixes issue #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..8aebdd8187 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -162,7 +162,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if base_url is None or base_url == "": base_url = f"https://api.openai.com/v1" super().__init__( @@ -537,7 +537,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if base_url is None or base_url == "": base_url = f"https://api.openai.com/v1" super().__init__(