@@ -75,14 +75,16 @@ def test_reasoning_content_streamed_and_captured(self):
7575
7676 def test_streaming_default_sends_stream_true (self ):
7777 """The default mode is streaming: the request body must carry
78- stream=True unless the caller opts out ."""
78+ stream=True plus stream_options requesting usage chunks ."""
7979 fake_openai_server .reset_state ()
8080 c = make_client ()
8181 try :
8282 c .chat ([Message (role = "user" , content = "hi" )])
8383 finally :
8484 c .close ()
85- self .assertIs (fake_openai_server .REQUEST_BODIES [- 1 ]["stream" ], True )
85+ body = fake_openai_server .REQUEST_BODIES [- 1 ]
86+ self .assertIs (body ["stream" ], True )
87+ self .assertEqual (body ["stream_options" ], {"include_usage" : True })
8688
8789
8890class TestClientNonStreaming (unittest .TestCase ):
@@ -114,13 +116,16 @@ def test_sync_chat_returns_full_response(self):
114116
115117 def test_sync_chat_sends_stream_false (self ):
116118 """Non-streaming mode must send stream=False in the payload
117- (and not ask for text/event-stream)."""
119+ (and not ask for text/event-stream); stream_options must be
120+ absent since OpenAI-style backends reject it when not streaming."""
118121 c = make_client ()
119122 try :
120123 c .chat ([Message (role = "user" , content = "hi" )], stream = False )
121124 finally :
122125 c .close ()
123- self .assertIs (fake_openai_server .REQUEST_BODIES [- 1 ]["stream" ], False )
126+ body = fake_openai_server .REQUEST_BODIES [- 1 ]
127+ self .assertIs (body ["stream" ], False )
128+ self .assertNotIn ("stream_options" , body )
124129
125130 def test_sync_chat_tool_calls_and_reasoning (self ):
126131 """stream=False parses content, reasoning_content, tool_calls
0 commit comments