إنتقل إلى المحتوى الرئيسي

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​

ScopeEndpoint GroupLimitWindowNotes
Per API Key (General)All /api/v1/* routes60 requests1 minuteEnforced first via api_key_rate_limits.
Per Owning User (General)All /api/v1/* routes120 requests1 minuteShared across all keys belonging to the same user.
Per API Key (Purchase)POST /api/v1/purchases, POST /api/v1/actions10 requests1 minuteApplied on top of general limits.
Per Owning User (Purchase)POST /api/v1/purchases, POST /api/v1/actions20 requests1 minuteShared purchase velocity ceiling per account.
Global HTTP GuardFastify server-wide fallback300 requests1 minuteKeyed 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/min guard returns standard x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset, and retry-after headers.
  • Custom API-key 429 rejections currently expose details.retryAfterSeconds inside the JSON payload (TODO(verify) confirming whether Retry-After and X-RateLimit-* HTTP headers will also be attached directly to apiKeySecurity 429 responses — tracked in OPEN_QUESTIONS.md).

Automated Fraud & Abuse Triggers (403 FRAUD_DETECTED)​

Beyond static rate limits, the security engine monitors these abuse signatures:

Fraud TypeDefault TriggerCooldown & Action
REPEATED_AUTH_FAILURE8 failed auth attempts from one IP within 10 minutesTemporary IP block (15 min) + api_key_fraud_events log
MULTI_IP_ABUSE5 distinct peer IPs using the same key within 15 minutesTemporary key block (15 min) + cache invalidation
RAPID_REPEAT_PURCHASE5 purchase/action attempts on a key within 60 secondsTemporary key block (15 min) + cache invalidation
SPENDING_SPIKEWindow burst exceeding 1000 USDT hard cap, or >= 250 USDT and > 3x trailing 24h 10-min averageTemporary 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')
}