@@ -20,20 +20,18 @@ npm install replicate
20
20
21
21
## Usage
22
22
23
- Create the client :
23
+ Set your ` REPLICATE_API_TOKEN ` in your environment :
24
24
25
- ``` js
26
- import Replicate from " replicate" ;
27
-
28
- const replicate = new Replicate ({
29
- // get your token from https://replicate.com/account
30
- auth: " my api token" , // defaults to process.env.REPLICATE_API_TOKEN
31
- });
25
+ ``` sh
26
+ # get your token from https://replicate.com/account
27
+ export REPLICATE_API_TOKEN=" r8_123..."
32
28
```
33
29
34
30
Run a model and await the result:
35
31
36
32
``` js
33
+ import replicate from " replicate" ;
34
+
37
35
const model = " stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478" ;
38
36
const input = {
39
37
prompt: " a 19th century portrait of a raccoon gentleman wearing a suit" ,
@@ -94,8 +92,12 @@ const output = await replicate.run(model, { input });
94
92
95
93
### Constructor
96
94
95
+ You can create a custom instance of the Replicate client using the ` replicate.Replicate ` constructor:
96
+
97
97
``` js
98
- const replicate = new Replicate (options);
98
+ import replicate from " replicate" ;
99
+
100
+ const replicate = new replicate.Replicate (options);
99
101
```
100
102
101
103
| name | type | description |
@@ -121,10 +123,10 @@ you can install a fetch function from an external package like
121
123
and pass it to the ` fetch ` option in the constructor.
122
124
123
125
``` js
124
- import Replicate from " replicate" ;
126
+ import replicate from " replicate" ;
125
127
import fetch from " cross-fetch" ;
126
128
127
- const replicate = new Replicate ({ fetch });
129
+ const replicate = new replicate. Replicate ({ fetch });
128
130
```
129
131
130
132
You can also use the ` fetch ` option to add custom behavior to client requests,
@@ -778,4 +780,50 @@ You can call this method directly to make other requests to the API.
778
780
779
781
## TypeScript
780
782
781
- The ` Replicate ` constructor and all ` replicate.* ` methods are fully typed.
783
+ The ` Replicate ` constructor and all ` replicate.* ` methods are fully typed. Types are accessible
784
+ via the named exports:
785
+
786
+ ``` ts
787
+ import type { Model , Prediction } from " replicate" ;
788
+ ```
789
+
790
+ ## Deprecated Constructor
791
+
792
+ Earlier versions of the Replicate library exported the ` Replicate ` constructor as the default
793
+ export. This will be removed in a future version, to migrate please update your code to use
794
+ the following pattern:
795
+
796
+ If you don't need to customize your Replicate client you can just remove the constructor code
797
+ entirely:
798
+
799
+ ``` js
800
+ // Deprecated
801
+ import Replicate from " replicate" ;
802
+
803
+ const replicate = new Replicate ();
804
+
805
+ replicate .run (... );
806
+
807
+ // Fixed
808
+ import replicate from " replicate" ;
809
+
810
+ replicate .run (... );
811
+ ```
812
+
813
+ If you need the Replicate construtor it's available on the ` replicate ` object.
814
+
815
+ ``` js
816
+ // Deprecated
817
+ import Replicate from " replicate" ;
818
+
819
+ const replicate = new Replicate ({auth: " my-token" });
820
+
821
+ replicate .run (... );
822
+
823
+ // Fixed
824
+ import replicate from " replicate" ;
825
+
826
+ replicate = new replicate.Replicate ({auth: " my-token" });
827
+
828
+ replicate .run (... );
829
+ ```
0 commit comments