Skip to content

Commit 00eab77

Browse files
fix(api)!: use correct env var for bearer token
The correct env var to use is REPLICATE_API_TOKEN, not REPLICATE_CLIENT_BEARER_TOKEN
1 parent 1330c62 commit 00eab77

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 27
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-37bb31ed76da599d3bded543a3765f745c8575d105c13554df7f8361c3641482.yml
33
openapi_spec_hash: 15bdec12ca84042768bfb28cc48dfce3
4-
config_hash: 810de4c2eee1a7649263cff01f00da7c
4+
config_hash: 64fd304bf0ff077a74053ce79a255106

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ import os
2828
from replicate import ReplicateClient
2929

3030
client = ReplicateClient(
31-
bearer_token=os.environ.get(
32-
"REPLICATE_CLIENT_BEARER_TOKEN"
33-
), # This is the default and can be omitted
31+
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
3432
)
3533

3634
accounts = client.accounts.list()
@@ -39,7 +37,7 @@ print(accounts.type)
3937

4038
While you can provide a `bearer_token` keyword argument,
4139
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
42-
to add `REPLICATE_CLIENT_BEARER_TOKEN="My Bearer Token"` to your `.env` file
40+
to add `REPLICATE_API_TOKEN="My Bearer Token"` to your `.env` file
4341
so that your Bearer Token is not stored in source control.
4442

4543
## Async usage
@@ -52,9 +50,7 @@ import asyncio
5250
from replicate import AsyncReplicateClient
5351

5452
client = AsyncReplicateClient(
55-
bearer_token=os.environ.get(
56-
"REPLICATE_CLIENT_BEARER_TOKEN"
57-
), # This is the default and can be omitted
53+
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
5854
)
5955

6056

src/replicate/_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def __init__(
8888
) -> None:
8989
"""Construct a new synchronous ReplicateClient client instance.
9090
91-
This automatically infers the `bearer_token` argument from the `REPLICATE_CLIENT_BEARER_TOKEN` environment variable if it is not provided.
91+
This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided.
9292
"""
9393
if bearer_token is None:
94-
bearer_token = os.environ.get("REPLICATE_CLIENT_BEARER_TOKEN")
94+
bearer_token = os.environ.get("REPLICATE_API_TOKEN")
9595
if bearer_token is None:
9696
raise ReplicateClientError(
97-
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the REPLICATE_CLIENT_BEARER_TOKEN environment variable"
97+
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the REPLICATE_API_TOKEN environment variable"
9898
)
9999
self.bearer_token = bearer_token
100100

@@ -270,13 +270,13 @@ def __init__(
270270
) -> None:
271271
"""Construct a new async AsyncReplicateClient client instance.
272272
273-
This automatically infers the `bearer_token` argument from the `REPLICATE_CLIENT_BEARER_TOKEN` environment variable if it is not provided.
273+
This automatically infers the `bearer_token` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided.
274274
"""
275275
if bearer_token is None:
276-
bearer_token = os.environ.get("REPLICATE_CLIENT_BEARER_TOKEN")
276+
bearer_token = os.environ.get("REPLICATE_API_TOKEN")
277277
if bearer_token is None:
278278
raise ReplicateClientError(
279-
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the REPLICATE_CLIENT_BEARER_TOKEN environment variable"
279+
"The bearer_token client option must be set either by passing bearer_token to the client or by setting the REPLICATE_API_TOKEN environment variable"
280280
)
281281
self.bearer_token = bearer_token
282282

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_validate_headers(self) -> None:
346346
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
347347

348348
with pytest.raises(ReplicateClientError):
349-
with update_env(**{"REPLICATE_CLIENT_BEARER_TOKEN": Omit()}):
349+
with update_env(**{"REPLICATE_API_TOKEN": Omit()}):
350350
client2 = ReplicateClient(base_url=base_url, bearer_token=None, _strict_response_validation=True)
351351
_ = client2
352352

@@ -1126,7 +1126,7 @@ def test_validate_headers(self) -> None:
11261126
assert request.headers.get("Authorization") == f"Bearer {bearer_token}"
11271127

11281128
with pytest.raises(ReplicateClientError):
1129-
with update_env(**{"REPLICATE_CLIENT_BEARER_TOKEN": Omit()}):
1129+
with update_env(**{"REPLICATE_API_TOKEN": Omit()}):
11301130
client2 = AsyncReplicateClient(base_url=base_url, bearer_token=None, _strict_response_validation=True)
11311131
_ = client2
11321132

0 commit comments

Comments
 (0)