# Retries

In a normal queue operation it is inevitable that jobs will eventually fail. Failed jobs will by default en on the "failed" set (unless removeOnFailed is enabled). However, it is often useful to perform a number of retries before the job is finally considered failed.

In order to enable retries we need to specify a max number of attempts to retry a job, and which backoff strategy to use. These are options passed inside the "opts" field of our job payload following this interface (for simplicity we will hide the rest of the available options for now):

```typescript
interface JobOpts {
  attempts: number;
  backoff: {
    type: "exponential" | "linear",
    delay: number // Time in milliseconds
  }
  // ... More opts
}
```

We can therefore enable retries by sending these options when adding a job, so for instance if we want to retry up to 5 times with an exponential backoff that starts with 1 second we would send the job like this:

{% tabs %}
{% tab title="Curl" %}

```powershell
curl --location 'http://mydomain.dev/queues/my-queue/jobs' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer my-secret-token' \
--data '[{
	"name": "paint-red",
        "data": {},
        "opts": {
        "attempts": 5,
        "backoff": {
          "type": "exponential",
          "delay": 1000
        }
}]'
```

{% endtab %}
{% endtabs %}

Now, if this job would fail when processed, it will retry up to 5 times following an exponential backoff (retrying after 1 second, 2 seconds, 4, seconds and so on).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bullmq.net/http-api/queues/adding-jobs/retries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
