@@ -955,6 +955,11 @@ def _request(
955955 stream : bool ,
956956 stream_cls : type [_StreamT ] | None ,
957957 ) -> ResponseT | _StreamT :
958+ # create a copy of the options we were given so that if the
959+ # options are mutated later & we then retry, the retries are
960+ # given the original options
961+ input_options = model_copy (options )
962+
958963 cast_to = self ._maybe_override_cast_to (cast_to , options )
959964 self ._prepare_options (options )
960965
@@ -979,7 +984,7 @@ def _request(
979984
980985 if retries > 0 :
981986 return self ._retry_request (
982- options ,
987+ input_options ,
983988 cast_to ,
984989 retries ,
985990 stream = stream ,
@@ -994,7 +999,7 @@ def _request(
994999
9951000 if retries > 0 :
9961001 return self ._retry_request (
997- options ,
1002+ input_options ,
9981003 cast_to ,
9991004 retries ,
10001005 stream = stream ,
@@ -1022,7 +1027,7 @@ def _request(
10221027 if retries > 0 and self ._should_retry (err .response ):
10231028 err .response .close ()
10241029 return self ._retry_request (
1025- options ,
1030+ input_options ,
10261031 cast_to ,
10271032 retries ,
10281033 err .response .headers ,
@@ -1518,6 +1523,11 @@ async def _request(
15181523 # execute it earlier while we are in an async context
15191524 self ._platform = await asyncify (get_platform )()
15201525
1526+ # create a copy of the options we were given so that if the
1527+ # options are mutated later & we then retry, the retries are
1528+ # given the original options
1529+ input_options = model_copy (options )
1530+
15211531 cast_to = self ._maybe_override_cast_to (cast_to , options )
15221532 await self ._prepare_options (options )
15231533
@@ -1540,7 +1550,7 @@ async def _request(
15401550
15411551 if retries > 0 :
15421552 return await self ._retry_request (
1543- options ,
1553+ input_options ,
15441554 cast_to ,
15451555 retries ,
15461556 stream = stream ,
@@ -1555,7 +1565,7 @@ async def _request(
15551565
15561566 if retries > 0 :
15571567 return await self ._retry_request (
1558- options ,
1568+ input_options ,
15591569 cast_to ,
15601570 retries ,
15611571 stream = stream ,
@@ -1578,7 +1588,7 @@ async def _request(
15781588 if retries > 0 and self ._should_retry (err .response ):
15791589 await err .response .aclose ()
15801590 return await self ._retry_request (
1581- options ,
1591+ input_options ,
15821592 cast_to ,
15831593 retries ,
15841594 err .response .headers ,
0 commit comments