Getting started

If you have not yet set up in your project, go to the quick start guide.


To get started with the Replicate integration on, you need to install the package. You can do this using npm, pnpm, or yarn:

npm install


To use the Replicate API with, you have to provide an API Key.


You can create an API Key in your Account Settings.

import { Replicate } from "";

//this will use the passed in API key (defined in your environment variables)
const replicate = new Replicate({
  id: "replicate",
  apiKey: process.env["REPLICATE_API_KEY"],


Include the Replicate integration in your job.

  id: "replicate-cinematic-prompt",
  name: "Replicate - Cinematic Prompt",
  version: "0.1.0",
  integrations: { replicate },
  trigger: eventTrigger({
    name: "replicate.cinematic",
    schema: z.object({
      prompt: z.string().default("rick astley riding a harley through post-apocalyptic miami"),
      version: z
  run: async (payload, io, ctx) => {
    //wait for prediction completion (uses remote callbacks internally)
    const prediction = await io.replicate.predictions.createAndAwait("await-prediction", {
      version: payload.version,
      input: {
        prompt: `${payload.prompt}, cinematic, 70mm, anamorphic, bokeh`,
        width: 1280,
        height: 720,
    return prediction.output;


You can paginate responses:

  • Using the getAll helper
  • Using the paginate helper
  id: "replicate-pagination",
  name: "Replicate Pagination",
  version: "0.1.0",
  integrations: {
  trigger: eventTrigger({
    name: "replicate.paginate",
  run: async (payload, io, ctx) => {
    // getAll - returns an array of all results (uses paginate internally)
    const all = await io.replicate.getAll(io.replicate.predictions.list, "get-all");

    // paginate - returns an async generator, useful to process one page at a time
    for await (const predictions of io.replicate.paginate(
    )) {
      await"stats", {
        total: predictions.length,
        versions: => p.version),

    return { count: all.length };



Function NameDescription
collections.getGets a collection.
collections.listReturns the first page of all collections. Use with pagination helper.


Function NameDescription
deployments.predictions.createCreates a new prediction with a deployment.
deployments.predictions.createAndAwaitCreates and waits for a new prediction with a deployment.


Function NameDescription
models.getGets a model.
models.versionsGets a model version.
models.versionsGets all model versions.


Function NameDescription
predictions.cancelCancels a prediction.
predictions.createCreates a prediction.
predictions.createAndAwaitCreates and waits for a prediction.
predictions.getGets a prediction.
predictions.listReturns the first page of all predictions. Use with pagination helper.


Function NameDescription
trainings.cancelCancels a training.
trainings.createCreates a training.
trainings.createAndAwaitCreates and waits for a training.
trainings.getGets a training.
trainings.listReturns the first page of all trainings. Use with pagination helper.


Function NameDescription
getAllPagination helper that returns an array of results.
paginatePagination helper that returns an async generator.
requestSends authenticated requests to the Replicate API.
runCreates and waits for a prediction.

Example jobs

Code examples

Check out pre-built jobs using Replicate in our API section.

Was this page helpful?