Skip to main content

Overview

OpenAI API calls can be slow or occasionally fail. This task configures custom retry options at the task level (overriding the project defaults) and explicitly throws an error when OpenAI returns an empty response — which triggers a retry without needing any extra tooling.

Task code

trigger/openai.ts

How retrying works

The retry config on the task controls how Trigger.dev retries the entire run if it throws:
If you only want to retry a specific part of your task (for example, one API call among many), use retry.onThrow to wrap just that block. See the Resend email sequence example for a pattern using retry.onThrow.

Testing your task

To test this task in the Trigger.dev dashboard, use the following payload on the Test page:

Resend email sequence

Use retry.onThrow for partial retries within a multi-step task

FFmpeg video processing

Process video files using FFmpeg in a background task