Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.99.3"
".": "1.99.4"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 111
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-f5c45f4ae5c2075cbc603d6910bba3da31c23714c209fbd3fd82a94f634a126b.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-56d3a72a5caa187aebcf9de169a6a28a9dc3f70a79d7467a03a9e22595936066.yml
openapi_spec_hash: 3eb8d86c06f0bb5e1190983e5acfc9ba
config_hash: e53ea2d984c4e05a57eb0227fa379b2b
config_hash: 7e18239879286d68a48ac5487a649aa6
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.99.4 (2025-08-08)

Full Changelog: [v1.99.3...v1.99.4](https://github.com/openai/openai-python/compare/v1.99.3...v1.99.4)

### Bug Fixes

* **types:** rename chat completion tool ([8d3bf88](https://github.com/openai/openai-python/commit/8d3bf88f5bc11cf30b8b050c24b2cc5a3807614f))
* **types:** revert ChatCompletionToolParam to a TypedDict ([3f4ae72](https://github.com/openai/openai-python/commit/3f4ae725af53e631ddc128c1c6862ecf0b08e073))

## 1.99.3 (2025-08-07)

Full Changelog: [v1.99.2...v1.99.3](https://github.com/openai/openai-python/compare/v1.99.2...v1.99.3)
Expand Down
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ from openai.types.chat import (
ChatCompletionStreamOptions,
ChatCompletionSystemMessageParam,
ChatCompletionTokenLogprob,
ChatCompletionTool,
ChatCompletionToolUnion,
ChatCompletionToolChoiceOption,
ChatCompletionToolMessageParam,
ChatCompletionUserMessageParam,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai"
version = "1.99.3"
version = "1.99.4"
description = "The official Python library for the openai API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/openai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "openai"
__version__ = "1.99.3" # x-release-please-version
__version__ = "1.99.4" # x-release-please-version
18 changes: 9 additions & 9 deletions src/openai/lib/_parsing/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
ChatCompletionMessage,
ParsedFunctionToolCall,
ParsedChatCompletionMessage,
ChatCompletionToolUnionParam,
ChatCompletionFunctionToolParam,
completion_create_params,
)
from ..._exceptions import LengthFinishReasonError, ContentFilterFinishReasonError
from ...types.shared_params import FunctionDefinition
from ...types.chat.completion_create_params import ResponseFormat as ResponseFormatParam
from ...types.chat.chat_completion_tool_param import ChatCompletionToolParam
from ...types.chat.chat_completion_message_function_tool_call import Function

ResponseFormatT = TypeVar(
Expand All @@ -41,7 +41,7 @@


def is_strict_chat_completion_tool_param(
tool: ChatCompletionToolParam,
tool: ChatCompletionToolUnionParam,
) -> TypeGuard[ChatCompletionFunctionToolParam]:
"""Check if the given tool is a strict ChatCompletionFunctionToolParam."""
if not tool["type"] == "function":
Expand All @@ -53,7 +53,7 @@ def is_strict_chat_completion_tool_param(


def select_strict_chat_completion_tools(
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
) -> Iterable[ChatCompletionFunctionToolParam] | NotGiven:
"""Select only the strict ChatCompletionFunctionToolParams from the given tools."""
if not is_given(tools):
Expand All @@ -63,7 +63,7 @@ def select_strict_chat_completion_tools(


def validate_input_tools(
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
) -> Iterable[ChatCompletionFunctionToolParam] | NotGiven:
if not is_given(tools):
return NOT_GIVEN
Expand All @@ -86,7 +86,7 @@ def validate_input_tools(
def parse_chat_completion(
*,
response_format: type[ResponseFormatT] | completion_create_params.ResponseFormat | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
chat_completion: ChatCompletion | ParsedChatCompletion[object],
) -> ParsedChatCompletion[ResponseFormatT]:
if is_given(input_tools):
Expand Down Expand Up @@ -166,13 +166,13 @@ def parse_chat_completion(


def get_input_tool_by_name(
*, input_tools: list[ChatCompletionToolParam], name: str
*, input_tools: list[ChatCompletionToolUnionParam], name: str
) -> ChatCompletionFunctionToolParam | None:
return next((t for t in input_tools if t["type"] == "function" and t.get("function", {}).get("name") == name), None)


def parse_function_tool_arguments(
*, input_tools: list[ChatCompletionToolParam], function: Function | ParsedFunction
*, input_tools: list[ChatCompletionToolUnionParam], function: Function | ParsedFunction
) -> object | None:
input_tool = get_input_tool_by_name(input_tools=input_tools, name=function.name)
if not input_tool:
Expand Down Expand Up @@ -218,7 +218,7 @@ def solve_response_format_t(
def has_parseable_input(
*,
response_format: type | ResponseFormatParam | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
) -> bool:
if has_rich_response_format(response_format):
return True
Expand Down Expand Up @@ -246,7 +246,7 @@ def is_response_format_param(response_format: object) -> TypeGuard[ResponseForma
return is_dict(response_format)


def is_parseable_tool(input_tool: ChatCompletionToolParam) -> bool:
def is_parseable_tool(input_tool: ChatCompletionToolUnionParam) -> bool:
if input_tool["type"] != "function":
return False

Expand Down
15 changes: 7 additions & 8 deletions src/openai/lib/streaming/chat/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
parse_function_tool_arguments,
)
from ...._streaming import Stream, AsyncStream
from ....types.chat import ChatCompletionChunk, ParsedChatCompletion
from ....types.chat import ChatCompletionChunk, ParsedChatCompletion, ChatCompletionToolUnionParam
from ...._exceptions import LengthFinishReasonError, ContentFilterFinishReasonError
from ....types.chat.chat_completion import ChoiceLogprobs
from ....types.chat.chat_completion_chunk import Choice as ChoiceChunk
from ....types.chat.completion_create_params import ResponseFormat as ResponseFormatParam
from ....types.chat.chat_completion_tool_param import ChatCompletionToolParam


class ChatCompletionStream(Generic[ResponseFormatT]):
Expand All @@ -59,7 +58,7 @@ def __init__(
*,
raw_stream: Stream[ChatCompletionChunk],
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
) -> None:
self._raw_stream = raw_stream
self._response = raw_stream.response
Expand Down Expand Up @@ -140,7 +139,7 @@ def __init__(
api_request: Callable[[], Stream[ChatCompletionChunk]],
*,
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
) -> None:
self.__stream: ChatCompletionStream[ResponseFormatT] | None = None
self.__api_request = api_request
Expand Down Expand Up @@ -182,7 +181,7 @@ def __init__(
*,
raw_stream: AsyncStream[ChatCompletionChunk],
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
) -> None:
self._raw_stream = raw_stream
self._response = raw_stream.response
Expand Down Expand Up @@ -263,7 +262,7 @@ def __init__(
api_request: Awaitable[AsyncStream[ChatCompletionChunk]],
*,
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
) -> None:
self.__stream: AsyncChatCompletionStream[ResponseFormatT] | None = None
self.__api_request = api_request
Expand Down Expand Up @@ -315,7 +314,7 @@ class ChatCompletionStreamState(Generic[ResponseFormatT]):
def __init__(
self,
*,
input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven = NOT_GIVEN,
) -> None:
self.__current_completion_snapshot: ParsedChatCompletionSnapshot | None = None
Expand Down Expand Up @@ -585,7 +584,7 @@ def _build_events(


class ChoiceEventState:
def __init__(self, *, input_tools: list[ChatCompletionToolParam]) -> None:
def __init__(self, *, input_tools: list[ChatCompletionToolUnionParam]) -> None:
self._input_tools = input_tools

self._content_done = False
Expand Down
26 changes: 13 additions & 13 deletions src/openai/resources/chat/completions/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
from ....types.chat.chat_completion_chunk import ChatCompletionChunk
from ....types.chat.parsed_chat_completion import ParsedChatCompletion
from ....types.chat.chat_completion_deleted import ChatCompletionDeleted
from ....types.chat.chat_completion_tool_param import ChatCompletionToolParam
from ....types.chat.chat_completion_audio_param import ChatCompletionAudioParam
from ....types.chat.chat_completion_message_param import ChatCompletionMessageParam
from ....types.chat.chat_completion_tool_union_param import ChatCompletionToolUnionParam
from ....types.chat.chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
from ....types.chat.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
from ....types.chat.chat_completion_tool_choice_option_param import ChatCompletionToolChoiceOptionParam
Expand Down Expand Up @@ -111,7 +111,7 @@ def parse(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -266,7 +266,7 @@ def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -555,7 +555,7 @@ def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -844,7 +844,7 @@ def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1408,7 +1408,7 @@ def stream(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ async def parse(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1705,7 +1705,7 @@ async def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1994,7 +1994,7 @@ async def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -2283,7 +2283,7 @@ async def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -2572,7 +2572,7 @@ async def create(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -2847,7 +2847,7 @@ def stream(
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
temperature: Optional[float] | NotGiven = NOT_GIVEN,
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
top_p: Optional[float] | NotGiven = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
Expand Down
1 change: 1 addition & 0 deletions src/openai/types/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .chat_completion_store_message import ChatCompletionStoreMessage as ChatCompletionStoreMessage
from .chat_completion_token_logprob import ChatCompletionTokenLogprob as ChatCompletionTokenLogprob
from .chat_completion_reasoning_effort import ChatCompletionReasoningEffort as ChatCompletionReasoningEffort
from .chat_completion_tool_union_param import ChatCompletionToolUnionParam as ChatCompletionToolUnionParam
from .chat_completion_content_part_text import ChatCompletionContentPartText as ChatCompletionContentPartText
from .chat_completion_custom_tool_param import ChatCompletionCustomToolParam as ChatCompletionCustomToolParam
from .chat_completion_message_tool_call import ChatCompletionMessageToolCall as ChatCompletionMessageToolCall
Expand Down
4 changes: 1 addition & 3 deletions src/openai/types/chat/chat_completion_tool_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from __future__ import annotations

from typing import Union
from typing_extensions import TypeAlias

from .chat_completion_custom_tool_param import ChatCompletionCustomToolParam
from .chat_completion_function_tool_param import ChatCompletionFunctionToolParam

__all__ = ["ChatCompletionToolParam"]

ChatCompletionToolParam: TypeAlias = Union[ChatCompletionFunctionToolParam, ChatCompletionCustomToolParam]
ChatCompletionToolParam: TypeAlias = ChatCompletionFunctionToolParam
13 changes: 13 additions & 0 deletions src/openai/types/chat/chat_completion_tool_union_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Union
from typing_extensions import TypeAlias

from .chat_completion_custom_tool_param import ChatCompletionCustomToolParam
from .chat_completion_function_tool_param import ChatCompletionFunctionToolParam

__all__ = ["ChatCompletionToolUnionParam"]

ChatCompletionToolUnionParam: TypeAlias = Union[ChatCompletionFunctionToolParam, ChatCompletionCustomToolParam]
4 changes: 2 additions & 2 deletions src/openai/types/chat/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from ..shared.chat_model import ChatModel
from ..shared_params.metadata import Metadata
from ..shared.reasoning_effort import ReasoningEffort
from .chat_completion_tool_param import ChatCompletionToolParam
from .chat_completion_audio_param import ChatCompletionAudioParam
from .chat_completion_message_param import ChatCompletionMessageParam
from .chat_completion_tool_union_param import ChatCompletionToolUnionParam
from ..shared_params.function_parameters import FunctionParameters
from ..shared_params.response_format_text import ResponseFormatText
from .chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
Expand Down Expand Up @@ -284,7 +284,7 @@ class CompletionCreateParamsBase(TypedDict, total=False):
are present.
"""

tools: Iterable[ChatCompletionToolParam]
tools: Iterable[ChatCompletionToolUnionParam]
"""A list of tools the model may call.

You can provide either
Expand Down
8 changes: 8 additions & 0 deletions tests/compat/test_tool_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from openai.types.chat import ChatCompletionToolParam


def test_tool_param_can_be_instantiated() -> None:
assert ChatCompletionToolParam(type="function", function={"name": "test"}) == {
"function": {"name": "test"},
"type": "function",
}