Skip to main content
Last updated on
Advanced — 0.0.x primitives

You don't need this page for a normal integration. Use the quickstarts and createMythos() instead. These low-level functions remain exported for custom setups.

reportUsage

Debit the Consumer's Mythos wallet after a billable action.

Signature​

typescript
function reportUsage(
jti: string,
opts: { credits: number; reason?: string; idempotencyKey?: string },
): Promise<void>

Parameters​

ParamTypeRequiredDescription
jtistringYessessionJti from launch session
opts.creditsnumberYesCredits to debit
opts.reasonstringNoHuman-readable reason for analytics
opts.idempotencyKeystringNoCaller-supplied dedup key sent as charge_id. Same key on retry avoids double-billing. Defaults to a fresh UUID per call. See Idempotency.

Returns​

Promise<void> — resolves on success.

Throws​

ErrorHTTP equivalentCause
InsufficientFundsError402Consumer wallet empty
SessionNotFoundError404Invalid session JTI
Error503Other Mythos API failure

Internal behavior​

Sends POST /api/apps/sessions/{jti}/meter with charge_id set to opts.idempotencyKey if provided, otherwise a fresh UUID per call. See Idempotency.

Example​

typescript
await reportUsage(req.mythos.sessionJti, { credits: 1, reason: 'page-view' });

// Retry-safe: same idempotencyKey on retry won't double-charge.
await reportUsage(req.mythos.sessionJti, { credits: 1, reason: 'page-view', idempotencyKey: postId });

See also​