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
Theretry config on the task controls how Trigger.dev retries the entire run if it throws:
| Option | Value | Description |
|---|---|---|
maxAttempts | 10 | Maximum total attempts (1 initial + 9 retries) |
factor | 1.8 | Exponential back-off multiplier |
minTimeoutInMs | 500 | Wait at least 500ms before the first retry |
maxTimeoutInMs | 30_000 | Cap retries at 30 seconds apart |
randomize | false | Don’t add jitter to the back-off timing |
Testing your task
To test this task in the Trigger.dev dashboard, use the following payload on the Test page:Related examples
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