Guide

Handle OneLifeVibe rate limits and retries in Node.js

Call the Platform API with Retry-After, jittered backoff and a clear stop on errors a retry cannot fix.

Stack
Node.js 18+ (fetch)
API
Platform API v1 · Connectors

The code

// Platform API calls with Retry-After, jittered backoff, and stop on errors a retry cannot fix.
const RETRY = new Set(['rate_limited', 'world_unreachable', 'internal_error', 'unavailable']);

export async function callTool(key, name, args, attempts = 5) {
  for (let i = 0; i < attempts; i++) {
    const res = await fetch(`https://onelifevibe.com/api/platform/v1/tools/${name}`, {
      method: 'POST',
      headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
      body: JSON.stringify({ arguments: args }),
    });
    if (res.ok) return res.json();
    const { error } = await res.json();
    if (error.code === 'quota_exceeded') throw new Error('daily quota used: buy a call pack or wait for 00:00 UTC');
    if (!RETRY.has(error.code)) throw new Error(`${res.status} ${error.code}: ${error.message}`);
    const retryAfter = Number(res.headers.get('retry-after'));
    const wait = Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter * 1000 : Math.min(30_000, 500 * 2 ** i);
    await new Promise((r) => setTimeout(r, wait + Math.random() * 250));
  }
  throw new Error(`${name}: gave up after ${attempts} attempts`);
}

The facts it relies on

Related guides

Try it against the real API. A free Sandbox key reads the catalogue and the event log at once, no card.

Get a free key Read the docs