From 3717560208280b8a2f92901982e8713b9ed1a178 Mon Sep 17 00:00:00 2001 From: NIK-TIGER-BILL Date: Fri, 20 Mar 2026 07:04:30 +0000 Subject: [PATCH] fix(client): treat empty OPENAI_BASE_URL as unset, falling back to default endpoint When OPENAI_BASE_URL is set to an empty string, os.environ.get() returns '' which is falsy but not None, causing the second None-check to be skipped. This means an empty string is passed as base_url, leading to confusing errors. Using ensures that both unset and empty string values are treated identically, falling back to the default https://api.openai.com/v1 endpoint. Closes #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"