Back to APIs

Run machine learning tasks easily and at scale.

Using our official Replicate integration

Create any tasks possible with the Replicate API.

Use io.runTask() and the official SDK or fetch.

Replicate integration docs

Example code using Replicate

Below is a working code example of how you can use Replicate with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
3
const replicate = new Replicate({
4
id: "replicate",
5
apiKey: process.env.REPLICATE_API_KEY!,
6
});
7
8
client.defineJob({
9
id: "replicate-cinematic-prompt",
10
name: "Replicate - Cinematic Prompt",
11
version: "0.1.0",
12
integrations: { replicate },
13
trigger: eventTrigger({
14
name: "replicate.cinematic",
15
schema: z.object({
16
prompt: z
17
.string()
18
.default("rick astley riding a harley through post-apocalyptic miami"),
19
version: z
20
.string()
21
.default(
22
"af1a68a271597604546c09c64aabcd7782c114a63539a4a8d14d1eeda5630c33"
23
),
24
}),
25
}),
26
run: async (payload, io, ctx) => {
27
//wait for prediction completion (uses remote callbacks internally)
28
const prediction = await io.replicate.predictions.createAndAwait(
29
"await-prediction",
30
{
31
version: payload.version,
32
input: {
33
prompt: `${payload.prompt}, cinematic, 70mm, anamorphic, bokeh`,
34
width: 1280,
35
height: 720,
36
},
37
}
38
);
39
return prediction.output;
40
},
41
});

Full-stack Replicate example projects