stable.se

API-tokens och webhooks ingår inte i de planer vi säljer idag. Hör av dig innan du bygger på API:et.

Utvecklardokumentationen är för närvarande bara tillgänglig på engelska.

Rate Limits

Understand API rate limit tiers, response headers, and strategies for staying within limits.

3 min read

Overview

The Stable API enforces rate limits to ensure fair usage and protect service stability. Limits apply per caller across all endpoints.

Rate Limit Tiers

TierLimitApplies To
Anonymous60 requests / minuteUnauthenticated requests
Session200 requests / minuteAuthenticated user across their sessions
API Token120 requests / minute per tokenEach API token independently

Unauthenticated requests are counted per IP address, signed-in sessions per user, and API tokens per token. Some endpoints have stricter limits of their own.

Response Headers

Responses include these headers:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed in the current window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetSeconds remaining until the window resets
X-RateLimit-ScopeWhich tier applies: anonymous, session, or api-token

Example

HTTP/1.1 200 OK
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 45
X-RateLimit-Scope: api-token

In this example, the current window resets in 45 seconds, with 87 requests remaining out of 120.

When You Hit the Limit

When the limit is exceeded, the API returns:

HTTP/1.1 429 Too Many Requests
X-RateLimit-Scope: api-token
Retry-After: 45
Content-Type: application/json
{
  "status": "429 Too Many Requests",
  "message": "Too many requests",
  "data": null,
  "error": { "TooManyRequests": "Too many requests" },
  "code": "too_many_requests"
}

The Retry-After header indicates how many seconds to wait before retrying.

Backoff Strategy

When you receive a 429, implement exponential backoff:

// Example for GET/read requests. Mutation retries need an idempotency contract.
async function fetchWithRetry(url: string, options: RequestInit, maxRetries = 3) {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    const response = await fetch(url, options);

    if (response.status !== 429) {
      return response;
    }

    if (attempt === maxRetries) {
      throw new Error('Rate limit exceeded after max retries');
    }

    // Use Retry-After header (seconds until window resets)
    const retryAfter = response.headers.get('Retry-After');
    const delay = retryAfter
      ? parseInt(retryAfter, 10) * 1000
      : Math.min(1000 * Math.pow(2, attempt), 60000);

    await new Promise((resolve) => setTimeout(resolve, delay));
  }
}

Best Practices

  • Monitor your usage via X-RateLimit-Remaining headers to avoid hitting limits
  • Implement backoff using the Retry-After header value (it's in seconds, not a timestamp)
  • Batch operations where possible instead of making many individual requests
  • Cache responses for data that doesn't change frequently
  • Use webhooks instead of polling to reduce API calls
  • Keep retries bounded and preserve mutation keys only where the endpoint supports safe replay