Skip to content

Commit 31298dc

Browse files
committed
Update UPGRADING.md
1 parent e82741d commit 31298dc

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

UPGRADING.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Upgrading from v1 to v2
22

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.
44

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.
66

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. 🧑🏽‍🦰 🤝 🤖
88

99
## Installing the v2 SDK
1010

@@ -14,9 +14,7 @@ Use pip to install the latest pre-release version of the v2 SDK:
1414
pip install --pre replicate
1515
```
1616

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
2018

2119
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.
2220

@@ -45,14 +43,18 @@ dependencies = [
4543

4644
## Client initialization and authentication
4745

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:
4947

5048
```python
5149
import replicate
5250

5351
output = replicate.run(...)
5452
```
5553

54+
☝️ This approach expects a `REPLICATE_API_TOKEN` variable to be present in the environment.
55+
56+
---
57+
5658
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:
5759

5860
### Before (v1)
@@ -79,7 +81,9 @@ The `api_token` parameter is still accepted for backward compatibility, but `bea
7981

8082
## Streaming output
8183

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.
8387

8488
### Before (v1)
8589

@@ -114,7 +118,7 @@ Note: `replicate.stream()` still works in v2 but is deprecated and will be remov
114118

115119
## Predictions
116120

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()`).
118122

119123
### Creating predictions
120124

@@ -355,7 +359,9 @@ for prediction in page.results:
355359

356360
## Models and versions
357361

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.
359365

360366
### Before (v1)
361367

@@ -397,7 +403,7 @@ The `model.versions` shorthand is not available in v2.
397403

398404
## Trainings
399405

400-
Training objects also lose their instance methods in v2.
406+
Training objects do not have the `.wait()` and `.cancel()` instance methods in v2.
401407

402408
### Before (v1)
403409

@@ -521,7 +527,7 @@ secret = replicate.webhooks.default.secret()
521527
Webhooks.validate(request, secret)
522528
```
523529

524-
The validation logic is identical; only import paths may differ.
530+
The validation logic is identical; only the import paths differ.
525531

526532
## Experimental use() interface
527533

@@ -621,25 +627,11 @@ The following features are not available in v2:
621627
- Model instance methods: `predict()`
622628
- `model.versions` shorthand (use `replicate.models.versions` instead)
623629
- Separate `async_*` methods (use `AsyncReplicate` client)
624-
- Positional arguments (all methods require keyword arguments)
625-
626-
## Migration strategy
627-
628-
For a gradual migration:
629-
630-
1. Start by updating client initialization and imports
631-
2. Replace prediction instance methods with resource methods
632-
3. Update async code to use `AsyncReplicate`
633-
4. Add keyword arguments to all API calls
634-
5. Update error handling to use specific exception types
635-
6. Test thoroughly, especially prediction lifecycle code
636-
637-
For codebases with extensive v1 usage, consider creating adapter functions to bridge the differences while you migrate incrementally.
630+
- Positional arguments (all API operation methods like `models.get` and `collections.let` require keyword arguments)
638631

639632
## Getting help
640633

641-
If you encounter issues during migration:
634+
If you encounter issues during the migration process:
642635

643636
- Check the [API documentation](https://replicate.com/docs/reference/http)
644-
- Review the [full API reference](api.md)
645637
- Open an issue on [GitHub](https://github.com/replicate/replicate-python-stainless/issues)

0 commit comments

Comments
 (0)