Skip to content

Commit 018ccb3

Browse files
committed
fix: add api_token parameter to copy() methods for consistency
The copy() methods in Replicate and AsyncReplicate were missing the api_token parameter that was added to __init__ in commit 8c05e64. This was causing test failures since the test suite expects the copy() method signature to match the constructor signature. This commit adds the api_token parameter to both copy() methods with the same handling logic as in __init__: - Accepts both api_token and bearer_token - Raises error if both are provided - Maps api_token to bearer_token internally
1 parent c02614d commit 018ccb3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/replicate/_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def use(
334334
def copy(
335335
self,
336336
*,
337+
api_token: str | None = None,
337338
bearer_token: str | None = None,
338339
base_url: str | httpx.URL | None = None,
339340
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
@@ -348,6 +349,15 @@ def copy(
348349
"""
349350
Create a new client instance re-using the same options given to the current client with optional overriding.
350351
"""
352+
# Handle api_token as legacy alias for bearer_token
353+
if api_token is not None and bearer_token is not None:
354+
raise ValueError(
355+
"Cannot provide both api_token and bearer_token parameters. "
356+
"Use bearer_token (api_token is deprecated)."
357+
)
358+
if api_token is not None:
359+
bearer_token = api_token
360+
351361
if default_headers is not None and set_default_headers is not None:
352362
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
353363

@@ -720,6 +730,7 @@ def use(
720730
def copy(
721731
self,
722732
*,
733+
api_token: str | None = None,
723734
bearer_token: str | None = None,
724735
base_url: str | httpx.URL | None = None,
725736
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
@@ -734,6 +745,15 @@ def copy(
734745
"""
735746
Create a new client instance re-using the same options given to the current client with optional overriding.
736747
"""
748+
# Handle api_token as legacy alias for bearer_token
749+
if api_token is not None and bearer_token is not None:
750+
raise ValueError(
751+
"Cannot provide both api_token and bearer_token parameters. "
752+
"Use bearer_token (api_token is deprecated)."
753+
)
754+
if api_token is not None:
755+
bearer_token = api_token
756+
737757
if default_headers is not None and set_default_headers is not None:
738758
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
739759

0 commit comments

Comments
 (0)