Skip to content

Commit

Permalink
Use Bearer authorization scheme (#295)
Browse files Browse the repository at this point in the history
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 <mattt@replicate.com>
  • Loading branch information
mattt committed Apr 25, 2024
1 parent 301a4ad commit c0cf1ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion replicate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _build_httpx_client(
if (
api_token := api_token or os.environ.get("REPLICATE_API_TOKEN")
) and api_token != "":
headers["Authorization"] = f"Token {api_token}"
headers["Authorization"] = f"Bearer {api_token}"

base_url = (
base_url or os.environ.get("REPLICATE_BASE_URL") or "https://api.replicate.com"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def test_authorization_when_setting_environ_after_import():
router.route(
method="GET",
url="https://api.replicate.com/",
headers={"Authorization": "Token test-set-after-import"},
headers={"Authorization": "Bearer test-set-after-import"},
).mock(
return_value=httpx.Response(
200,
Expand Down Expand Up @@ -42,7 +42,7 @@ async def test_client_error_handling():
router.route(
method="GET",
url="https://api.replicate.com/",
headers={"Authorization": "Token test-client-error"},
headers={"Authorization": "Bearer test-client-error"},
).mock(
return_value=httpx.Response(
400,
Expand All @@ -69,7 +69,7 @@ async def test_server_error_handling():
router.route(
method="GET",
url="https://api.replicate.com/",
headers={"Authorization": "Token test-server-error"},
headers={"Authorization": "Bearer test-server-error"},
).mock(
return_value=httpx.Response(
500,
Expand Down

0 comments on commit c0cf1ec

Please sign in to comment.