Automate generating text and images, fine-tune and more.

Using our official OpenAI integration

  • Easily subscribe to OpenAI webhooks to trigger your jobs.

  • Create any tasks possible with the OpenAI API.

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

  • Example code using OpenAI

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

    import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
    import { OpenAI } from "@trigger.dev/openai";
    import { z } from "zod";
    const openai = new OpenAI({
    id: "openai",
    apiKey: process.env.OPENAI_API_KEY!,
    });
    // This Job will generate an image from a prompt, using OpenAI's image API
    client.defineJob({
    id: "openai-generate-image",
    name: "OpenAI: generate image from a prompt",
    version: "1.0.0",
    trigger: eventTrigger({
    name: "openai.images",
    schema: z.object({}),
    }),
    integrations: {
    openai,
    },
    run: async (payload, io, ctx) => {
    const imageResults = await io.openai.createImage("image", {
    prompt: "A hedgehog wearing a party hat",
    n: 2,
    size: "256x256",
    response_format: "url",
    });
    return {
    images: imageResults.data?.map((image) => image.url),
    };
    },
    });
    ,