## Clear queued async tasks

### cURL

```bash
curl --request DELETE \
  --url https://api.cloro.dev/v1/async/queue \
  --header 'Authorization: Bearer <token>'
```

### Python

```python
import requests

url = "https://api.cloro.dev/v1/async/queue"

headers = {"Authorization": "Bearer <token>"}

response = requests.delete(url, headers=headers)

print(response.text)
```

### JavaScript

```javascript
const options = {method: 'DELETE', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api.cloro.dev/v1/async/queue', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### PHP

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.cloro.dev/v1/async/queue",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>
```

### Go

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

url := "https://api.cloro.dev/v1/async/queue"

req, _ := http.NewRequest("DELETE", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}
```

### Unirest Example

```java
HttpResponse<String> response = Unirest.delete("https://api.cloro.dev/v1/async/queue")
  .header("Authorization", "Bearer <token>")
  .asString();
```

### Ruby

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.cloro.dev/v1/async/queue")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

### Response Codes

- **200** - Success
- **401** - Unauthorized
- **429** - Rate limit exceeded
- **500** - Internal server error

### Example JSON Responses

#### Success Response
```json
{
  "success": true,
  "cleared": 42
}
```

#### Error Response
```json
{
  "error": {
    "code": "MISSING_API_KEY",
    "message": "Missing or invalid API key",
    "timestamp": "2025-01-15T12:00:00.000Z"
  }
}
```

```json
{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "API key rate limit exceeded",
    "timestamp": "2025-01-15T12:00:00.000Z"
  }
}
```

```json
{
  "success": false,
  "error": "Maximum retries exceeded"
}
```

### Description
Clears your organization’s pending async queue in a single call — useful when you’ve enqueued a large backlog by mistake or want to reset the queue instead of waiting for it to drain. Only queued tasks are affected:

- `QUEUED` tasks are **removed**.
- `PROCESSING` tasks are already in-flight on a worker and are **left running** — they cannot be recalled from here.
- `COMPLETED` and `FAILED` tasks are historical and are **left in place**; you can still retrieve them via [`GET /v1/async/task/{taskId}`](/content/docs/api-reference/endpoint/get-task-status/index.html) until they age out of the [retention window](/content/docs/api-reference/endpoint/get-task-status#task-retention-policy/index.html).

Credits are only deducted once a task is processed, so clearing the queue has **no effect on your credit balance** and no refund is issued. The call is safe to repeat: an already-empty queue returns `cleared: 0` rather than an error. To check how many tasks are queued before clearing, use the [async status endpoint](/content/docs/api-reference/endpoint/get-async-status/index.html).

### Authorizations
Authorization is required as a bearer token. One key grants access to every endpoint in this specification; per-key scopes are not available, so a client cannot request a narrower permission. Keys are created, rotated, and revoked in the [dashboard](https://dashboard.cloro.dev/api-keys).

### Response
Returns the number of queued tasks that were removed.
