← Developer tools

Rate-limit and batching planner

Backfilling charts for an existing user base, or recomputing after a schema change, is bounded by two things: the plan's per-minute limit and how many requests your worker keeps in flight. Enter the batch and see the wall time on every plan.

Free · runs in your browser · no API key needed · updated

20,000 calls through one API key.

Wall time for the batch on each plan
PlanLimit / minRate-limit floorWith your concurrencyPacingMonthly quota
Free605 h 33 min5 h 33 minbound by the plan limit1 per 1000 msexceeds 1,000
Hobby1801 h 51 min1 h 51 minbound by the plan limit1 per 334 msexceeds 10,000
Starter60033 min33 minbound by the plan limit1 per 100 msfits (50,000)
Pro6,0003 min17 minbound by your concurrency1 per 10 msfits (250,000)
javascript
// Paced batch for the Hobby plan: 180 requests / minute per key.
const RATE_PER_MINUTE = 180;
const MAX_IN_FLIGHT = 8;
const SPACING_MS = Math.ceil(60_000 / RATE_PER_MINUTE);
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

async function chart(body) {
  for (let attempt = 0; attempt < 5; attempt++) {
    const res = await fetch("https://api.astronode.dev/v1/charts/birth", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify(body),
    });
    if (res.status === 429) {
      // A 429 costs no quota and takes no window slot; retrying early just fails again.
      const { error } = await res.json();
      if (error.code === "QUOTA_EXCEEDED") throw new Error(error.message); // Retry-After = next UTC month
      await sleep(Number(res.headers.get("retry-after") ?? 1) * 1000); // RATE_LIMITED
      continue;
    }
    if (!res.ok) throw new Error(`AstroNode ${res.status}: ${await res.text()}`);
    return (await res.json()).data;
  }
  throw new Error("still rate limited after 5 attempts");
}

// Start one request every SPACING_MS, never more than MAX_IN_FLIGHT at once.
async function runBatch(bodies) {
  const results = new Array(bodies.length);
  let next = 0;
  const worker = async () => {
    while (next < bodies.length) {
      const i = next++;
      const started = Date.now();
      results[i] = await chart(bodies[i]);
      await sleep(Math.max(0, SPACING_MS * MAX_IN_FLIGHT - (Date.now() - started)));
    }
  };
  await Promise.all(Array.from({ length: MAX_IN_FLIGHT }, worker));
  return results;
}

How the limit works

Each API key has a sliding 60-second window: at most rate_per_minute requests in any 60 seconds - 60 on Free, 180 on Hobby, 600 on Starter, 6,000 on Pro. The per-minute limit is checked before the monthly quota, on every request.

Over the limit: HTTP 429

json
{
  "request_id": "...",
  "error": {
    "code": "RATE_LIMITED",
    "message": "Rate limit exceeded",
    "details": { "retry_after_seconds": 12 }
  }
}

Every response from the limiter - successes and 429s alike - carries x-ratelimit-limit, x-ratelimit-remaining and x-ratelimit-reset. The reset is the Unix second when the window next frees a slot (the oldest request in it plus 60 s), so a client can slow down before it is refused. Every 429 also carries a standard Retry-After header in seconds: for RATE_LIMITED it equals details.retry_after_seconds; for QUOTA_EXCEEDED it is the time to the start of the next UTC month, when the quota resets - no retry helps before then.

How the planner computes wall time

calls = users × calls per user. Your client can issue at most concurrency × 60,000 / latency_ms requests a minute; the plan allows rate_per_minute. Wall time is calls divided by the smaller of the two, and the table says which one binds. Pacing is the gap between request starts that keeps one key under its limit: ceil(60,000 / rate_per_minute) ms - 334 ms on Hobby, 10 ms on Pro.

Latency is yours to measure: it depends on your region, the endpoint and your network, so the planner does not assume a figure. Start with a small batch, read your p50, and plug it in.

Batch endpoints change the arithmetic

Bulk Kundli matching (POST /v1/compatibility/batch, Starter and above) takes 1 to 500 pairs in one request, each with your own id. A 500-pair batch is one request against the rate limit and, if it succeeds, one billable call against the quota - not 500. Where a batch endpoint exists, use it before tuning concurrency.

Common mistakes

  • Retrying immediately. A 429 costs no quota and is not added to the window, but until the oldest request ages out every retry is refused again - a wasted round trip that keeps your workers busy doing nothing. Honour Retry-After. Requests that pass the limiter and then fail (an engine 400, say) do take a window slot, so validate inputs before sending.
  • Treating every 429 alike. Branch on error.code: RATE_LIMITED means wait seconds; QUOTA_EXCEEDED means stop the job.
  • Unbounded `Promise.all`. Firing 20,000 requests at once guarantees a wall of 429s. Bound concurrency and pace starts, as the generated worker does.
  • Recomputing unchanged inputs. Results are deterministic; skip any birth whose request body hash you already have.

FAQ

Is the limit per key or per account?
The per-minute window is per API key. The monthly quota is per account, summed across all of its keys.
Does the 429 response include a Retry-After header?
Yes, on every 429. For RATE_LIMITED it matches error.details.retry_after_seconds; for QUOTA_EXCEEDED it counts down to the next UTC month. Most HTTP clients' retry helpers read it directly.
How do I see my remaining budget?
Read x-ratelimit-remaining and x-ratelimit-reset on any response, including a 429, for the minute window; the dashboard shows the month's billable usage.