Skip to content

Commit 57eb175

Browse files
zekesuperhighfives
andcommitted
document typescript usage
Co-Authored-By: Charlie Gleason <[email protected]>
1 parent 02b06d4 commit 57eb175

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ const output = await replicate.run(model, { input });
112112
> upload the file to your own storage provider
113113
> and pass a publicly accessible URL.
114114
115+
## TypeScript usage
116+
117+
This library exports TypeScript definitions. You can import them like this:
118+
119+
```ts
120+
import Replicate, { Prediction } from 'replicate';
121+
```
122+
123+
Here's an example that uses the `Prediction` type with a custom `onProgress` callback:
124+
125+
```ts
126+
import Replicate, { Prediction } from 'replicate';
127+
128+
const replicate = new Replicate();
129+
const model = "black-forest-labs/flux-schnell";
130+
const prompt = "a 19th century portrait of a raccoon gentleman wearing a suit";
131+
const input = { prompt };
132+
133+
const onProgress = (prediction: Prediction) => {
134+
console.log({ prediction });
135+
};
136+
137+
await replicate.run(model, { input }, onProgress)
138+
```
139+
140+
See the full list of exported types in [index.d.ts](./index.d.ts).
141+
115142
### Webhooks
116143

117144
Webhooks provide real-time updates about your prediction. Specify an endpoint when you create a prediction, and Replicate will send HTTP POST requests to that URL when the prediction is created, updated, and finished.

0 commit comments

Comments
 (0)