@ai-sdk/replicate 0.0.0-64aae7dd-20260114144918 → 0.0.0-98261322-20260122142521
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/60-replicate.mdx +241 -0
- package/package.json +10 -5
- package/src/index.ts +7 -0
- package/src/replicate-error.ts +13 -0
- package/src/replicate-image-model.test.ts +752 -0
- package/src/replicate-image-model.ts +268 -0
- package/src/replicate-image-settings.ts +36 -0
- package/src/replicate-provider.test.ts +24 -0
- package/src/replicate-provider.ts +99 -0
- package/src/version.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
# @ai-sdk/replicate
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-98261322-20260122142521
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
- 080559b: chore: add docs to package dist
|
|
8
|
+
|
|
9
|
+
## 2.0.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8dc54db: chore: add src folders to package bundle
|
|
14
|
+
|
|
15
|
+
## 2.0.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [5c090e7]
|
|
20
|
+
- @ai-sdk/provider@3.0.4
|
|
21
|
+
- @ai-sdk/provider-utils@4.0.8
|
|
22
|
+
|
|
23
|
+
## 2.0.7
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [46f46e4]
|
|
28
|
+
- @ai-sdk/provider-utils@4.0.7
|
|
29
|
+
|
|
30
|
+
## 2.0.6
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [1b11dcb]
|
|
35
|
+
- @ai-sdk/provider-utils@4.0.6
|
|
36
|
+
- @ai-sdk/provider@3.0.3
|
|
10
37
|
|
|
11
38
|
## 2.0.5
|
|
12
39
|
|
package/dist/index.js
CHANGED
|
@@ -227,7 +227,7 @@ var replicateImageProviderOptionsSchema = (0, import_provider_utils2.lazySchema)
|
|
|
227
227
|
);
|
|
228
228
|
|
|
229
229
|
// src/version.ts
|
|
230
|
-
var VERSION = true ? "0.0.0-
|
|
230
|
+
var VERSION = true ? "0.0.0-98261322-20260122142521" : "0.0.0-test";
|
|
231
231
|
|
|
232
232
|
// src/replicate-provider.ts
|
|
233
233
|
function createReplicate(options = {}) {
|
package/dist/index.mjs
CHANGED
|
@@ -210,7 +210,7 @@ var replicateImageProviderOptionsSchema = lazySchema(
|
|
|
210
210
|
);
|
|
211
211
|
|
|
212
212
|
// src/version.ts
|
|
213
|
-
var VERSION = true ? "0.0.0-
|
|
213
|
+
var VERSION = true ? "0.0.0-98261322-20260122142521" : "0.0.0-test";
|
|
214
214
|
|
|
215
215
|
// src/replicate-provider.ts
|
|
216
216
|
function createReplicate(options = {}) {
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Replicate
|
|
3
|
+
description: Learn how to use Replicate models with the AI SDK.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Replicate Provider
|
|
7
|
+
|
|
8
|
+
[Replicate](https://replicate.com/) is a platform for running open-source AI models.
|
|
9
|
+
It is a popular choice for running image generation models.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
The Replicate provider is available via the `@ai-sdk/replicate` module. You can install it with
|
|
14
|
+
|
|
15
|
+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
|
|
16
|
+
<Tab>
|
|
17
|
+
<Snippet text="pnpm add @ai-sdk/replicate" dark />
|
|
18
|
+
</Tab>
|
|
19
|
+
<Tab>
|
|
20
|
+
<Snippet text="npm install @ai-sdk/replicate" dark />
|
|
21
|
+
</Tab>
|
|
22
|
+
<Tab>
|
|
23
|
+
<Snippet text="yarn add @ai-sdk/replicate" dark />
|
|
24
|
+
</Tab>
|
|
25
|
+
|
|
26
|
+
<Tab>
|
|
27
|
+
<Snippet text="bun add @ai-sdk/replicate" dark />
|
|
28
|
+
</Tab>
|
|
29
|
+
</Tabs>
|
|
30
|
+
|
|
31
|
+
## Provider Instance
|
|
32
|
+
|
|
33
|
+
You can import the default provider instance `replicate` from `@ai-sdk/replicate`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { replicate } from '@ai-sdk/replicate';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If you need a customized setup, you can import `createReplicate` from `@ai-sdk/replicate`
|
|
40
|
+
and create a provider instance with your settings:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createReplicate } from '@ai-sdk/replicate';
|
|
44
|
+
|
|
45
|
+
const replicate = createReplicate({
|
|
46
|
+
apiToken: process.env.REPLICATE_API_TOKEN ?? '',
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You can use the following optional settings to customize the Replicate provider instance:
|
|
51
|
+
|
|
52
|
+
- **baseURL** _string_
|
|
53
|
+
|
|
54
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
55
|
+
The default prefix is `https://api.replicate.com/v1`.
|
|
56
|
+
|
|
57
|
+
- **apiToken** _string_
|
|
58
|
+
|
|
59
|
+
API token that is being sent using the `Authorization` header. It defaults to
|
|
60
|
+
the `REPLICATE_API_TOKEN` environment variable.
|
|
61
|
+
|
|
62
|
+
- **headers** _Record<string,string>_
|
|
63
|
+
|
|
64
|
+
Custom headers to include in the requests.
|
|
65
|
+
|
|
66
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
67
|
+
|
|
68
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
69
|
+
|
|
70
|
+
## Image Models
|
|
71
|
+
|
|
72
|
+
You can create Replicate image models using the `.image()` factory method.
|
|
73
|
+
For more on image generation with the AI SDK see [generateImage()](/docs/reference/ai-sdk-core/generate-image).
|
|
74
|
+
|
|
75
|
+
<Note>
|
|
76
|
+
Model support for `size` and other parameters varies by model. Check the
|
|
77
|
+
model's documentation on [Replicate](https://replicate.com/explore) for
|
|
78
|
+
supported options and additional parameters that can be passed via
|
|
79
|
+
`providerOptions.replicate`.
|
|
80
|
+
</Note>
|
|
81
|
+
|
|
82
|
+
### Supported Image Models
|
|
83
|
+
|
|
84
|
+
The following image models are currently supported by the Replicate provider:
|
|
85
|
+
|
|
86
|
+
- [black-forest-labs/flux-1.1-pro-ultra](https://replicate.com/black-forest-labs/flux-1.1-pro-ultra)
|
|
87
|
+
- [black-forest-labs/flux-1.1-pro](https://replicate.com/black-forest-labs/flux-1.1-pro)
|
|
88
|
+
- [black-forest-labs/flux-dev](https://replicate.com/black-forest-labs/flux-dev)
|
|
89
|
+
- [black-forest-labs/flux-pro](https://replicate.com/black-forest-labs/flux-pro)
|
|
90
|
+
- [black-forest-labs/flux-schnell](https://replicate.com/black-forest-labs/flux-schnell)
|
|
91
|
+
- [bytedance/sdxl-lightning-4step](https://replicate.com/bytedance/sdxl-lightning-4step)
|
|
92
|
+
- [fofr/aura-flow](https://replicate.com/fofr/aura-flow)
|
|
93
|
+
- [fofr/latent-consistency-model](https://replicate.com/fofr/latent-consistency-model)
|
|
94
|
+
- [fofr/realvisxl-v3-multi-controlnet-lora](https://replicate.com/fofr/realvisxl-v3-multi-controlnet-lora)
|
|
95
|
+
- [fofr/sdxl-emoji](https://replicate.com/fofr/sdxl-emoji)
|
|
96
|
+
- [fofr/sdxl-multi-controlnet-lora](https://replicate.com/fofr/sdxl-multi-controlnet-lora)
|
|
97
|
+
- [ideogram-ai/ideogram-v2-turbo](https://replicate.com/ideogram-ai/ideogram-v2-turbo)
|
|
98
|
+
- [ideogram-ai/ideogram-v2](https://replicate.com/ideogram-ai/ideogram-v2)
|
|
99
|
+
- [lucataco/dreamshaper-xl-turbo](https://replicate.com/lucataco/dreamshaper-xl-turbo)
|
|
100
|
+
- [lucataco/open-dalle-v1.1](https://replicate.com/lucataco/open-dalle-v1.1)
|
|
101
|
+
- [lucataco/realvisxl-v2.0](https://replicate.com/lucataco/realvisxl-v2.0)
|
|
102
|
+
- [lucataco/realvisxl2-lcm](https://replicate.com/lucataco/realvisxl2-lcm)
|
|
103
|
+
- [luma/photon-flash](https://replicate.com/luma/photon-flash)
|
|
104
|
+
- [luma/photon](https://replicate.com/luma/photon)
|
|
105
|
+
- [nvidia/sana](https://replicate.com/nvidia/sana)
|
|
106
|
+
- [playgroundai/playground-v2.5-1024px-aesthetic](https://replicate.com/playgroundai/playground-v2.5-1024px-aesthetic)
|
|
107
|
+
- [recraft-ai/recraft-v3-svg](https://replicate.com/recraft-ai/recraft-v3-svg)
|
|
108
|
+
- [recraft-ai/recraft-v3](https://replicate.com/recraft-ai/recraft-v3)
|
|
109
|
+
- [stability-ai/stable-diffusion-3.5-large-turbo](https://replicate.com/stability-ai/stable-diffusion-3.5-large-turbo)
|
|
110
|
+
- [stability-ai/stable-diffusion-3.5-large](https://replicate.com/stability-ai/stable-diffusion-3.5-large)
|
|
111
|
+
- [stability-ai/stable-diffusion-3.5-medium](https://replicate.com/stability-ai/stable-diffusion-3.5-medium)
|
|
112
|
+
- [tstramer/material-diffusion](https://replicate.com/tstramer/material-diffusion)
|
|
113
|
+
|
|
114
|
+
You can also use [versioned models](https://replicate.com/docs/topics/models/versions).
|
|
115
|
+
The id for versioned models is the Replicate model id followed by a colon and the version ID (`$modelId:$versionId`), e.g.
|
|
116
|
+
`bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637`.
|
|
117
|
+
|
|
118
|
+
<Note>
|
|
119
|
+
You can also pass any available Replicate model ID as a string if needed.
|
|
120
|
+
</Note>
|
|
121
|
+
|
|
122
|
+
### Basic Usage
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { replicate } from '@ai-sdk/replicate';
|
|
126
|
+
import { generateImage } from 'ai';
|
|
127
|
+
import { writeFile } from 'node:fs/promises';
|
|
128
|
+
|
|
129
|
+
const { image } = await generateImage({
|
|
130
|
+
model: replicate.image('black-forest-labs/flux-schnell'),
|
|
131
|
+
prompt: 'The Loch Ness Monster getting a manicure',
|
|
132
|
+
aspectRatio: '16:9',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await writeFile('image.webp', image.uint8Array);
|
|
136
|
+
|
|
137
|
+
console.log('Image saved as image.webp');
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Model-specific options
|
|
141
|
+
|
|
142
|
+
```ts highlight="9-11"
|
|
143
|
+
import { replicate } from '@ai-sdk/replicate';
|
|
144
|
+
import { generateImage } from 'ai';
|
|
145
|
+
|
|
146
|
+
const { image } = await generateImage({
|
|
147
|
+
model: replicate.image('recraft-ai/recraft-v3'),
|
|
148
|
+
prompt: 'The Loch Ness Monster getting a manicure',
|
|
149
|
+
size: '1365x1024',
|
|
150
|
+
providerOptions: {
|
|
151
|
+
replicate: {
|
|
152
|
+
style: 'realistic_image',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Versioned Models
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { replicate } from '@ai-sdk/replicate';
|
|
162
|
+
import { generateImage } from 'ai';
|
|
163
|
+
|
|
164
|
+
const { image } = await generateImage({
|
|
165
|
+
model: replicate.image(
|
|
166
|
+
'bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637',
|
|
167
|
+
),
|
|
168
|
+
prompt: 'The Loch Ness Monster getting a manicure',
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Image Editing
|
|
173
|
+
|
|
174
|
+
Replicate supports image editing through various models. Pass input images via `prompt.images` to transform or edit existing images.
|
|
175
|
+
|
|
176
|
+
#### Basic Image Editing
|
|
177
|
+
|
|
178
|
+
Transform an existing image using text prompts:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const imageBuffer = readFileSync('./input-image.png');
|
|
182
|
+
|
|
183
|
+
const { images } = await generateImage({
|
|
184
|
+
model: replicate.image('black-forest-labs/flux-kontext-dev'),
|
|
185
|
+
prompt: {
|
|
186
|
+
text: 'Turn the cat into a golden retriever dog',
|
|
187
|
+
images: [imageBuffer],
|
|
188
|
+
},
|
|
189
|
+
providerOptions: {
|
|
190
|
+
replicate: {
|
|
191
|
+
guidance_scale: 7.5,
|
|
192
|
+
num_inference_steps: 30,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Inpainting with Mask
|
|
199
|
+
|
|
200
|
+
Edit specific parts of an image using a mask. For FLUX Fill models, white areas in the mask indicate where the image should be edited:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const image = readFileSync('./input-image.png');
|
|
204
|
+
const mask = readFileSync('./mask.png'); // White = inpaint, black = keep
|
|
205
|
+
|
|
206
|
+
const { images } = await generateImage({
|
|
207
|
+
model: replicate.image('black-forest-labs/flux-fill-pro'),
|
|
208
|
+
prompt: {
|
|
209
|
+
text: 'A sunlit indoor lounge area with a pool containing a flamingo',
|
|
210
|
+
images: [image],
|
|
211
|
+
mask: mask,
|
|
212
|
+
},
|
|
213
|
+
providerOptions: {
|
|
214
|
+
replicate: {
|
|
215
|
+
guidance_scale: 7.5,
|
|
216
|
+
num_inference_steps: 30,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
<Note>
|
|
223
|
+
Input images can be provided as `Buffer`, `ArrayBuffer`, `Uint8Array`, or
|
|
224
|
+
base64-encoded strings. Different Replicate models have different parameter
|
|
225
|
+
names and capabilities — check the model's documentation on
|
|
226
|
+
[Replicate](https://replicate.com/explore) for details.
|
|
227
|
+
</Note>
|
|
228
|
+
|
|
229
|
+
### Provider Options
|
|
230
|
+
|
|
231
|
+
Common provider options for image generation:
|
|
232
|
+
|
|
233
|
+
- **maxWaitTimeInSeconds** _number_ - Maximum time in seconds to wait for the prediction to complete in sync mode. By default, Replicate uses [sync mode](https://replicate.com/docs/topics/predictions/create-a-prediction#timeout-duration) with a 60-second timeout. Set to a positive number to use a custom duration (e.g., `120` for 2 minutes). When not specified, uses the default 60-second wait.
|
|
234
|
+
- **guidance_scale** _number_ - Guidance scale for classifier-free guidance. Higher values make the output more closely match the prompt.
|
|
235
|
+
- **num_inference_steps** _number_ - Number of denoising steps. More steps = higher quality but slower.
|
|
236
|
+
- **negative_prompt** _string_ - Negative prompt to guide what to avoid in the generation.
|
|
237
|
+
- **output_format** _'png' | 'jpg' | 'webp'_ - Output image format.
|
|
238
|
+
- **output_quality** _number (1-100)_ - Output image quality. Only applies to jpg and webp.
|
|
239
|
+
- **strength** _number (0-1)_ - Strength of the transformation for img2img. Lower values keep more of the original image.
|
|
240
|
+
|
|
241
|
+
For more details, see the [Replicate models page](https://replicate.com/explore).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/replicate",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-98261322-20260122142521",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
11
|
+
"docs/**/*",
|
|
12
|
+
"src",
|
|
11
13
|
"CHANGELOG.md",
|
|
12
14
|
"README.md"
|
|
13
15
|
],
|
|
16
|
+
"directories": {
|
|
17
|
+
"doc": "./docs"
|
|
18
|
+
},
|
|
14
19
|
"exports": {
|
|
15
20
|
"./package.json": "./package.json",
|
|
16
21
|
".": {
|
|
@@ -20,15 +25,15 @@
|
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@ai-sdk/provider": "
|
|
24
|
-
"@ai-sdk/provider-utils": "
|
|
28
|
+
"@ai-sdk/provider": "3.0.4",
|
|
29
|
+
"@ai-sdk/provider-utils": "4.0.8"
|
|
25
30
|
},
|
|
26
31
|
"devDependencies": {
|
|
27
32
|
"@types/node": "20.17.24",
|
|
28
33
|
"tsup": "^8",
|
|
29
34
|
"typescript": "5.8.3",
|
|
30
35
|
"zod": "3.25.76",
|
|
31
|
-
"@ai-sdk/test-server": "1.0.
|
|
36
|
+
"@ai-sdk/test-server": "1.0.2",
|
|
32
37
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
@@ -54,7 +59,7 @@
|
|
|
54
59
|
"scripts": {
|
|
55
60
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
56
61
|
"build:watch": "pnpm clean && tsup --watch",
|
|
57
|
-
"clean": "del-cli dist *.tsbuildinfo",
|
|
62
|
+
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
58
63
|
"lint": "eslint \"./**/*.ts*\"",
|
|
59
64
|
"type-check": "tsc --build",
|
|
60
65
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createReplicate, replicate } from './replicate-provider';
|
|
2
|
+
export type {
|
|
3
|
+
ReplicateProvider,
|
|
4
|
+
ReplicateProviderSettings,
|
|
5
|
+
} from './replicate-provider';
|
|
6
|
+
export type { ReplicateImageProviderOptions } from './replicate-image-model';
|
|
7
|
+
export { VERSION } from './version';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
const replicateErrorSchema = z.object({
|
|
5
|
+
detail: z.string().optional(),
|
|
6
|
+
error: z.string().optional(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const replicateFailedResponseHandler = createJsonErrorResponseHandler({
|
|
10
|
+
errorSchema: replicateErrorSchema,
|
|
11
|
+
errorToMessage: error =>
|
|
12
|
+
error.detail ?? error.error ?? 'Unknown Replicate error',
|
|
13
|
+
});
|