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: UPGRADING.md
+20-28Lines changed: 20 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Upgrading from v1 to v2
2
2
3
-
This guide helps you migrate from the v1 Replicate Python SDK to v2. The v2 SDK is a complete rewrite generated from Replicate's OpenAPI specification, providing better type safety, more consistent error handling, and improved async support.
3
+
This guide will help you migrate an existing codebase from the v1 Replicate Python SDK to v2. The v2 SDK is a complete rewrite generated in partnership with [Stainless](https://www.stainless.com/customers/replicate), the folks who help build and maintain SDKs for companies like OpenAI, Anthropic, and Cloudflare. The v2 SDK is largely autogenerated from Replicate's OpenAPI specification, providing better type safety, more consistent error handling, and improved async support. Check out the [v2 release notes](#TODO) for more details.
4
4
5
-
This doc is intended for both humans and agents.
5
+
✋ If you are working on a new project, you don't need to read this document.
6
6
7
-
If you're using an AI tool to assist with the upgrade process, you can provide it with this entire document as context.
7
+
This doc is intended for both humans and agents. 🧑🏽🦰 🤝 🤖
8
8
9
9
## Installing the v2 SDK
10
10
@@ -14,9 +14,7 @@ Use pip to install the latest pre-release version of the v2 SDK:
14
14
pip install --pre replicate
15
15
```
16
16
17
-
The v2 SDK requires Python 3.8 or higher, same as v1.
18
-
19
-
## Pinning to 1.x
17
+
## Pinning to the legacy v1 SDK
20
18
21
19
You are not required to upgrade to the new 2.x version. If you're already using the 1.x version and want to continue using it, pin the version number in your dependency files.
22
20
@@ -45,14 +43,18 @@ dependencies = [
45
43
46
44
## Client initialization and authentication
47
45
48
-
In both the v1 and v2 SDKs, the simplest usage pattern is to import the `replicate` module and use the module-level functions like `replicate.run()`, which automatically uses the `REPLICATE_API_TOKEN` environment variable, without explicitly instantiating a client:
46
+
In both the v1 and v2 SDKs, the simplest way to import and use the library is to import the `replicate` module and use the module-level functions like `replicate.run()`, without explicitly instantiating a client:
49
47
50
48
```python
51
49
import replicate
52
50
53
51
output = replicate.run(...)
54
52
```
55
53
54
+
☝️ This approach expects a `REPLICATE_API_TOKEN` variable to be present in the environment.
55
+
56
+
---
57
+
56
58
For cases where you need to instantiate a client (e.g., for custom configuration or async support), the client class name and parameter names have changed in v2:
57
59
58
60
### Before (v1)
@@ -79,7 +81,9 @@ The `api_token` parameter is still accepted for backward compatibility, but `bea
79
81
80
82
## Streaming output
81
83
82
-
Streaming works differently in v2. Prediction objects no longer have a `stream()` method. Use `replicate.use()` with `streaming=True` for streaming output.
84
+
Streaming works differently in v2. Prediction objects no longer have a `stream()` method and the `replicate.stream()` method is deprecated.
85
+
86
+
You should use `replicate.use()` with `streaming=True` for streaming output in the v2 SDK.
83
87
84
88
### Before (v1)
85
89
@@ -114,7 +118,7 @@ Note: `replicate.stream()` still works in v2 but is deprecated and will be remov
114
118
115
119
## Predictions
116
120
117
-
Prediction objects have changed significantly. Instance methods like `wait()`, `cancel()`, and `reload()` are removed in favor of client methods (e.g., use `replicate.predictions.wait(prediction.id)` instead of `prediction.wait()`).
121
+
Prediction objects in the v2 client no longer have instance methods like `wait()`, `cancel()`, and `reload()`. These have been removed in favor of client methods (e.g., use `replicate.predictions.wait(prediction.id)` instead of `prediction.wait()`).
118
122
119
123
### Creating predictions
120
124
@@ -355,7 +359,9 @@ for prediction in page.results:
355
359
356
360
## Models and versions
357
361
358
-
Model and version access uses keyword arguments throughout.
362
+
Model and version access uses keyword arguments throughout, instead of shorthand positional arguments.
363
+
364
+
The new keyword argument syntax in v2 is more verbose but clearer and more consistent with Replicate's HTTP API, and consistent across all SDKs in different programming languages.
359
365
360
366
### Before (v1)
361
367
@@ -397,7 +403,7 @@ The `model.versions` shorthand is not available in v2.
397
403
398
404
## Trainings
399
405
400
-
Training objects also lose their instance methods in v2.
406
+
Training objects do not have the `.wait()` and `.cancel()` instance methods in v2.
0 commit comments