Sample Javascript client

const API_KEY = process.env.ANDUIN_API_KEY;
const MAX_RETRIES = 3;
const BASE_DELAY_MS = 500;

async function callAPI(path, options = {}) {
  const url = `https://api.anduintransact.com${path}`;

  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
    const response = await fetch(url, {
      ...options,
      headers: {
        Authorization: `Bearer ${API_KEY}`,
        "Content-Type": "application/json",
        ...options.headers,
      },
    });

    if (response.status !== 429) return response;
    if (attempt === MAX_RETRIES) break;

    const delay = BASE_DELAY_MS * 2 ** attempt +
      Math.random() * BASE_DELAY_MS * 0.5;
    console.warn(
      `[retry] ${path} returned 429 — attempt ${
        attempt + 1
      }/${MAX_RETRIES}, retrying in ${Math.round(delay)}ms`,
    );
    await new Promise((r) => setTimeout(r, delay));
  }

  throw new Error(
    `${path}: still receiving 429 after ${MAX_RETRIES + 1} attempts`,
  );
}

async function callAPIInBatches(items, fn, batchSize = 5) {
  const results = [];
  for (let i = 0; i < items.length; i += batchSize) {
    const batch = items.slice(i, i + batchSize);
    results.push(...(await Promise.allSettled(batch.map(fn))));
    // Ease pressure on the API between batches to reduce 429s
    if (i + batchSize < items.length) {
      await new Promise((r) => setTimeout(r, 300));
    }
  }
  return results;
}

// --- Usage ---

async function main() {
  const dealIds = ["deal_1", "deal_2", "deal_3", "deal_4", "deal_5", "deal_6"];

  // Option 1: Sequential — safest for heavy endpoints (order creation, bulk operations)
  for (const id of dealIds) {
    await callAPI(`/v2/deals/${id}`, { method: "GET" });
  }

Did this page help you?