Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions litellm/llms/chatgpt/responses/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ def transform_responses_api_request(
litellm_params,
headers,
)
request.pop("max_output_tokens", None)
request.pop("max_tokens", None)
request.pop("max_completion_tokens", None)
request.pop("metadata", None)
base_instructions = get_chatgpt_default_instructions()
existing_instructions = request.get("instructions")
if existing_instructions:
Expand All @@ -92,7 +88,22 @@ def transform_responses_api_request(
if "reasoning.encrypted_content" not in include:
include.append("reasoning.encrypted_content")
request["include"] = include
return request

allowed_keys = {
"model",
"input",
"instructions",
"stream",
"store",
"include",
"tools",
"tool_choice",
"reasoning",
"previous_response_id",
"truncation",
}

return {k: v for k, v in request.items() if k in allowed_keys}
Comment on lines +92 to +106

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowlist may silently drop valid future parameters

The allowlist approach is a sound improvement over the previous pop() pattern, but it has a maintainability trade-off: any new parameter that ChatGPT's Responses API starts supporting in the future will be silently dropped until this allowlist is updated. Consider adding a code comment noting this so future developers know to update allowed_keys when the ChatGPT Responses API evolves.

Additionally, the parent class's get_supported_openai_params() is not overridden in ChatGPTResponsesAPIConfig, so it still advertises all OpenAI Responses API params as "supported" even though they'll be stripped here. Overriding get_supported_openai_params to return only the allowed keys would give callers accurate information about what's actually supported and enable LiteLLM's drop_params logic to surface warnings when unsupported params are provided.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


def transform_response_api_response(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,45 @@ def test_chatgpt_forces_streaming_and_reasoning_include(self):
"You are Codex, based on GPT-5."
)

def test_chatgpt_drops_unsupported_responses_params(self):
config = ChatGPTResponsesAPIConfig()
request = config.transform_responses_api_request(
model="chatgpt/gpt-5.2-codex",
input="hi",
response_api_optional_request_params={
# unsupported by ChatGPT Codex
"user": "user_123",
"temperature": 0.2,
"top_p": 0.9,
"context_management": [{"type": "compaction", "compact_threshold": 200000}],
"metadata": {"foo": "bar"},
"max_output_tokens": 123,
"stream_options": {"include_usage": True},
# supported and should be preserved
"truncation": "auto",
"previous_response_id": "resp_123",
"reasoning": {"effort": "medium"},
"tools": [{"type": "function", "function": {"name": "hello"}}],
"tool_choice": {"type": "function", "function": {"name": "hello"}},
},
litellm_params=GenericLiteLLMParams(),
headers={},
)

assert "user" not in request
assert "temperature" not in request
assert "top_p" not in request
assert "context_management" not in request
assert "metadata" not in request
assert "max_output_tokens" not in request
assert "stream_options" not in request

assert request["truncation"] == "auto"
assert request["previous_response_id"] == "resp_123"
assert request["reasoning"] == {"effort": "medium"}
assert request["tools"] == [{"type": "function", "function": {"name": "hello"}}]
assert request["tool_choice"] == {"type": "function", "function": {"name": "hello"}}

def test_chatgpt_non_stream_sse_response_parsing(self):
config = ChatGPTResponsesAPIConfig()
response_payload = {
Expand Down
Loading