Usage metering
Bill a Consumer only after they approve the price and the server performs the billable action.
Fixed-price flow
- The browser calls
confirmCharge({ credits, reason }). - If
approvedis true, the browser sends the action through the SDK's session-awarefetch. - The server calls
mythos.charge(req, { credits, reason, idempotencyKey, consentId }). - The SDK returns
chargeIdandsessionMeteredTotal.
typescript
const { approved, consentId } = await confirmCharge({ credits: 1, reason: 'calculate' });
if (approved) await fetch('/api/calculate', {
method: 'POST',
body: JSON.stringify({ consentId }),
});
typescript
await mythos.charge(req, { credits: 1, reason: 'calculate', consentId });
Credits must be integers. Use a stable, client-generated idempotencyKey for retries of the same action; see Fixed-price charge.
LLM billing
Use mythos.llm to route an OpenAI client through the Mythos gateway, then inspect the completion with mythos.billing. See LLM chat.