Rate Limits, Abuse Controls & Retries
To protect account balances from compromised keys, brute-force attacks, and runaway retry loops, every /api/v1/* request passes through per-key, per-user, and IP protections.
Rate Limit Quotas
| Scope | Endpoint Group | Limit | Window | Notes |
|---|---|---|---|---|
| Per API Key (General) | All /api/v1/* routes | 60 requests | 1 minute | Enforced first via api_key_rate_limits. |
| Per Owning User (General) | All /api/v1/* routes | 120 requests | 1 minute | Shared across all keys belonging to the same user. |
| Per API Key (Purchase) | POST /api/v1/purchases, POST /api/v1/actions | 10 requests | 1 minute | Applied on top of general limits. |
| Per Owning User (Purchase) | POST /api/v1/purchases, POST /api/v1/actions | 20 requests | 1 minute | Shared purchase velocity ceiling per account. |
| Global HTTP Guard | Fastify server-wide fallback | 300 requests | 1 minute | Keyed by safe key prefix (ak:gpk_live_...) when present, else peer IP. |
Exceeded Response Shape & Headers
When a key or user quota is exceeded, the server responds with 429 Too Many Requests:
{
"error": {
"code": "RATE_LIMITED",
"message": "API key rate limit exceeded. Please slow down.",
"details": {
"bucket": "per_key_purchase",
"limit": 10,
"retryAfterSeconds": 60
}
}
}
Response Headers Note
- Fastify's global
300/minguard returns standardx-ratelimit-limit,x-ratelimit-remaining,x-ratelimit-reset, andretry-afterheaders. - Custom API-key
429rejections currently exposedetails.retryAfterSecondsinside the JSON payload (TODO(verify)confirming whetherRetry-AfterandX-RateLimit-*HTTP headers will also be attached directly toapiKeySecurity429responses — tracked inOPEN_QUESTIONS.md).
Automated Fraud & Abuse Triggers (403 FRAUD_DETECTED)
Beyond static rate limits, the security engine monitors these abuse signatures:
| Fraud Type | Default Trigger | Cooldown & Action |
|---|---|---|
REPEATED_AUTH_FAILURE | 8 failed auth attempts from one IP within 10 minutes | Temporary IP block (15 min) + api_key_fraud_events log |
MULTI_IP_ABUSE | 5 distinct peer IPs using the same key within 15 minutes | Temporary key block (15 min) + cache invalidation |
RAPID_REPEAT_PURCHASE | 5 purchase/action attempts on a key within 60 seconds | Temporary key block (15 min) + cache invalidation |
SPENDING_SPIKE | Window burst exceeding 1000 USDT hard cap, or >= 250 USDT and > 3x trailing 24h 10-min average | Temporary key block (15 min) + cache invalidation |
Exponential Backoff Retry Strategy
Only retry 429 and 5xx responses (or network timeouts), and always reuse the same idempotencyKey on POST /api/v1/purchases or POST /api/v1/actions:
async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
export async function callWithBackoff<T>(
fn: () => Promise<Response>,
maxAttempts = 4,
): Promise<T> {
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
const res = await fn()
if (res.ok) return (await res.json()) as T
const retryable = res.status === 429 || res.status >= 500
if (!retryable || attempt === maxAttempts) {
const body = await res.json().catch(() => ({}))
throw new Error(`HTTP ${res.status}: ${JSON.stringify(body)}`)
}
const headerDelaySec = Number(res.headers.get('retry-after'))
const payload = await res.clone().json().catch(() => ({}))
const bodyDelaySec = Number(payload?.error?.details?.retryAfterSeconds)
const baseDelayMs =
Number.isFinite(headerDelaySec) && headerDelaySec > 0
? headerDelaySec * 1000
: Number.isFinite(bodyDelaySec) && bodyDelaySec > 0 && res.status === 429
? Math.min(bodyDelaySec * 1000, 15_000)
: Math.min(1000 * 2 ** (attempt - 1), 16_000)
const jitterMs = Math.floor(Math.random() * 400)
await sleep(baseDelayMs + jitterMs)
}
throw new Error('Exhausted retry attempts')
}