@@ -20,20 +20,18 @@ npm install replicate
2020
2121## Usage
2222
23- Create the client :
23+ Set your ` REPLICATE_API_TOKEN ` in your environment :
2424
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..."
3228```
3329
3430Run a model and await the result:
3531
3632``` js
33+ import replicate from " replicate" ;
34+
3735const model = " stability-ai/stable-diffusion:27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478" ;
3836const input = {
3937 prompt: " a 19th century portrait of a raccoon gentleman wearing a suit" ,
@@ -94,8 +92,12 @@ const output = await replicate.run(model, { input });
9492
9593### Constructor
9694
95+ You can create a custom instance of the Replicate client using the ` replicate.Replicate ` constructor:
96+
9797``` js
98- const replicate = new Replicate (options);
98+ import replicate from " replicate" ;
99+
100+ const replicate = new replicate.Replicate (options);
99101```
100102
101103| name | type | description |
@@ -121,10 +123,10 @@ you can install a fetch function from an external package like
121123and pass it to the ` fetch ` option in the constructor.
122124
123125``` js
124- import Replicate from " replicate" ;
126+ import replicate from " replicate" ;
125127import fetch from " cross-fetch" ;
126128
127- const replicate = new Replicate ({ fetch });
129+ const replicate = new replicate. Replicate ({ fetch });
128130```
129131
130132You 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.
778780
779781## TypeScript
780782
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