You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistent base_url behavior with module client and OpenAIClient #1373
Thanks for reporting, @dramdass. I'm not sure we'd prioritize a fix here, but we'd likely accept a contribution that updates the module client to match the non-module client.
Root cause._ModuleClient.base_url in src/openai/__init__.py overrides the getter and returns the module-level global after only _normalize_httpx_url():
With that change the module client produces https://example.com/api/v1/models, the same as OpenAI(...). The existing tests/test_module_client.py suite passes (32 tests). The Azure and Bedrock module clients inherit this getter, so they pick up the fix too. A regression test could assert openai.completions._client.base_url == URL("http://foo.com/api/v1/") after setting openai.base_url = "http://foo.com/api/v1". The existing test_base_url_option uses a URL with no path, which is why it doesn't catch this.
Activity
rattrayalex commentedon May 13, 2024
Thanks for reporting, @dramdass. I'm not sure we'd prioritize a fix here, but we'd likely accept a contribution that updates the module client to match the non-module client.
dramdass commentedon May 14, 2024
The right fix seems to be in
src/__init__.pybut the comment says# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.. I could't find a relevant place in the schema here https://github.com/openai/openai-openapi/tree/master to generate it. Can I add the fix manually intosrc/__init__.py?rattrayalex commentedon May 25, 2024
Yes, that would be the correct location.
Fix inconsistent base_url behavior in module client and OpenAIClient
fix(responses): correct reasoning output type (#1373)
mrutunjay-kinagi commentedon Sep 30, 2026
This still reproduces on current
main(3.22.1):Root cause.
_ModuleClient.base_urlinsrc/openai/__init__.pyoverrides the getter and returns the module-level global after only_normalize_httpx_url():BaseClientapplies_enforce_trailing_slash()in both__init__and thebase_urlsetter, but this override bypasses it wheneveropenai.base_urlis set.Suggested fix (one line):
With that change the module client produces
https://example.com/api/v1/models, the same asOpenAI(...). The existingtests/test_module_client.pysuite passes (32 tests). The Azure and Bedrock module clients inherit this getter, so they pick up the fix too. A regression test could assertopenai.completions._client.base_url == URL("http://foo.com/api/v1/")after settingopenai.base_url = "http://foo.com/api/v1". The existingtest_base_url_optionuses a URL with no path, which is why it doesn't catch this.cc @marcuswood-oai