@@ -956,6 +956,11 @@ def _request(
956956 stream : bool ,
957957 stream_cls : type [_StreamT ] | None ,
958958 ) -> ResponseT | _StreamT :
959+ # create a copy of the options we were given so that if the
960+ # options are mutated later & we then retry, the retries are
961+ # given the original options
962+ input_options = model_copy (options )
963+
959964 cast_to = self ._maybe_override_cast_to (cast_to , options )
960965 self ._prepare_options (options )
961966
@@ -980,7 +985,7 @@ def _request(
980985
981986 if retries > 0 :
982987 return self ._retry_request (
983- options ,
988+ input_options ,
984989 cast_to ,
985990 retries ,
986991 stream = stream ,
@@ -995,7 +1000,7 @@ def _request(
9951000
9961001 if retries > 0 :
9971002 return self ._retry_request (
998- options ,
1003+ input_options ,
9991004 cast_to ,
10001005 retries ,
10011006 stream = stream ,
@@ -1024,7 +1029,7 @@ def _request(
10241029 if retries > 0 and self ._should_retry (err .response ):
10251030 err .response .close ()
10261031 return self ._retry_request (
1027- options ,
1032+ input_options ,
10281033 cast_to ,
10291034 retries ,
10301035 err .response .headers ,
@@ -1533,6 +1538,11 @@ async def _request(
15331538 # execute it earlier while we are in an async context
15341539 self ._platform = await asyncify (get_platform )()
15351540
1541+ # create a copy of the options we were given so that if the
1542+ # options are mutated later & we then retry, the retries are
1543+ # given the original options
1544+ input_options = model_copy (options )
1545+
15361546 cast_to = self ._maybe_override_cast_to (cast_to , options )
15371547 await self ._prepare_options (options )
15381548
@@ -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 ,
@@ -1570,7 +1580,7 @@ async def _request(
15701580
15711581 if retries > 0 :
15721582 return await self ._retry_request (
1573- options ,
1583+ input_options ,
15741584 cast_to ,
15751585 retries ,
15761586 stream = stream ,
@@ -1593,7 +1603,7 @@ async def _request(
15931603 if retries > 0 and self ._should_retry (err .response ):
15941604 await err .response .aclose ()
15951605 return await self ._retry_request (
1596- options ,
1606+ input_options ,
15971607 cast_to ,
15981608 retries ,
15991609 err .response .headers ,
0 commit comments