@@ -172,7 +172,7 @@ def __init__(
172172 _token_cache : TokenCache | None | NotGiven = not_given ,
173173 ) -> None :
174174 """Construct a new synchronous Anthropic client instance.
175-
175+
176176 Credentials are resolved in the following order (first match wins):
177177
178178 1. Explicit constructor arguments — ``api_key=``, ``auth_token=``,
@@ -456,6 +456,19 @@ def copy(
456456
457457 http_client = http_client or self ._client
458458 # --- credentials support (hand-written, upstream to Stainless) ---
459+ replaces_static_auth = (
460+ (not isinstance (credentials , NotGiven ) and credentials is not None )
461+ or config is not None
462+ or profile is not None
463+ )
464+ copied_api_key = api_key if api_key is not None else self .api_key
465+ copied_auth_token = auth_token if auth_token is not None else self .auth_token
466+ if replaces_static_auth :
467+ if api_key is None :
468+ copied_api_key = None
469+ if auth_token is None :
470+ copied_auth_token = None
471+
459472 if config is not None :
460473 if not isinstance (credentials , NotGiven ) or profile is not None :
461474 raise TypeError ("Pass at most one of `credentials=`, `config=`, or `profile=`." )
@@ -475,8 +488,8 @@ def copy(
475488 _extra_kwargs = {"_token_cache" : self ._token_cache , ** _extra_kwargs }
476489 # --- end credentials support ---
477490 return self .__class__ (
478- api_key = api_key or self . api_key ,
479- auth_token = auth_token or self . auth_token ,
491+ api_key = copied_api_key ,
492+ auth_token = copied_auth_token ,
480493 webhook_key = webhook_key or self .webhook_key ,
481494 base_url = base_url or self .base_url ,
482495 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
@@ -854,6 +867,19 @@ def copy(
854867
855868 http_client = http_client or self ._client
856869 # --- credentials support (hand-written, upstream to Stainless) ---
870+ replaces_static_auth = (
871+ (not isinstance (credentials , NotGiven ) and credentials is not None )
872+ or config is not None
873+ or profile is not None
874+ )
875+ copied_api_key = api_key if api_key is not None else self .api_key
876+ copied_auth_token = auth_token if auth_token is not None else self .auth_token
877+ if replaces_static_auth :
878+ if api_key is None :
879+ copied_api_key = None
880+ if auth_token is None :
881+ copied_auth_token = None
882+
857883 if config is not None :
858884 if not isinstance (credentials , NotGiven ) or profile is not None :
859885 raise TypeError ("Pass at most one of `credentials=`, `config=`, or `profile=`." )
@@ -873,8 +899,8 @@ def copy(
873899 _extra_kwargs = {"_token_cache" : self ._token_cache , ** _extra_kwargs }
874900 # --- end credentials support ---
875901 return self .__class__ (
876- api_key = api_key or self . api_key ,
877- auth_token = auth_token or self . auth_token ,
902+ api_key = copied_api_key ,
903+ auth_token = copied_auth_token ,
878904 webhook_key = webhook_key or self .webhook_key ,
879905 base_url = base_url or self .base_url ,
880906 timeout = self .timeout if isinstance (timeout , NotGiven ) else timeout ,
0 commit comments