Developer docs · Browse & search
OPERATE

Recovery, diagnostics and usage

Cancel, retry or rerun many runs at once, see what went wrong, and report usage per customer.

Recovery and diagnostics

ts
const job = await jwtson.recovery.start('retry', failedRunIds); // up to 100
await jwtson.recovery.compare([a, b]);                         // side by side, no model call
const failures = await jwtson.diagnostics.failures({ days: 7 }); // failed runs grouped by what went wrong
await run.tag('flaky'); await jwtson.runs.list({ tag: 'flaky' }).toArray();

A job acts on each run as it was when you decided. To make one survive your own restart, prepare it, save it with your record, and send the saved copy:

ts
const request = await jwtson.recovery.prepare('cancel', [{ id: run.id, revision: seen.revision }], { reason: 'incident_response' });
await db.save('incident-42', request);                    // plain JSON
await jwtson.recovery.start(await db.load('incident-42')); // again after a restart: the same job, nothing done twice

A run that moved on since the revision you gave is reported as changed, not acted on.

Usage, for rebilling your customers

ts
const november = await jwtson.usage.byAudience({ month: '2026-11' });
// [{ audience: 'acme', runs: 66, inputTokens: 660, outputTokens: 330, tokens: 990, estimate: true }, …]
const report = await jwtson.usage.report({ by: 'user', from: '2026-11-01', to: '2026-12-01' });

You can group usage by app, audience, group, user or agent. Give the period as the last days, a calendar month, or from to to, where to is the day after the last one counted.

The only line counted today is AI usage, and its tokens are an estimate. Store compute, database storage and channel messages arrive with the usage ledger. Totals are about a minute behind.

From the @jwtson/sdk README, as the code stands.