Skip to content

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

Closed
mvanhorn wants to merge 1 commit into
openai:mainfrom
mvanhorn:osc/2927-empty-base-url-fallback
Closed

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

Conversation

@mvanhorn

Copy link
Copy Markdown

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 <[email protected]>
@marcuswood-oai

Copy link
Copy Markdown
Contributor

Thanks for taking the time to contribute! This fix needs to land upstream in our SDK generator so generated clients consistently include it. We’re tracking it in #2927, so I’m closing this PR in favor of the upstream fix.

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

2 participants