Skip to content

Commit e10fb3d

Browse files
committed
fix: add api_token parameter to copy methods for legacy compatibility
The copy() method signatures were missing the api_token parameter that exists in __init__(), causing test failures. Added api_token parameter to both sync and async copy methods with proper handling for legacy compatibility.
1 parent b0beaf1 commit e10fb3d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/replicate/_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def copy(
337337
self,
338338
*,
339339
bearer_token: str | None = None,
340+
api_token: str | None = None, # Legacy compatibility parameter
340341
base_url: str | httpx.URL | None = None,
341342
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
342343
http_client: httpx.Client | None = None,
@@ -350,6 +351,12 @@ def copy(
350351
"""
351352
Create a new client instance re-using the same options given to the current client with optional overriding.
352353
"""
354+
# Handle legacy api_token parameter
355+
if api_token is not None and bearer_token is not None:
356+
raise ValueError("Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility.")
357+
if api_token is not None:
358+
bearer_token = api_token
359+
353360
if default_headers is not None and set_default_headers is not None:
354361
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
355362

@@ -725,6 +732,7 @@ def copy(
725732
self,
726733
*,
727734
bearer_token: str | None = None,
735+
api_token: str | None = None, # Legacy compatibility parameter
728736
base_url: str | httpx.URL | None = None,
729737
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
730738
http_client: httpx.AsyncClient | None = None,
@@ -738,6 +746,12 @@ def copy(
738746
"""
739747
Create a new client instance re-using the same options given to the current client with optional overriding.
740748
"""
749+
# Handle legacy api_token parameter
750+
if api_token is not None and bearer_token is not None:
751+
raise ValueError("Cannot specify both 'bearer_token' and 'api_token'. Please use 'bearer_token' (recommended) or 'api_token' for legacy compatibility.")
752+
if api_token is not None:
753+
bearer_token = api_token
754+
741755
if default_headers is not None and set_default_headers is not None:
742756
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
743757

0 commit comments

Comments
 (0)