Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a9b95c

Browse files
fix(api): fix client_settings.opts.api_key.read_env
This regressed when using the "Guess with AI" feature. See https://replicatehq.slack.com/archives/C08H2L2E0KT/p1746642117876339
1 parent 3173e5f commit 5a9b95c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
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: 35
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/replicate%2Freplicate-client-efbc8cc2d74644b213e161d3e11e0589d1cef181fb318ea02c8eb6b00f245713.yml
33
openapi_spec_hash: 13da0c06c900b61cd98ab678e024987a
4-
config_hash: e25b98bb6202d27e54fc6e08c7de80d8
4+
config_hash: 8e80c2bf93f71823213f5773dd297921

‎README.md‎

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

3030
client = Replicate(
31-
api_key=os.environ.get("REPLICATE_CLIENT_API_KEY"), # This is the default and can be omitted
31+
api_key=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
3232
)
3333

3434
account = client.account.get()
@@ -37,7 +37,7 @@ print(account.type)
3737

3838
While you can provide an `api_key` keyword argument,
3939
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
40-
to add `REPLICATE_CLIENT_API_KEY="My API Key"` to your `.env` file
40+
to add `REPLICATE_API_TOKEN="My API Key"` to your `.env` file
4141
so that your API Key is not stored in source control.
4242

4343
## Async usage
@@ -50,7 +50,7 @@ import asyncio
5050
from replicate import AsyncReplicate
5151

5252
client = AsyncReplicate(
53-
api_key=os.environ.get("REPLICATE_CLIENT_API_KEY"), # This is the default and can be omitted
53+
api_key=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
5454
)
5555

5656

‎src/replicate/_client.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ def __init__(
8383
) -> None:
8484
"""Construct a new synchronous Replicate client instance.
8585
86-
This automatically infers the `api_key` argument from the `REPLICATE_CLIENT_API_KEY` environment variable if it is not provided.
86+
This automatically infers the `api_key` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided.
8787
"""
8888
if api_key is None:
89-
api_key = os.environ.get("REPLICATE_CLIENT_API_KEY")
89+
api_key = os.environ.get("REPLICATE_API_TOKEN")
9090
if api_key is None:
9191
raise ReplicateError(
92-
"The api_key client option must be set either by passing api_key to the client or by setting the REPLICATE_CLIENT_API_KEY environment variable"
92+
"The api_key client option must be set either by passing api_key to the client or by setting the REPLICATE_API_TOKEN environment variable"
9393
)
9494
self.api_key = api_key
9595

@@ -305,13 +305,13 @@ def __init__(
305305
) -> None:
306306
"""Construct a new async AsyncReplicate client instance.
307307
308-
This automatically infers the `api_key` argument from the `REPLICATE_CLIENT_API_KEY` environment variable if it is not provided.
308+
This automatically infers the `api_key` argument from the `REPLICATE_API_TOKEN` environment variable if it is not provided.
309309
"""
310310
if api_key is None:
311-
api_key = os.environ.get("REPLICATE_CLIENT_API_KEY")
311+
api_key = os.environ.get("REPLICATE_API_TOKEN")
312312
if api_key is None:
313313
raise ReplicateError(
314-
"The api_key client option must be set either by passing api_key to the client or by setting the REPLICATE_CLIENT_API_KEY environment variable"
314+
"The api_key client option must be set either by passing api_key to the client or by setting the REPLICATE_API_TOKEN environment variable"
315315
)
316316
self.api_key = api_key
317317

‎tests/test_client.py‎

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

342342
with pytest.raises(ReplicateError):
343-
with update_env(**{"REPLICATE_CLIENT_API_KEY": Omit()}):
343+
with update_env(**{"REPLICATE_API_TOKEN": Omit()}):
344344
client2 = Replicate(base_url=base_url, api_key=None, _strict_response_validation=True)
345345
_ = client2
346346

@@ -1092,7 +1092,7 @@ def test_validate_headers(self) -> None:
10921092
assert request.headers.get("Authorization") == f"Bearer {api_key}"
10931093

10941094
with pytest.raises(ReplicateError):
1095-
with update_env(**{"REPLICATE_CLIENT_API_KEY": Omit()}):
1095+
with update_env(**{"REPLICATE_API_TOKEN": Omit()}):
10961096
client2 = AsyncReplicate(base_url=base_url, api_key=None, _strict_response_validation=True)
10971097
_ = client2
10981098

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /