Rate Limits

Rate limits protect the API from abuse and ensure fair usage across all users. Limits are applied per API key.

Rate Limit Tiers

TierRate LimitDetails
Free10 requests/minuteDefault for new accounts
Paid60 requests/minuteFor accounts with purchased credits
EnterpriseCustomContact us for higher limits

Rate Limit Headers

Every API response includes headers showing your current rate limit status.

HTTP Headers
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 55
X-RateLimit-Reset: 1700000060
HeaderDescription
X-RateLimit-LimitMaximum requests per minute for your tier
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp when the limit resets

Handling Rate Limits

When you exceed the rate limit, the API returns a 429 status code. Here's how to handle it gracefully.

TypeScript
import railwail, { RailwailError } from "railwail";

const rw = railwail("rw_live_xxxxx");

async function requestWithRetry(fn: () => Promise<any>, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (err) {
      if (err instanceof RailwailError && err.status === 429) {
        const waitMs = Math.pow(2, i) * 1000; // Exponential backoff
        console.log(`Rate limited. Retrying in ${waitMs}ms...`);
        await new Promise(resolve => setTimeout(resolve, waitMs));
      } else {
        throw err;
      }
    }
  }
  throw new Error("Max retries exceeded");
}

const reply = await requestWithRetry(() =>
  rw.run("gpt-4o", "Hello!")
);

Best practices

Use exponential backoff when retrying after rate limits. Space out requests and batch where possible to stay within your tier's limits.