Suede
In questa pagina

Limiti di frequenza

L’API applica limiti di frequenza per chiave API (oppure per IP del client, se la richiesta non è autenticata). Suede stabilisce il limite e la finestra e può modificarli, quindi leggili dalle intestazioni della risposta invece di inserire un numero fisso nel codice.

Intestazioni

Ogni risposta /v1 include:

Intestazione Significato
X-RateLimit-Limit Numero massimo di richieste consentite nella finestra corrente.
X-RateLimit-Remaining Richieste rimanenti nella finestra corrente.
X-RateLimit-Reset Istante, in secondi dall’epoch Unix, in cui la finestra si azzera.

Quando superi il limite, l’API risponde con HTTP 429 e un’intestazione Retry-After (i secondi da attendere):

JSON
{ "error": { "type": "rate_limited", "message": "Rate limit exceeded. Slow down and retry after the reset.", "request_id": "…" } }

Gestire il 429

Rallenta e riprova dopo Retry-After secondi. Uno schema semplice e affidabile:

cURL
# Inspect your current budget from the headers of any response.
curl -sD - -o /dev/null "https://api.suede.io/v1/search?q=test" \
  -H "Authorization: Bearer $SUEDE_API_KEY" | grep -i '^x-ratelimit'
C#
async Task<HttpResponseMessage> GetWithRetryAsync(HttpClient http, string url)
{
    while (true)
    {
        var res = await http.GetAsync(url);
        if (res.StatusCode != System.Net.HttpStatusCode.TooManyRequests) return res;
        var wait = res.Headers.RetryAfter?.Delta ?? TimeSpan.FromSeconds(1);
        await Task.Delay(wait);
    }
}
JavaScript
async function getWithRetry(url, init) {
  for (;;) {
    const res = await fetch(url, init);
    if (res.status !== 429) return res;
    const wait = Number(res.headers.get("retry-after") ?? "1") * 1000;
    await new Promise((r) => setTimeout(r, wait));
  }
}

La limitazione della frequenza è separata dalla fatturazione. Vedi Errori per le risposte 402 restituite quando il tuo abbonamento non è attivo o il saldo dei crediti è esaurito.

Questa pagina ti è stata utile?