Skip to content

Commit a04ba6e

Browse files
test(openai-agents): Set streaming header when library uses with_streaming_response() (#5583)
A new `openai` function is called in version 0.10.3 of `openai-agents`, which sets a header in the `httpx.Request` object used to call a model. Add the header to the `httpx.Request` object to mirror the `httpx.Request` object constructed in the call paths of `openai-agents`.
1 parent add1f75 commit a04ba6e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,15 @@ async def test_hosted_mcp_tool_propagation_header_streamed(
14251425
"/responses",
14261426
)
14271427

1428+
# openai-agents calls with_streaming_response() if available starting with
1429+
# https://github.com/openai/openai-agents-python/commit/159beb56130f7d85192acfd593c9168757984dc0.
1430+
# When using with_streaming_response() the header set below changes the response type:
1431+
# https://github.com/openai/openai-python/blob/656e3cab4a18262a49b961d41293367e45ee71b9/src/openai/_response.py#L67.
1432+
if parse_version(OPENAI_AGENTS_VERSION) >= (0, 10, 3) and hasattr(
1433+
agent_with_tool.model._client.responses, "with_streaming_response"
1434+
):
1435+
request.headers["X-Stainless-Raw-Response"] = "stream"
1436+
14281437
response = httpx.Response(
14291438
200,
14301439
request=request,
@@ -3178,6 +3187,15 @@ async def test_streaming_ttft_on_chat_span(sentry_init, test_agent, async_iterat
31783187
"/responses",
31793188
)
31803189

3190+
# openai-agents calls with_streaming_response() if available starting with
3191+
# https://github.com/openai/openai-agents-python/commit/159beb56130f7d85192acfd593c9168757984dc0.
3192+
# When using with_streaming_response() the header set below changes the response type:
3193+
# https://github.com/openai/openai-python/blob/656e3cab4a18262a49b961d41293367e45ee71b9/src/openai/_response.py#L67.
3194+
if parse_version(OPENAI_AGENTS_VERSION) >= (0, 10, 3) and hasattr(
3195+
agent_with_tool.model._client.responses, "with_streaming_response"
3196+
):
3197+
request.headers["X-Stainless-Raw-Response"] = "stream"
3198+
31813199
response = httpx.Response(
31823200
200,
31833201
request=request,

0 commit comments

Comments
 (0)