Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(

if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
if base_url is None:
if base_url is None or base_url == "":
base_url = f"https://api.openai.com/v1"

super().__init__(
Expand Down Expand Up @@ -537,7 +537,7 @@ def __init__(

if base_url is None:
base_url = os.environ.get("OPENAI_BASE_URL")
if base_url is None:
if base_url is None or base_url == "":
base_url = f"https://api.openai.com/v1"

super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def model_dump(
exclude_defaults=exclude_defaults,
# warnings are not supported in Pydantic v1
warnings=True if PYDANTIC_V1 else warnings,
by_alias=by_alias,
by_alias=bool(by_alias) if by_alias is not None else True,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep by_alias default false in compat model_dump

Converting by_alias=None to True here changes the meaning of every model_dump(...) call site that omits by_alias (for example _utils/_transform.py and debug serialization in _base_client.py), because pydantic v2 now always serializes aliases instead of field names; this diverges from the v1 branch in the same function (bool(by_alias) => False for None) and from the SDK’s own BaseModel.model_dump() default behavior. For models with aliased fields, this silently changes emitted keys and can break request/data transformations that expect Python field names.

Useful? React with 👍 / 👎.

)
return cast(
"dict[str, Any]",
Expand Down