Skip to content

fix(client): treat empty OPENAI_BASE_URL as unset#2952

Open
mvanhorn wants to merge 1 commit intoopenai:mainfrom
mvanhorn:osc/2927-empty-base-url-fallback
Open

fix(client): treat empty OPENAI_BASE_URL as unset#2952
mvanhorn wants to merge 1 commit intoopenai:mainfrom
mvanhorn:osc/2927-empty-base-url-fallback

Conversation

@mvanhorn
Copy link

Fixes #2927

Problem

When OPENAI_BASE_URL is set to an empty string (e.g., OPENAI_BASE_URL=""), os.environ.get("OPENAI_BASE_URL") returns "" instead of None. The subsequent if base_url is None check passes, so the client uses an empty string as the base URL instead of falling back to https://api.openai.com/v1.

Fix

Use or None to normalize empty strings to None, allowing the default fallback to trigger correctly. Applied to both OpenAI and AsyncOpenAI constructors.

Tests

Added test_base_url_env_empty_string for both sync and async clients, verifying that an empty OPENAI_BASE_URL falls back to the default endpoint.

This contribution was developed with AI assistance (Claude Code).

When OPENAI_BASE_URL is set to an empty string, os.environ.get()
returns "" instead of None, preventing the fallback to the default
API endpoint. Use `or None` to treat empty strings as missing.

Fixes openai#2927

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty OPENAI_BASE_URL prevents fallback to default API endpoint

1 participant