Skip to content

Commit 4105376

Browse files
feat(api): Support images and files for function call outputs in responses, BatchUsage
This release introduces a major version change to reflect a breaking modification in the `ResponseFunctionToolCallOutputItem` and `ResponseCustomToolCallOutput` schemas. Specifically, the `output` field, which previously accepted only a `string` value, has been expanded to support multiple structured types: ``` Before: output: string After: output: string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile> ``` This change allows custom tool calls to return images, files, and rich text content in addition to plain strings, aligning `ResponseCustomToolCallOutput` with the broader `ResponseInput` type system. Because this alters the type and shape of the field, it may break existing callsites that only accept strings. BREAKING CHANGE: `ResponseFunctionToolCallOutputItem.output` and `ResponseCustomToolCallOutput.output` now return `string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>` instead of `string` only. This may break existing callsites that assume `output` is always a string.
1 parent a1493f9 commit 4105376

23 files changed

+332
-24
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-410219ea680089f02bb55163c673919703f946c3d6ad7ff5d6f607121d5287d5.yml
3-
openapi_spec_hash: 2b3eee95d3f6796c7a61dfddf694a59a
4-
config_hash: 666d6bb4b564f0d9d431124b5d1a0665
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-49233088b5e73dbb96bf7af27be3d4547632e3db1c2b00f14184900613325bbc.yml
3+
openapi_spec_hash: b34f14b141d5019244112901c5c7c2d8
4+
config_hash: 94e9ba08201c3d1ca46e093e6a0138fa

api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ Methods:
687687
Types:
688688

689689
```python
690-
from openai.types import Batch, BatchError, BatchRequestCounts
690+
from openai.types import Batch, BatchError, BatchRequestCounts, BatchUsage
691691
```
692692

693693
Methods:
@@ -769,6 +769,8 @@ from openai.types.responses import (
769769
ResponseFormatTextJSONSchemaConfig,
770770
ResponseFunctionCallArgumentsDeltaEvent,
771771
ResponseFunctionCallArgumentsDoneEvent,
772+
ResponseFunctionCallOutputItem,
773+
ResponseFunctionCallOutputItemList,
772774
ResponseFunctionToolCall,
773775
ResponseFunctionToolCallItem,
774776
ResponseFunctionToolCallOutputItem,
@@ -784,11 +786,14 @@ from openai.types.responses import (
784786
ResponseInputAudio,
785787
ResponseInputContent,
786788
ResponseInputFile,
789+
ResponseInputFileContent,
787790
ResponseInputImage,
791+
ResponseInputImageContent,
788792
ResponseInputItem,
789793
ResponseInputMessageContentList,
790794
ResponseInputMessageItem,
791795
ResponseInputText,
796+
ResponseInputTextContent,
792797
ResponseItem,
793798
ResponseMcpCallArgumentsDeltaEvent,
794799
ResponseMcpCallArgumentsDoneEvent,

src/openai/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from .moderation import Moderation as Moderation
3232
from .audio_model import AudioModel as AudioModel
3333
from .batch_error import BatchError as BatchError
34+
from .batch_usage import BatchUsage as BatchUsage
3435
from .file_object import FileObject as FileObject
3536
from .image_model import ImageModel as ImageModel
3637
from .file_content import FileContent as FileContent

src/openai/types/batch.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .._models import BaseModel
77
from .batch_error import BatchError
8+
from .batch_usage import BatchUsage
89
from .shared.metadata import Metadata
910
from .batch_request_counts import BatchRequestCounts
1011

@@ -80,8 +81,24 @@ class Batch(BaseModel):
8081
a maximum length of 512 characters.
8182
"""
8283

84+
model: Optional[str] = None
85+
"""Model ID used to process the batch, like `gpt-5-2025-08-07`.
86+
87+
OpenAI offers a wide range of models with different capabilities, performance
88+
characteristics, and price points. Refer to the
89+
[model guide](https://platform.openai.com/docs/models) to browse and compare
90+
available models.
91+
"""
92+
8393
output_file_id: Optional[str] = None
8494
"""The ID of the file containing the outputs of successfully executed requests."""
8595

8696
request_counts: Optional[BatchRequestCounts] = None
8797
"""The request counts for different statuses within the batch."""
98+
99+
usage: Optional[BatchUsage] = None
100+
"""
101+
Represents token usage details including input tokens, output tokens, a
102+
breakdown of output tokens, and the total tokens used. Only populated on batches
103+
created after September 7, 2025.
104+
"""

src/openai/types/batch_usage.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from .._models import BaseModel
4+
5+
__all__ = ["BatchUsage", "InputTokensDetails", "OutputTokensDetails"]
6+
7+
8+
class InputTokensDetails(BaseModel):
9+
cached_tokens: int
10+
"""The number of tokens that were retrieved from the cache.
11+
12+
[More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
13+
"""
14+
15+
16+
class OutputTokensDetails(BaseModel):
17+
reasoning_tokens: int
18+
"""The number of reasoning tokens."""
19+
20+
21+
class BatchUsage(BaseModel):
22+
input_tokens: int
23+
"""The number of input tokens."""
24+
25+
input_tokens_details: InputTokensDetails
26+
"""A detailed breakdown of the input tokens."""
27+
28+
output_tokens: int
29+
"""The number of output tokens."""
30+
31+
output_tokens_details: OutputTokensDetails
32+
"""A detailed breakdown of the output tokens."""
33+
34+
total_tokens: int
35+
"""The total number of tokens used."""

src/openai/types/responses/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@
8585
from .response_conversation_param import ResponseConversationParam as ResponseConversationParam
8686
from .response_format_text_config import ResponseFormatTextConfig as ResponseFormatTextConfig
8787
from .response_function_tool_call import ResponseFunctionToolCall as ResponseFunctionToolCall
88+
from .response_input_file_content import ResponseInputFileContent as ResponseInputFileContent
8889
from .response_input_message_item import ResponseInputMessageItem as ResponseInputMessageItem
90+
from .response_input_text_content import ResponseInputTextContent as ResponseInputTextContent
8991
from .response_refusal_done_event import ResponseRefusalDoneEvent as ResponseRefusalDoneEvent
9092
from .response_function_web_search import ResponseFunctionWebSearch as ResponseFunctionWebSearch
9193
from .response_input_content_param import ResponseInputContentParam as ResponseInputContentParam
94+
from .response_input_image_content import ResponseInputImageContent as ResponseInputImageContent
9295
from .response_refusal_delta_event import ResponseRefusalDeltaEvent as ResponseRefusalDeltaEvent
9396
from .response_output_message_param import ResponseOutputMessageParam as ResponseOutputMessageParam
9497
from .response_output_refusal_param import ResponseOutputRefusalParam as ResponseOutputRefusalParam
@@ -106,8 +109,12 @@
106109
from .response_content_part_added_event import ResponseContentPartAddedEvent as ResponseContentPartAddedEvent
107110
from .response_format_text_config_param import ResponseFormatTextConfigParam as ResponseFormatTextConfigParam
108111
from .response_function_tool_call_param import ResponseFunctionToolCallParam as ResponseFunctionToolCallParam
112+
from .response_input_file_content_param import ResponseInputFileContentParam as ResponseInputFileContentParam
113+
from .response_input_text_content_param import ResponseInputTextContentParam as ResponseInputTextContentParam
109114
from .response_mcp_call_completed_event import ResponseMcpCallCompletedEvent as ResponseMcpCallCompletedEvent
115+
from .response_function_call_output_item import ResponseFunctionCallOutputItem as ResponseFunctionCallOutputItem
110116
from .response_function_web_search_param import ResponseFunctionWebSearchParam as ResponseFunctionWebSearchParam
117+
from .response_input_image_content_param import ResponseInputImageContentParam as ResponseInputImageContentParam
111118
from .response_reasoning_text_done_event import ResponseReasoningTextDoneEvent as ResponseReasoningTextDoneEvent
112119
from .response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall as ResponseCodeInterpreterToolCall
113120
from .response_input_message_content_list import ResponseInputMessageContentList as ResponseInputMessageContentList
@@ -131,6 +138,9 @@
131138
from .response_format_text_json_schema_config import (
132139
ResponseFormatTextJSONSchemaConfig as ResponseFormatTextJSONSchemaConfig,
133140
)
141+
from .response_function_call_output_item_list import (
142+
ResponseFunctionCallOutputItemList as ResponseFunctionCallOutputItemList,
143+
)
134144
from .response_function_tool_call_output_item import (
135145
ResponseFunctionToolCallOutputItem as ResponseFunctionToolCallOutputItem,
136146
)
@@ -143,6 +153,9 @@
143153
from .response_mcp_list_tools_completed_event import (
144154
ResponseMcpListToolsCompletedEvent as ResponseMcpListToolsCompletedEvent,
145155
)
156+
from .response_function_call_output_item_param import (
157+
ResponseFunctionCallOutputItemParam as ResponseFunctionCallOutputItemParam,
158+
)
146159
from .response_image_gen_call_generating_event import (
147160
ResponseImageGenCallGeneratingEvent as ResponseImageGenCallGeneratingEvent,
148161
)
@@ -212,6 +225,9 @@
212225
from .response_format_text_json_schema_config_param import (
213226
ResponseFormatTextJSONSchemaConfigParam as ResponseFormatTextJSONSchemaConfigParam,
214227
)
228+
from .response_function_call_output_item_list_param import (
229+
ResponseFunctionCallOutputItemListParam as ResponseFunctionCallOutputItemListParam,
230+
)
215231
from .response_code_interpreter_call_code_done_event import (
216232
ResponseCodeInterpreterCallCodeDoneEvent as ResponseCodeInterpreterCallCodeDoneEvent,
217233
)

src/openai/types/responses/response_custom_tool_call_output.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import Optional
4-
from typing_extensions import Literal
3+
from typing import List, Union, Optional
4+
from typing_extensions import Literal, Annotated, TypeAlias
55

6+
from ..._utils import PropertyInfo
67
from ..._models import BaseModel
8+
from .response_input_file import ResponseInputFile
9+
from .response_input_text import ResponseInputText
10+
from .response_input_image import ResponseInputImage
711

8-
__all__ = ["ResponseCustomToolCallOutput"]
12+
__all__ = ["ResponseCustomToolCallOutput", "OutputOutputContentList"]
13+
14+
OutputOutputContentList: TypeAlias = Annotated[
15+
Union[ResponseInputText, ResponseInputImage, ResponseInputFile], PropertyInfo(discriminator="type")
16+
]
917

1018

1119
class ResponseCustomToolCallOutput(BaseModel):
1220
call_id: str
1321
"""The call ID, used to map this custom tool call output to a custom tool call."""
1422

15-
output: str
16-
"""The output from the custom tool call generated by your code."""
23+
output: Union[str, List[OutputOutputContentList]]
24+
"""
25+
The output from the custom tool call generated by your code. Can be a string or
26+
an list of output content.
27+
"""
1728

1829
type: Literal["custom_tool_call_output"]
1930
"""The type of the custom tool call output. Always `custom_tool_call_output`."""

src/openai/types/responses/response_custom_tool_call_output_param.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22

33
from __future__ import annotations
44

5-
from typing_extensions import Literal, Required, TypedDict
5+
from typing import Union, Iterable
6+
from typing_extensions import Literal, Required, TypeAlias, TypedDict
67

7-
__all__ = ["ResponseCustomToolCallOutputParam"]
8+
from .response_input_file_param import ResponseInputFileParam
9+
from .response_input_text_param import ResponseInputTextParam
10+
from .response_input_image_param import ResponseInputImageParam
11+
12+
__all__ = ["ResponseCustomToolCallOutputParam", "OutputOutputContentList"]
13+
14+
OutputOutputContentList: TypeAlias = Union[ResponseInputTextParam, ResponseInputImageParam, ResponseInputFileParam]
815

916

1017
class ResponseCustomToolCallOutputParam(TypedDict, total=False):
1118
call_id: Required[str]
1219
"""The call ID, used to map this custom tool call output to a custom tool call."""
1320

14-
output: Required[str]
15-
"""The output from the custom tool call generated by your code."""
21+
output: Required[Union[str, Iterable[OutputOutputContentList]]]
22+
"""
23+
The output from the custom tool call generated by your code. Can be a string or
24+
an list of output content.
25+
"""
1626

1727
type: Required[Literal["custom_tool_call_output"]]
1828
"""The type of the custom tool call output. Always `custom_tool_call_output`."""

src/openai/types/responses/response_function_call_arguments_done_event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class ResponseFunctionCallArgumentsDoneEvent(BaseModel):
1414
item_id: str
1515
"""The ID of the item."""
1616

17+
name: str
18+
"""The name of the function that was called."""
19+
1720
output_index: int
1821
"""The index of the output item."""
1922

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import Union
4+
from typing_extensions import Annotated, TypeAlias
5+
6+
from ..._utils import PropertyInfo
7+
from .response_input_file_content import ResponseInputFileContent
8+
from .response_input_text_content import ResponseInputTextContent
9+
from .response_input_image_content import ResponseInputImageContent
10+
11+
__all__ = ["ResponseFunctionCallOutputItem"]
12+
13+
ResponseFunctionCallOutputItem: TypeAlias = Annotated[
14+
Union[ResponseInputTextContent, ResponseInputImageContent, ResponseInputFileContent],
15+
PropertyInfo(discriminator="type"),
16+
]

0 commit comments

Comments
 (0)