Skip to content
Resvary. 1.3.0 stable
Menu
Explore the ledger

Prepaid credits and usage billing for AI products

Open source · 1.3.0 stable

Reserve a maximum cost before an AI job runs. Charge the actual usage when it finishes. Release the rest and give users an auditable receipt.

Apache-2.0 TypeScript · Embedded SDK Postgres deployment backend
01 / Problem

AI usage has a timing problem

You must decide whether a customer can start an AI request before the final cost exists. Tokens, seconds, images, and tool calls arrive after the provider finishes.

Resvary checks available credits and creates a reservation before provider work begins. It commits the final charge after execution and releases the unused amount.

  • 01Concurrent jobs can spend the same apparent balance.
  • 02A retried request can create a duplicate charge.
  • 03Failed jobs can leave credits locked without an explicit release.
  • 04Mutable prices make old charges hard to explain.
  • 05A balance snapshot cannot show why the number changed.
02 / Credit lifecycle

One lifecycle from authorization to receipt

Fund → Reserve → Execute → Commit → Release → Receipt
STEP 01

Fund the account

Grant credits manually, from a direct Arc USDC transfer, or from a Circle Gateway Nanopayment. All three fund the same ledger.

STEP 02

Reserve the maximum cost

Rate the estimated usage against an immutable price version and hold that amount before expensive work begins.

STEP 03

Run the AI operation

Call a model, agent, generation pipeline, tool, or batch worker with your existing provider stack.

STEP 04

Commit actual usage

Rate the provider's final usage, charge it once, and release the unused part of the reservation in the same transaction.

STEP 05

Record the result

Store an immutable ledger entry, usage receipt, idempotency result, and outbox event for reconciliation.

03 / Why Resvary

The credit boundary around each AI call

Authorize spend before execution

Resvary checks available credits and creates an atomic reservation before your application starts provider work. Overlapping requests cannot reserve the same credits twice when the store supplies the required transaction isolation.

Charge once across retries

Every mutating command requires an idempotency key. Replaying the same key and payload returns the original result. Reusing the key with different input raises a conflict.

Explain each balance change

Immutable ledger entries and per-charge usage receipts record the price version, line items, amount charged, amount released, and balance after the operation.

Keep payment rails separate from usage

The credit lifecycle does not depend on an AI provider. Manual grants, direct Arc USDC transfers, and Circle Gateway Nanopayments all fund the same ledger without changing usage accounting.

Usage receipt

Each commit records its own explanation

The usage receipt records the price version, line items, final charge, released credits, and resulting balance. Your team can trace each balance change without reconstructing it from logs.

Resvary ledger 1.3.0 stable
✓ Reserving credits
Resvary · usage receipt 1.3.0 stable
RECEIPTrcp_8f42c1
ACCOUNTacct_studio_04
METERtokens.chat
PRICE VERSIONpv_7
INPUT · 18,400 tok0.055200
OUTPUT · 2,440 tok0.073200
RESERVED$0.400000
CHARGED$0.128400
RELEASED$0.271600
BALANCE AFTER$4.871600
IDEMPOTENCY req_5c9d0e7a3b COMMITTED 2026-08-14 09:41:02Z LEDGER le_1183 · le_1184
04 / Usage pricing

Price the usage your provider returns

A meter can rate one or more integer dimensions. Each immutable price version keeps old receipts tied to the rates used at the time of the charge.

Version 1.3.0 supports linear, graduated, and package price components with integer-only rating. Package pricing charges each started block and does not create reusable entitlements.

LLM chat
input tokens · output tokens
Image generation
images · compute seconds
AI agents
tool calls · steps · runtime
Speech and video
seconds · minutes processed
Batch jobs
items · pages · completed jobs
Developer APIs
requests · domain-specific units
05 / TypeScript SDK

Wrap each provider call in a metered lifecycle

runMetered reserves estimated usage, runs your provider callback, commits the final charge, and returns the released amount with a receipt.

Install the local stack npm install @resvary/sdk @resvary/sqlite
metered-request.ts
import { CreditLedger } from '@resvary/sdk/credits';
import { createSqliteCreditStore } from '@resvary/sqlite';

const credits = new CreditLedger({
  projectId: 'my_ai_product',
  store: createSqliteCreditStore({
    path: '.resvary/resvary.sqlite',
  }),
});

const result = await credits.runMetered(
  {
    customerId: 'customer_123',
    priceId: 'price_llm_v1',
    estimatedUsage: {
      input_tokens: '2000',
      output_tokens: '1000',
    },
    idempotencyKey: 'request_abc',
  },
  async () => {
    const completion = await callModel();

    return {
      value: completion,
      usageEventId: completion.id,
      actualUsage: {
        input_tokens: String(completion.usage.inputTokens),
        output_tokens: String(completion.usage.outputTokens),
      },
    };
  },
);

console.log(result.receipt.amount);
console.log(result.receipt.releasedAmount);

If the provider throws, runMetered releases the full reservation. Save the provider result and usage before committing. If the commit fails, retry only the commit with the same key while the reservation remains open and unexpired. An expired reservation is released and requires reconciliation; do not rerun the provider.

Install the 1.3.0 packages from npm. Use @resvary/sdk with @resvary/sqlite locally; add @resvary/postgres and @resvary/worker for multi-process deployments.

06 / Demo

Inspect the credit lifecycle in one place

The published ledger is a read-only preview and needs no AI key. Enter the admin token from your own deployment to run grants, usage, replay, failure, and funding scenarios. The separate buyer-agent prototype has an archived Testnet proof; its current source supports explicit Mainnet configuration.

Explore the ledger → Review the archived Testnet proof →
Demo actions
  • Grant $5 in development credits
  • Run a simulated AI operation
  • Replay the same request
  • Simulate provider failure
  • Simulate an Arc Testnet funding confirmation
Data exposed
  • Posted, reserved, and available balances
  • Reservation status
  • Actual charge and released amount
  • Price line items
  • Immutable ledger history
  • Usage receipts
  • Transactional outbox events
  • Signed event headers
07 / Use cases

Add prepaid credits to variable-cost AI workloads

AI SaaS

Sell prepaid product credits while keeping subscriptions, checkout, and invoices in your existing billing stack.

AI APIs

Authorize requests before execution and reconcile each customer charge to provider usage.

Agent platforms

Reserve a budget for an agent run, then charge for its final steps, tools, tokens, or runtime.

Generation products

Rate images, audio, video, or batch jobs with units that match your provider costs.

Paid developer tools

Give teams auditable credit balances and retry-safe usage charges without building a ledger from scratch.

08 / Transactions

Balance changes stay inside one transaction

Each balance-changing command validates idempotency, checks the account and lifecycle state, writes ledger entries, updates the account snapshot, stores the domain record and outbox event, and saves the command result before commit.

The SQLite store uses BEGIN IMMEDIATE to serialize competing writers. It stores balances, reservations, receipts, idempotency results, and outbox events across restarts.

SQLite supports local and single-node deployments. Multi-process deployments should use the bundled Postgres adapter with explicit migrations, serializable transactions, and a separate outbox worker.

Balance definitions
Posted Granted credits minus committed charges
Reserved Credits held by open reservations
Available Posted minus reserved
Circle-native funding

Direct Arc USDC and Circle Gateway Nanopayments are first-class funding paths. Each external payment becomes one funding transaction and one credit grant, keyed by rail + network + external payment ID. Usage accounting remains payment-rail agnostic.

Arc invoice → memo proof → payment receipt → funding confirmation → credit grant
A payment receipt proves which external transfer funded an account. A usage receipt explains why product credits were charged.

Arc adapters support explicit Mainnet and Testnet configuration. Mainnet funding moves real USDC and requires application-level controls.

09 / Operator Console

Explain every balance. Recover known ledger incidents safely.

A self-hosted command ledger for one Resvary project. Search customers, trace a charge through its receipt and price version, and run only the recovery actions the ledger can prove are safe. The panel uses synthetic data to illustrate the interface.

Operator ConsoleIllustrative preview
Available$12,375.60
Overdue1
Dead letter1
Overview + Customers

Balances, lots, grants, reservations, funding, receipts, and one chronological customer record.

Audit Explorer

Charge → receipt → reservation → price → ledger entries, with the original JSON intact.

Guarded operations

Positive grants, reasoned adjustments, overdue expiry sweeps, and dead-letter requeue only.

Self-hosted boundary

Postgres in production, SQLite for local and single-node use. No outbound telemetry.

One instance / one projectSynthetic example data
10 / Get started

Install version 1.3.0. Run it in your stack.

The Apache-2.0 packages are published on npm. Use SQLite locally or on one node; use Postgres and the worker for multi-process deployments. The Operator Console, signed webhooks, and explicit Mainnet and Testnet funding adapters ship with the self-hosted release.

Not included Hosted cloud, enterprise SLA, tax invoices, custody, and transferable or redeemable balances.
11 / FAQ

Questions engineers ask first

Is Resvary a payment processor?

No. Resvary manages closed-loop product credits and usage authorization. Keep checkout, subscriptions, tax, and fiat payment processing in the systems you already use.

Does Resvary replace Stripe Billing, Lago, or Orb?

Resvary handles the real-time credit boundary around an AI operation. A broader billing platform can continue to handle checkout, subscriptions, invoicing, or finance workflows.

Why reserve credits before the AI request?

The final provider cost arrives after execution. A reservation prevents concurrent requests from spending the same available balance while keeping the final charge tied to actual usage.

What happens when the provider fails?

runMetered releases the reservation and keeps the execution claim when the callback throws. Start a new operation only after confirming the provider did not complete the first one.

What happens if commit fails after the AI request succeeds?

Save the provider result and usage. Retry the commit with the same idempotency key only while the reservation remains open and unexpired. Expired reservations require reconciliation. Do not repeat the provider call.

Can an actual charge exceed its reservation?

No. Your application must create another reservation before continuing work that needs a higher limit.

Can I use my existing AI provider?

Yes. The core ledger does not depend on a model vendor. Your application passes estimated and actual usage into the SDK.

Do I need crypto or Arc to use Resvary?

No. Manual grants work without a blockchain. Direct Arc USDC and Gateway Nanopayments are optional Mainnet or Testnet funding adapters; neither changes the usage ledger.

Is SQLite production-ready?

SQLite targets local and single-node deployments. Use the Postgres deployment backend for multi-process deployments.

Are credits transferable or redeemable?

No. Resvary models non-transferable, non-redeemable product credits that customers use inside one merchant project.

Is a usage receipt a tax invoice?

No. A usage receipt explains an operational credit charge. Each merchant remains responsible for its customer terms, refund policy, privacy notice, invoices, and tax treatment.

Is Resvary free to use?

The current code is available under the Apache-2.0 license. No hosted paid plan exists yet.

How do I try Resvary?

Inspect the published read-only ledger without an AI key, or install the SDK and follow the getting-started guide.

Add a retry-safe credit ledger to your next AI request

Inspect the lifecycle in the published ledger, then evaluate the open-source SDK inside your application.