From 44b0775461859628b7c58fcde4284ed7a9c0c521 Mon Sep 17 00:00:00 2001 From: Rishab Motgi Date: Tue, 19 May 2026 11:10:22 -0700 Subject: [PATCH] fix(client): treat empty OPENAI_BASE_URL env var as unset os.environ.get("OPENAI_BASE_URL") returns "" when the variable is set but blank. The subsequent 'if base_url is None' check then skips the default fallback, passing an empty string to httpx which raises APIConnectionError. Change to 'if not base_url' to treat both None and empty string as absent, falling back to the default API endpoint. 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 499a62dfe5..c9459c101f 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -211,7 +211,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if not base_url: base_url = f"https://api.openai.com/v1" custom_headers_env = os.environ.get("OPENAI_CUSTOM_HEADERS") @@ -717,7 +717,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if not base_url: base_url = f"https://api.openai.com/v1" custom_headers_env = os.environ.get("OPENAI_CUSTOM_HEADERS")