You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,17 +28,17 @@ import os
28
28
from replicate import Replicate
29
29
30
30
client = Replicate(
31
-
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
31
+
api_key=os.environ.get("REPLICATE_CLIENT_API_KEY"), # This is the default and can be omitted
32
32
)
33
33
34
34
account = client.account.get()
35
35
print(account.type)
36
36
```
37
37
38
-
While you can provide a `bearer_token` keyword argument,
38
+
While you can provide an `api_key` keyword argument,
39
39
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
40
-
to add `REPLICATE_API_TOKEN="My Bearer Token"` to your `.env` file
41
-
so that your Bearer Token is not stored in source control.
40
+
to add `REPLICATE_CLIENT_API_KEY="My API Key"` to your `.env` file
41
+
so that your API Key is not stored in source control.
42
42
43
43
## Async usage
44
44
@@ -50,7 +50,7 @@ import asyncio
50
50
from replicate import AsyncReplicate
51
51
52
52
client = AsyncReplicate(
53
-
bearer_token=os.environ.get("REPLICATE_API_TOKEN"), # This is the default and can be omitted
53
+
api_key=os.environ.get("REPLICATE_CLIENT_API_KEY"), # This is the default and can be omitted
54
54
)
55
55
56
56
@@ -136,6 +136,24 @@ for prediction in first_page.results:
136
136
# Remove `await` for non-async usage.
137
137
```
138
138
139
+
## File uploads
140
+
141
+
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
142
+
143
+
```python
144
+
from pathlib import Path
145
+
from replicate import Replicate
146
+
147
+
client = Replicate()
148
+
149
+
client.files.create(
150
+
content=Path("/path/to/file"),
151
+
filename="filename",
152
+
)
153
+
```
154
+
155
+
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
156
+
139
157
## Handling errors
140
158
141
159
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `replicate.APIConnectionError` is raised.
prefix=f"Expected entry at `{key}`"ifkeyisnotNoneelsef"Expected file input `{obj!r}`"
36
36
raiseRuntimeError(
37
-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37
+
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/replicate/replicate-python-stainless/tree/main#file-uploads"
0 commit comments