Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(responses): stop treating stream_options as a Responses API param

shivama376f7240021
diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py
index 9f689a2dd31..2263d53182a 100644
--- a/litellm/types/llms/openai.py
+++ b/litellm/types/llms/openai.py
@@ -1171,7 +1171,6 @@ class ResponsesAPIOptionalRequestParams(TypedDict, total=False):
max_tool_calls: Optional[int]
prompt_cache_key: Optional[str]
prompt_cache_retention: Optional[str]
- stream_options: Optional[dict]
top_logprobs: Optional[int]
partial_images: Optional[int] # Number of partial images to generate (1-3) for streaming image generation
context_management: Optional[List[ContextManagementEntry]]
diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py
index 3327fc39f73..8875a75e86f 100644
--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py
+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py
@@ -2,6 +2,7 @@ import json
import os
import sys
+import httpx
import pytest
from fastapi.testclient import TestClient
@@ -9,6 +10,7 @@ sys.path.insert(0, os.path.abspath("../../../../.."))
from unittest.mock import AsyncMock, MagicMock, patch
+import litellm
from litellm.anthropic_interface import messages
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
from litellm.types.utils import Delta, ModelResponse, StreamingChoices
@@ -37,6 +39,68 @@ def test_anthropic_experimental_pass_through_messages_handler():
assert mock_responses.call_args.kwargs["api_key"] == "test-api-key"
+async def test_openai_model_does_not_forward_stream_options_to_responses_api():
+ """
+ Regression test for LIT-4779. `always_include_stream_usage` injects
+ stream_options={'include_usage': True} into every streaming request, but OpenAI
+ models on /v1/messages go to the Responses API, which 400s on that param.
+ """
+ responses_payload = {
+ "id": "resp_stream_options",
+ "object": "response",
+ "created_at": 1734366691,
+ "status": "completed",
+ "model": "gpt-5.5",
+ "output": [
+ {
+ "type": "message",
+ "id": "msg_1",
+ "status": "completed",
+ "role": "assistant",
+ "content": [{"type": "output_text", "text": "hi", "annotations": []}],
+ }
+ ],
+ "parallel_tool_calls": True,
+ "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2},
+ "error": None,
+ "incomplete_details": None,
+ "instructions": None,
+ "metadata": None,
+ "temperature": None,
+ "tool_choice": "auto",
+ "tools": [],
+ "top_p": None,
+ "max_output_tokens": None,
+ "previous_response_id": None,
+ "reasoning": None,
+ "truncation": None,
+ "user": None,
+ }
+
+ mock_response = MagicMock()
+ mock_response.status_code = 200
+ mock_response.text = json.dumps(responses_payload)
+ mock_response.headers = httpx.Headers({})
+ mock_response.json.return_value = responses_payload
+
+ with patch.object(AsyncHTTPHandler, "post", new_callable=AsyncMock) as mock_post:
+ mock_post.return_value = mock_response
+
+ await litellm.anthropic.messages.acreate(
+ max_tokens=100,
+ messages=[{"role": "user", "content": "Hello, how are you?"}],
+ model="openai/gpt-5.5",
+ api_key="test-api-key",
+ stream_options={"include_usage": True},
+ )
+
+ mock_post.assert_called_once()
+ post_kwargs = mock_post.call_args.kwargs
+ request_body = post_kwargs["json"] if "json" in post_kwargs else json.loads(post_kwargs["data"])
+ assert "stream_options" not in request_body
+
+
def test_anthropic_experimental_pass_through_messages_handler_dynamic_api_key_and_api_base_and_custom_values():
"""
Test that api key, api base, and extra kwargs are forwarded to litellm.completion for Azure models.
diff --git a/tests/test_litellm/responses/test_responses_api_request_body.py b/tests/test_litellm/responses/test_responses_api_request_body.py
index 44dfa240d42..2922c9738aa 100644
--- a/tests/test_litellm/responses/test_responses_api_request_body.py
+++ b/tests/test_litellm/responses/test_responses_api_request_body.py
@@ -198,6 +198,33 @@ async def test_aresponses_azure_shell_tool_400_maps_to_bad_request_error():
assert "not supported" in str(excinfo.value).lower()
+async def test_aresponses_drops_stream_options():
+ """
+ stream_options is a Chat Completions param; the Responses API rejects it with
+ "Unknown parameter: 'stream_options.include_usage'". It must never reach the wire.
+ """
+ with patch(
+ "litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.post",
+ new_callable=AsyncMock,
+ ) as mock_post:
+ mock_post.return_value = MockResponse(
+ _minimal_responses_api_payload("resp_stream_options_test", "gpt-5.5"), 200
+ )
+
+ await litellm.aresponses(
+ model="openai/gpt-5.5",
+ api_key="fake-api-key",
+ input="hi",
+ stream_options={"include_usage": True},
+ )
+
+ mock_post.assert_called_once()
+ post_kwargs = mock_post.call_args.kwargs
+ request_body = post_kwargs["json"] if "json" in post_kwargs else json.loads(post_kwargs["data"])
+ assert "stream_options" not in request_body
+
+
@pytest.mark.asyncio
async def test_aresponses_request_level_drop_params_drops_bedrock_mantle_service_tier(
monkeypatch,