Skip to main content

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​

MethodLimitResponse
GET /v1/user/usage, GET /v1/tunnels/{id}/stats30 requests per minute per user in a team, shared by both methods429, RateLimited
GET /v1/secrets/configs/config/secrets/watchNumber of concurrent subscriptions per user, depends on the plan429, TooManyRequests
GET /v1/system/ips1 request per second from one IP address429

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.

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 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.

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

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.