From 416ce551fd5dc6c11391e18e6974d43d2c5aff15 Mon Sep 17 00:00:00 2001 From: NIK-TIGER-BILL Date: Tue, 17 Mar 2026 07:06:27 +0000 Subject: [PATCH] fix(client): treat empty OPENAI_BASE_URL as unset and fall back to default When OPENAI_BASE_URL is set to an empty string, os.environ.get() returns "" which is falsy but not None, so the second `if base_url is None` check never fires and the default API URL is never used. Using `or None` converts empty strings to None, allowing the fallback to proceed correctly. 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"