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
| Tier | Rate Limit | Details |
|---|---|---|
| Free | 10 requests/minute | Default for new accounts |
| Paid | 60 requests/minute | For accounts with purchased credits |
| Enterprise | Custom | Contact 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| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests per minute for your tier |
| X-RateLimit-Remaining | Requests remaining in the current window |
| X-RateLimit-Reset | Unix 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.