Skip to content

Commit f6f6029

Browse files
committed
update client section of upgrade guide
1 parent fbe8fce commit f6f6029

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

UPGRADING.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

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

5+
This doc is intended for both humans and agents.
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.
8+
59
## Installation
610

11+
Use pip to install the latest pre-release version of the SDK:
12+
713
```sh
814
pip install --pre replicate
915
```
@@ -12,7 +18,7 @@ The v2 SDK requires Python 3.8 or higher, same as v1.
1218

1319
## Pinning to 1.x
1420

15-
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 file.
21+
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.
1622

1723
Here's an example `requirements.txt`:
1824

@@ -39,38 +45,34 @@ dependencies = [
3945

4046
## Client initialization and authentication
4147

42-
The client class name and parameter names have changed.
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:
49+
50+
```python
51+
import replicate
52+
53+
output = replicate.run(...)
54+
```
55+
56+
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:
4357

4458
### Before (v1)
4559

4660
```python
61+
import os
4762
import replicate
4863
from replicate import Client
4964

50-
# Using environment variable
51-
client = Client()
52-
53-
# Explicit token
54-
client = Client(api_token="r8_...")
55-
56-
# Module-level usage
57-
output = replicate.run(...)
65+
client = Client(api_token=os.environ["REPLICATE_API_TOKEN"])
5866
```
5967

6068
### After (v2)
6169

6270
```python
71+
import os
6372
import replicate
6473
from replicate import Replicate
6574

66-
# Using environment variable (REPLICATE_API_TOKEN)
67-
client = Replicate()
68-
69-
# Explicit token (note: bearer_token, not api_token)
70-
client = Replicate(bearer_token="r8_...")
71-
72-
# Module-level usage (still works)
73-
output = replicate.run(...)
75+
client = Replicate(bearer_token=os.environ["REPLICATE_API_TOKEN"])
7476
```
7577

7678
The `api_token` parameter is still accepted for backward compatibility, but `bearer_token` is preferred.

0 commit comments

Comments
 (0)