Commit fc482504

peter-zhong-replit <peter.zhong@repl.it>
2025-12-01 21:13:27
fix(client): avoid mutating user-provided response config object (#2700)
1 parent df4109a
Changed files (1)
src
openai
resources
responses
src/openai/resources/responses/responses.py
@@ -2,6 +2,7 @@
 
 from __future__ import annotations
 
+from copy import copy
 from typing import Any, List, Type, Union, Iterable, Optional, cast
 from functools import partial
 from typing_extensions import Literal, overload
@@ -1046,6 +1047,7 @@ class Responses(SyncAPIResource):
                 if "format" in text:
                     raise TypeError("Cannot mix and match text.format with text_format")
 
+                text = copy(text)
                 text["format"] = _type_to_text_format_param(text_format)
 
             api_request: partial[Stream[ResponseStreamEvent]] = partial(
@@ -1151,7 +1153,7 @@ class Responses(SyncAPIResource):
 
             if "format" in text:
                 raise TypeError("Cannot mix and match text.format with text_format")
-
+            text = copy(text)
             text["format"] = _type_to_text_format_param(text_format)
 
         tools = _make_tools(tools)
@@ -2507,7 +2509,7 @@ class AsyncResponses(AsyncAPIResource):
 
                 if "format" in text:
                     raise TypeError("Cannot mix and match text.format with text_format")
-
+                text = copy(text)
                 text["format"] = _type_to_text_format_param(text_format)
 
             api_request = self.create(
@@ -2617,7 +2619,7 @@ class AsyncResponses(AsyncAPIResource):
 
             if "format" in text:
                 raise TypeError("Cannot mix and match text.format with text_format")
-
+            text = copy(text)
             text["format"] = _type_to_text_format_param(text_format)
 
         tools = _make_tools(tools)