Limiti di frequenza
L’API limita le richieste al secondo per team (non per chiave):
| Piano | Richieste al secondo |
|---|---|
| Free | 10 |
| Pro | 10 |
| Scale | 25 |
| Enterprise | Personalizzato |
Il limite di Resend è di 2 richieste al secondo. Un batch di fino a 100 email è una richiesta, quindi puoi inviare migliaia di email al secondo entro il limite.
I limiti si applicano in finestre di un secondo. Le sessioni della dashboard non sono soggette a limiti di frequenza. Le quote di invio (Piani e quote) sono separate dai limiti di richieste.
Ogni risposta include:
| Header | Significato |
|---|---|
ratelimit-limit |
Richieste consentite per finestra (ad esempio 10). |
ratelimit-remaining |
Richieste rimaste nella finestra corrente. |
ratelimit-reset |
Secondi prima del reset della finestra (1). |
retry-after |
Solo su 429: secondi da attendere prima di riprovare (1). |
HTTP/1.1 429 Too Many Requestsratelimit-limit: 10ratelimit-remaining: 0ratelimit-reset: 1retry-after: 1
{ "statusCode": 429, "name": "rate_limit_exceeded", "message": "Too many requests. You can only make 10 requests per second." }Gestire il 429
Sezione intitolata “Gestire il 429”import { SpacePost, type SendEmailOptions } from "@spacepost/node";
const spacepost = new SpacePost();
async function sendWithRetry(email: SendEmailOptions, key: string, attempts = 5) { for (let i = 0; i < attempts; i++) { const { data, error } = await spacepost.emails.send(email, { idempotencyKey: key }); if (!error) return data; if (error.name !== "rate_limit_exceeded") throw new Error(`${error.name}: ${error.message}`); await new Promise((r) => setTimeout(r, 1000 * (i + 1))); } throw new Error("rate limited");}import time, requests
def post_with_retry(url, headers, json, attempts=5): for _ in range(attempts): r = requests.post(url, headers=headers, json=json, timeout=15) if r.status_code != 429: return r time.sleep(float(r.headers.get("retry-after", 1))) return rRiutilizza sempre la stessa Idempotency-Key nei nuovi tentativi, in modo che una richiesta che era in realtà andata a buon fine non venga ripetuta.
Consigli
Sezione intitolata “Consigli”- Preferisci i batch a molti invii singoli.
- Metti gli invii in coda in un worker in background e limita la sua concorrenza al tuo limite.
- Distribuisci i job di importazione (ad esempio la creazione di contatti) a un ritmo costante.