You can use Parea to get visibility into your OpenAI calls made through Trigger.dev. This guide will show you how to do that.

Pre-requisites

  1. Created a Trigger.dev project & job
  2. Followed the Authentication steps to set up an organization and API key.
  3. Installed the Parea SDK: npm i parea-ai

Instrumenting your OpenAI calls

Assuming you are calling OpenAI through Trigger.dev like this:

await io.openai.chat.completions.create("chat-completion", {
  model: "gpt-3.5-turbo",
  messages: [
    {
      role: "user",
      content: "Create a good programming joke about background jobs",
    },
  ],
});

To instrument your OpenAI calls, you need to:

  1. Instantiate the Parea client in the beginning of your application
  2. Wrap io.openai.chat.completions.create with traceOpenAITriggerDev. This will automatically log any OpenAI call and send it to Parea.

Applying these changes, your code will look like this:

imoprt { Parea, traceOpenAITriggerDev } from "parea-ai";

// initialize Parea in the beginning
new Parea(process.env.PAREA_API_KEY);

...

// wrap io.openai.chat.completions.create
const tracedOpenAI = traceOpenAITriggerDev(io.openai.chat.completions.create);
// call the wrapped function
await tracedOpenAI("chat-completion", {
  model: "gpt-3.5-turbo",
  messages: [
    {
      role: "user",
      content: "Create a good programming joke about background jobs",
    },
  ],
});

Visualizing your traces

You will see the OpenAI call appear in the dashboard as shown below: