# rate_limited

HTTP 429 · `code`: `rate_limited` · `title`: Rate limited

The key made more calls in a minute than its limit (240 by default), or the organisation more than its own (600 by default) over all its keys, or the organisation already had its limit of requests in flight (2 by default) when this one arrived, or repeated failed authentications were throttled. A scan run through `POST /v1/domains/{domain_uuid}/scans/{scan_type}` answers it too when that domain’s scan of that type was started less than 10 minutes ago.

## What the answer carries

Every [problem document](https://developer.watchtower15.com/api/errors/) carries `type`, `title`, `status`, `code`, `detail` and `request_id`. In addition: `limit`: the limit that was exceeded. Header `Retry-After`: the seconds to wait.

## What to do

Wait for `Retry-After` seconds, then retry, and slow the job down. When the refusal is for requests in flight, `Retry-After` is 1 and `limit` is the number of requests an organisation may have in flight at once (2 by default): send fewer calls at the same time, up to that number, each waiting for its answer, and retry the refused call after a second. For a scan, `Retry-After` is the seconds left of its 10-minute cooldown, per domain and scan type: back off for that long rather than retrying at once. See [rate limits](https://developer.watchtower15.com/api/rate-limits/) and [acting on incidents and scans](https://developer.watchtower15.com/api/acting-on-incidents-and-scans/).

## This page's address

The API's answer names this page in `type` as `https://docs.watchtower15.com/api/errors/rate_limited/`, an identifier that never changes within `v1`. That address answers with a permanent redirect to this page, so a link in a log still opens it, and a client comparing `type` as a string never breaks.

**Response (429 Too Many Requests)**

```http
HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Retry-After: 23
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1794215663
X-Request-Id: 4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d

{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Back off and retry**

curl:

```bash
# --retry honours Retry-After on a 429.
curl --retry 3 https://rest.watchtower15.com/v1/servers \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
// The SDK retries a 429 itself, waiting Retry-After when it is
// at most max_retry_wait seconds; past that it throws.
try {
    $page = $wt15->servers->list(['limit' => 100]);
} catch (WatchTower15\Exception\RateLimitException $e) {
    $wait = $e->getRetryAfter();
}
```

Node.js:

```ts
import { RateLimitError } from '@watchtower15/sdk';

// The SDK retries a 429 itself, waiting Retry-After when it is
// at most maxRetryWait; past that it throws.
let wait;
try {
  const page = await wt15.servers.list({ limit: 100 });
} catch (error) {
  if (!(error instanceof RateLimitError)) throw error;
  wait = error.retryAfter;
}
```

Python:

```python
from watchtower15 import RateLimitError

# The SDK retries a 429 itself, waiting Retry-After when it is
# at most max_retry_wait; past that it raises.
try:
    page = client.servers.list(limit=100)
except RateLimitError as error:
    wait = error.retry_after
```

Source: https://developer.watchtower15.com/api/errors/rate_limited/
