@@ -870,19 +870,17 @@ def stream(
870870 if not is_given (response_id ):
871871 raise ValueError ("id must be provided when streaming an existing response" )
872872
873- # TODO: get rid of the cast
874- r = self .retrieve (
875- response_id ,
876- stream = True ,
877- include = include or [],
878- extra_headers = extra_headers ,
879- extra_query = extra_query ,
880- extra_body = extra_body ,
881- starting_after = NOT_GIVEN ,
882- timeout = timeout ,
883- )
884873 return ResponseStreamManager (
885- lambda : cast (Stream [ResponseStreamEvent ], r ),
874+ lambda : self .retrieve (
875+ response_id = response_id ,
876+ stream = True ,
877+ include = include or [],
878+ extra_headers = extra_headers ,
879+ extra_query = extra_query ,
880+ extra_body = extra_body ,
881+ starting_after = NOT_GIVEN ,
882+ timeout = timeout ,
883+ ),
886884 text_format = text_format ,
887885 input_tools = tools ,
888886 starting_after = starting_after if is_given (starting_after ) else None ,
@@ -1000,7 +998,7 @@ def retrieve(
1000998 extra_query : Query | None = None ,
1001999 extra_body : Body | None = None ,
10021000 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
1003- ) -> Response | Stream [ResponseStreamEvent ]: ...
1001+ ) -> Stream [ResponseStreamEvent ]: ...
10041002
10051003 @overload
10061004 def retrieve (
@@ -1039,6 +1037,16 @@ def retrieve(
10391037 include: Additional fields to include in the response. See the `include` parameter for
10401038 Response creation above for more information.
10411039
1040+ stream: If set to true, the model response data will be streamed to the client using
1041+ [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
1042+ See the
1043+ [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
1044+ for more information.
1045+
1046+ starting_after: When retrieving a background response, this parameter can be used to start
1047+ replaying after an event with the given sequence number. Must be used in conjunction with
1048+ the `stream` parameter set to `true`.
1049+
10421050 extra_headers: Send extra headers
10431051
10441052 extra_query: Add additional query parameters to the request
@@ -1919,7 +1927,7 @@ def stream(
19191927
19201928 tools = _make_tools (tools )
19211929 if len (new_response_args_names ) > 0 :
1922- if not is_given (input ):
1930+ if isinstance (input , NotGiven ):
19231931 raise ValueError ("input must be provided when creating a new response" )
19241932
19251933 if not is_given (model ):
@@ -1966,7 +1974,7 @@ def stream(
19661974 starting_after = None ,
19671975 )
19681976 else :
1969- if not is_given (response_id ):
1977+ if isinstance (response_id , NotGiven ):
19701978 raise ValueError ("response_id must be provided when streaming an existing response" )
19711979
19721980 api_request = self .retrieve (
@@ -2097,7 +2105,7 @@ async def retrieve(
20972105 extra_query : Query | None = None ,
20982106 extra_body : Body | None = None ,
20992107 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
2100- ) -> Response | AsyncStream [ResponseStreamEvent ]: ...
2108+ ) -> AsyncStream [ResponseStreamEvent ]: ...
21012109
21022110 @overload
21032111 async def retrieve (
@@ -2136,6 +2144,10 @@ async def retrieve(
21362144 include: Additional fields to include in the response. See the `include` parameter for
21372145 Response creation above for more information.
21382146
2147+ stream:
2148+ starting_after: When retrieving a background response, this parameter can be used to start
2149+ replaying after an event with the given sequence number. Must be used in
2150+
21392151 extra_headers: Send extra headers
21402152
21412153 extra_query: Add additional query parameters to the request
0 commit comments