> Markdown version of https://tuna.am/en/docs/api/rate-limits/. Documentation index: [llms.txt](https://tuna.am/en/llms.txt), full text in one file: [llms-full.txt](https://tuna.am/en/llms-full.txt). Any page is available as Markdown: append `.md` to its URL without the trailing slash.

# Rate limits

The request rate is limited by individual methods, the ones that are expensive for the server. When a limit is exceeded, the API responds with `429`. Other methods may get limits later, so handle `429` in every request.

## Methods with limits

| Method                                                                                                                                         | Limit                                                             | Response                 |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------ |
| [`GET /v1/user/usage`](https://tuna.am/en/docs/api/user-usage.md), [`GET /v1/tunnels/{id}/stats`](https://tuna.am/en/docs/api/tunnel-stats.md) | 30 requests per minute per user in a team, shared by both methods | `429`, `RateLimited`     |
| [`GET /v1/secrets/configs/config/secrets/watch`](https://tuna.am/en/docs/api/secrets-secret-watch.md)                                          | Number of concurrent subscriptions per user, depends on the plan  | `429`, `TooManyRequests` |
| [`GET /v1/system/ips`](https://tuna.am/en/docs/api/get-i-ps.md)                                                                                | 1 request per second from one IP address                          | `429`                    |

The server updates the address list every 5 minutes, so there is no point in polling the method more often. The method supports `ETag`: with the `If-None-Match` header it returns `304` if the list has not changed. For details, see [Using tuna in a corporate network](https://tuna.am/en/docs/guides/corporate-network.md).

## Retrying requests

* `429` and `503`: wait and retry. If the response has a `Retry-After` header, wait the number of seconds it specifies. If not, increase the delay with each attempt: 1, 2, 4 seconds and so on.
* `500`: retry once or twice with a delay. If the error persists, contact [support](https://tuna.am/en/docs/support.md) and include the `request_id` from the response.
* `POST`, `PUT`, `PATCH` and `DELETE` requests may have already been applied when they return a `5xx` error. Before retrying, check whether the object was already created or the change was already applied.
* Retrying other `4xx` errors does not help: fix the request instead. For what each status means, see [API errors](https://tuna.am/en/docs/api/errors.md#status-codes).

In Python, retries for `GET` requests are configured on a `requests` session:

```python
import requests
from requests.adapters import HTTPAdapter
from urllib3.util import Retry

session = requests.Session()
session.headers["Authorization"] = "Bearer {API-key}"
session.mount("https://", HTTPAdapter(max_retries=Retry(
    total=3,
    backoff_factor=1,
    status_forcelist=[429, 500, 503],
)))

r = session.get("https://api.tuna.am/v1/user/usage")

```

By default, `Retry` respects `Retry-After` and does not retry `POST`.
