Skip to content

Commit 06db0de

Browse files
authored
Document global fetch availability (#60)
* Add discussion of fetch availability and configuration * Add warning about incompatibility with browser Add link to Next.js guide
1 parent 948543a commit 06db0de

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Replicate Node.js client
22

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.
412
513
## Installation
614

@@ -72,6 +80,32 @@ const replicate = new Replicate(options);
7280
| `options.baseUrl` | string | Defaults to https://api.replicate.com/v1 |
7381
| `options.fetch` | function | Fetch function to use. Defaults to `globalThis.fetch` |
7482

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+
75109
### `replicate.models.get`
76110

77111
```js

0 commit comments

Comments
 (0)