|
1 | 1 | # Replicate Node.js client |
2 | 2 |
|
3 | | -A Node.js client for [Replicate](https://replicate.com). It lets you run models from your Node.js code, and everything else you can do with [the HTTP API](https://replicate.com/docs/reference/http). |
| 3 | +A Node.js client for [Replicate](https://replicate.com). |
| 4 | +It lets you run models from your Node.js code, |
| 5 | +and everything else you can do with |
| 6 | +[Replicate's HTTP API](https://replicate.com/docs/reference/http). |
| 7 | + |
| 8 | +> **Warning** |
| 9 | +> This library can't interact with Replicate's API directly from a browser. |
| 10 | +> For more information about how to build a web application |
| 11 | +> check out our ["Build a website with Next.js"](https://replicate.com/docs/get-started/nextjs) guide. |
4 | 12 |
|
5 | 13 | ## Installation |
6 | 14 |
|
@@ -72,6 +80,32 @@ const replicate = new Replicate(options); |
72 | 80 | | `options.baseUrl` | string | Defaults to https://api.replicate.com/v1 | |
73 | 81 | | `options.fetch` | function | Fetch function to use. Defaults to `globalThis.fetch` | |
74 | 82 |
|
| 83 | +The client makes requests to Replicate's API using |
| 84 | +[fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch). |
| 85 | +By default, the `globalThis.fetch` function is used, |
| 86 | +which is available on [Node.js 18](https://nodejs.org/en/blog/announcements/v18-release-announce#fetch-experimental) and later, |
| 87 | +as well as |
| 88 | +[Cloudflare Workers](https://developers.cloudflare.com/workers/runtime-apis/fetch/), |
| 89 | +[Vercel Edge Functions](https://vercel.com/docs/concepts/functions/edge-functions), |
| 90 | +and other environments. |
| 91 | + |
| 92 | +On earlier versions of Node.js |
| 93 | +and other environments where global fetch isn't available, |
| 94 | +you can install a fetch function from an external package like |
| 95 | +[cross-fetch](https://www.npmjs.com/package/cross-fetch) |
| 96 | +and pass it to the `fetch` option in the constructor. |
| 97 | + |
| 98 | +```js |
| 99 | +import Replicate from "replicate"; |
| 100 | +import fetch from 'cross-fetch'; |
| 101 | + |
| 102 | +const replicate = new Replicate({ |
| 103 | + // get your token from https://replicate.com/account |
| 104 | + auth: process.env.REPLICATE_API_TOKEN, |
| 105 | + fetch: fetch |
| 106 | +}); |
| 107 | +``` |
| 108 | + |
75 | 109 | ### `replicate.models.get` |
76 | 110 |
|
77 | 111 | ```js |
|
0 commit comments