Early accessWe're onboarding teams in batches. The sandbox and docs are open to everyone. Request access →

Skip to content
APIserver.in
Docs menu

Docs

Idempotency

Retry safely. A replayed request is never billed twice.

How it works

  • Send Idempotency-Key: <unique string> on any POST. Use one key per logical operation (a UUID is ideal).
  • Within 24 hours, the same key with the same body returns the original response — same request_id — with Idempotent-Replayed: true. It is not billed again.
  • The same key with a different body returns 400 VALIDATION_FAILED.
  • Keys are scoped to your API key.

Example

retry with backoff (Node)
import { randomUUID } from "node:crypto";

async function verifyGstin(gstin) {
  const key = randomUUID(); // one key for every retry of this operation
  for (let attempt = 0; attempt < 4; attempt++) {
    const res = await fetch("https://api.apiserver.in/v1/gst/verify", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.APISERVER_KEY}`,
        "Content-Type": "application/json",
        "Idempotency-Key": key,
      },
      body: JSON.stringify({ gstin }),
    });
    const body = await res.json();
    if (body.success || !body.error.retryable) return body;
    const wait = Number(res.headers.get("retry-after") ?? 0) * 1000 || 2 ** attempt * 250;
    await new Promise((r) => setTimeout(r, wait + Math.random() * 100));
  }
}