Skip to content

Commit fdf5f76

Browse files
authored
document the replicate.run() method (#138)
1 parent 46fbca2 commit fdf5f76

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
@@ -145,6 +145,33 @@ client.fetch = (url, options) => {
145145
};
146146
```
147147

148+
### `replicate.run`
149+
150+
Run a model and await the result. Unlike [`replicate.prediction.create`](#replicatepredictionscreate), this method returns only the prediction output rather than the entire prediction object.
151+
152+
```js
153+
const model = "stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f";
154+
const input = {
155+
prompt: "a 19th century portrait of a raccoon gentleman wearing a suit",
156+
};
157+
const output = await replicate.run(identifier, options, progress);
158+
```
159+
160+
| name | type | description |
161+
| ------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
162+
| `identifier` | string | **Required**. The model version identifier in the format `{owner}/{name}:{version}`, for example `stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f` |
163+
| `options.input` | object | **Required**. An object with the model inputs. |
164+
| `options.wait` | object | Options for waiting for the prediction to finish |
165+
| `options.wait.interval` | number | Polling interval in milliseconds. Defaults to 500 |
166+
| `options.webhook` | string | An HTTPS URL for receiving a webhook when the prediction has new output |
167+
| `options.webhook_events_filter` | string[] | An array of events which should trigger [webhooks](https://replicate.com/docs/webhooks). Allowable values are `start`, `output`, `logs`, and `completed` |
168+
| `options.signal` | object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction |
169+
| `progress` | function | Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time its updated while polling for completion, and when it's completed. |
170+
171+
Throws `Error` if the prediction failed.
172+
173+
Returns `Promise<object>` which resolves with the output of running the model.
174+
148175
### `replicate.models.get`
149176

150177
```js

0 commit comments

Comments
 (0)