Skip to content

Commit c0cf1ec

Browse files
authored
Use Bearer authorization scheme (#295)
Replicate's API now supports the standard [Bearer authentication scheme](https://swagger.io/docs/specification/authentication/bearer-authentication/). https://replicate.com/changelog/2024-04-03-bearer-tokens For compatibility with existing clients, the existing `Token` scheme will be supported indefinitely. But going forward, the new `Bearer` scheme is preferred. Signed-off-by: Mattt Zmuda <[email protected]>
1 parent 301a4ad commit c0cf1ec

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

replicate/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _build_httpx_client(
335335
if (
336336
api_token := api_token or os.environ.get("REPLICATE_API_TOKEN")
337337
) and api_token != "":
338-
headers["Authorization"] = f"Token {api_token}"
338+
headers["Authorization"] = f"Bearer {api_token}"
339339

340340
base_url = (
341341
base_url or os.environ.get("REPLICATE_BASE_URL") or "https://api.replicate.com"

tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def test_authorization_when_setting_environ_after_import():
1414
router.route(
1515
method="GET",
1616
url="https://api.replicate.com/",
17-
headers={"Authorization": "Token test-set-after-import"},
17+
headers={"Authorization": "Bearer test-set-after-import"},
1818
).mock(
1919
return_value=httpx.Response(
2020
200,
@@ -42,7 +42,7 @@ async def test_client_error_handling():
4242
router.route(
4343
method="GET",
4444
url="https://api.replicate.com/",
45-
headers={"Authorization": "Token test-client-error"},
45+
headers={"Authorization": "Bearer test-client-error"},
4646
).mock(
4747
return_value=httpx.Response(
4848
400,
@@ -69,7 +69,7 @@ async def test_server_error_handling():
6969
router.route(
7070
method="GET",
7171
url="https://api.replicate.com/",
72-
headers={"Authorization": "Token test-server-error"},
72+
headers={"Authorization": "Bearer test-server-error"},
7373
).mock(
7474
return_value=httpx.Response(
7575
500,

0 commit comments

Comments
 (0)