The limits that size a batch
| Limit | Value | When you exceed it |
|---|---|---|
| Pairs per call | 1-500 | 400 VALIDATION_ERROR |
| Request body | 512 KiB | 413 with error.code: "VALIDATION_ERROR", message "Request body is too large" |
Pair id | 1-64 characters | 400 VALIDATION_ERROR |
| Plan | Starter, for the batch and for GET /v1/reports/:id | 403 PLAN_REQUIRED |
The pair count binds first. Each pair carries two full births, about 225 bytes as compact JSON, so 500 pairs come to about 113 KB - well inside the 512 KiB body limit, even pretty-printed. Split by count, and keep a byte ceiling only as a guard for unusually long ids. The call is asynchronous: 202 with a report id, then poll GET /v1/reports/:id until status is ready; the results arrive sorted by score, highest first. Idempotent starts and polling etiquette are covered in async report jobs.
Pack by bytes, cache by pair
The pair cache is what makes a list page affordable: when a new profile joins, only its pairs are sent. The key hashes both births in order, because Ashtakoot is directional - person_a is the groom and person_b the bride, and swapping them changes koot details (in our test pair Varna's initial_score was 0 one way and 1 the other):
bulk-match.mjs
// bulk-match.mjs - score one profile against a candidate list, cheaply and repeatably
import { createHash } from "node:crypto";
const API = process.env.ASTRONODE_API_URL ?? "https://api.astronode.dev";
const KEY = process.env.ASTRONODE_API_KEY;
const H = { authorization: `Bearer ${KEY}`, "content-type": "application/json" };
const MAX_BODY = 500_000; // the batch route refuses bodies over 512 KiB (413); 500 pairs fit well inside
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
let calls = 0;
// Pair cache: sha256 of both births, in order. Ashtakoot is directional (person_a is the
// groom, person_b the bride), so A|B and B|A are different keys.
const birthKey = (b) => `${b.date}T${b.time}|${b.tz_offset_minutes}|${b.lat}|${b.lng}`;
const pairKey = (a, b) => createHash("sha256").update(`${birthKey(a)}#${birthKey(b)}`).digest("hex").slice(0, 32);
const cache = new Map(); // stand-in for a table: pair_key -> { score, nadi, manglik, engine_version }
// Split at 500 pairs; the byte ceiling only guards against unusually long ids.
function* chunks(pairs) {
let batch = [], size = 12;
for (const p of pairs) {
const n = JSON.stringify(p).length + 1;
if (batch.length && (size + n > MAX_BODY || batch.length === 500)) { yield batch; batch = []; size = 12; }
batch.push(p); size += n;
}
if (batch.length) yield batch;
}
const runBatch = async (pairs) => {
calls++;
const start = await fetch(`${API}/v1/compatibility/batch`, { method: "POST", headers: H, body: JSON.stringify({ pairs }) });
const { data, meta } = await start.json();
for (let wait = 500; ; wait = Math.min(wait * 2, 8000)) { // polls are billed: back off
calls++;
const poll = await (await fetch(`${API}/v1/reports/${data.id}`, { headers: H })).json();
if (poll.data.status === "ready") return { results: poll.data.result.results, engine: meta.engine_version };
if (poll.data.status === "failed") throw new Error(poll.data.error_message);
await sleep(wait);
}
};
const match = async (seeker, candidates) => {
const todo = candidates
.map((c) => ({ c, key: pairKey(seeker.birth, c.birth) }))
.filter(({ key }) => !cache.has(key));
const byId = new Map(todo.map(({ c, key }) => [c.id, key]));
const pairs = todo.map(({ c }) => ({ id: c.id, person_a: seeker.birth, person_b: c.birth }));
const batches = [];
for (const batch of chunks(pairs)) {
batches.push(batch.length);
const { results, engine } = await runBatch(batch);
for (const r of results) {
const nadi = r.koots.find((k) => k.name === "nadi").score;
cache.set(byId.get(r.id), { score: r.score, nadi, manglik: r.manglik_match.status, engine_version: engine });
}
}
// Rank: your product's rule. Here: score, but a 0 in Nadi or a manglik mismatch sorts last.
const ranked = candidates
.map((c) => ({ id: c.id, ...cache.get(pairKey(seeker.birth, c.birth)) }))
.map((r) => ({ ...r, flagged: r.nadi === 0 || r.manglik !== "compatible" }))
.sort((x, y) => x.flagged - y.flagged || y.score - x.score || x.id.localeCompare(y.id));
return { ranked, sent: pairs.length, batches };
};
// 700 candidates born 1993-1998 in four cities (your profiles table).
const CITIES = [[19.076, 72.8777], [28.6139, 77.209], [12.9716, 77.5946], [22.5726, 88.3639]];
const candidate = (i) => ({
id: `bride_${String(i).padStart(4, "0")}`,
birth: { date: new Date(Date.UTC(1993, 0, 1) + i * 259_200_000).toISOString().slice(0, 10),
time: `${String(i % 24).padStart(2, "0")}:${String((i * 7) % 60).padStart(2, "0")}:00`,
tz_offset_minutes: 330, lat: CITIES[i % 4][0], lng: CITIES[i % 4][1] },
});
const seeker = { id: "groom_17", birth: { date: "1994-02-11", time: "07:45:00", tz_offset_minutes: 330, lat: 19.076, lng: 72.8777 } };
const list = Array.from({ length: 700 }, (_, i) => candidate(i));
let run = await match(seeker, list);
console.log(`run 1: ${run.sent} pairs in batches of ${run.batches.join(" + ")}, ${calls} billable calls`);
for (const r of run.ranked.slice(0, 5)) console.log(` ${r.id} ${r.score}/36 nadi ${r.nadi} manglik ${r.manglik}`);
console.log(` flagged (nadi 0 or manglik mismatch): ${run.ranked.filter((r) => r.flagged).length} of ${run.ranked.length}`);
calls = 0;
run = await match(seeker, [...list, ...Array.from({ length: 40 }, (_, i) => candidate(700 + i))]);
console.log(`run 2 (40 new profiles): ${run.sent} pairs in batches of ${run.batches.join(" + ")}, ${calls} billable calls`);Output:
run 1: 700 pairs in batches of 500 + 200, 4 billable calls bride_0008 34/36 nadi 8 manglik compatible bride_0072 34/36 nadi 8 manglik compatible bride_0081 34/36 nadi 8 manglik compatible bride_0108 34/36 nadi 8 manglik compatible bride_0117 34/36 nadi 8 manglik compatible flagged (nadi 0 or manglik mismatch): 271 of 700 run 2 (40 new profiles): 40 pairs in batches of 40, 2 billable calls
Seven hundred pairs went in two batches, 500 and 200: the 500-pair cap split them, not the byte ceiling. The second run, with 40 new profiles added to the same list, sent only those 40.
What it costs per match
- Calls, not pairs, are billed. Each start is one call and each poll is one call. Above, 700 matches cost 4 calls - about 0.006 per match - against 700 calls for
/v1/compatibilityone pair at a time. - Count more polls in production. The run above used the in-memory API, where a job is finished by the time the first poll arrives. Behind a real queue you will see
pendingfirst; the backoff in the code (0.5 s doubling to 8 s) keeps a slow job to a handful of polls. - Refusals are free. The 413 and the 400s are not billed, so probing the size limit costs nothing - but a body that is too large is still a wasted round trip on a results page.
- The cache is the real saving. Store pair scores in a table keyed by the pair hash, with
engine_version, and re-score only when the version changes. The batch response'smeta.engine_versiontells you which version scored it.
The order is yours
The API sorts by total score and nothing else. The ranking above is a product rule: a Nadi score of 0 or a manglik status other than compatible sorts below every clean match, then score, then id for a stable order - which put 271 of the 700 at the bottom. Your audience may weigh these differently; each result carries the eight koots with score, initial_score (before cancellations) and pass, plus manglik_match, so the rule can change without another call.
The batch gives scores, not reasons. When someone opens a profile, fetch the full breakdown for that one pair - the matrimony use case lists the detail calls, and the Gun Milan scoring guide explains the cancellations behind initial_score.
Questions
- What do I end up with?
- 700 candidates scored and ranked in 4 calls, and 40 new ones in 2. The code is in Node.js.
- Which endpoints does this recipe call, and in what order?
- 2 endpoints, in this order: Bulk Kundli Matching (
POST /v1/compatibility/batch), then Report Status and Download (GET /v1/reports/:id).