← Back to Discover

Resvary

Resvary is an open-source TypeScript software development kit (SDK), released under the Apache-2.0 license, for prepaid credits and usage billing in AI products.

Libraries & SDKs

What it does

Resvary manages prepaid, closed-loop product credits for AI products. Manual grants, direct Arc USDC transfers, and Circle Gateway Nanopayments all fund the same ledger. The application wraps each provider call in runMetered. Resvary checks available credits and reserves the estimated maximum cost against an immutable price version. The application's callback then runs the AI operation with its existing provider stack. Resvary rates the provider's final usage and charges it once. It releases the unused part of the reservation in the same transaction. It stores an immutable ledger entry, a usage receipt, an idempotency result, and an outbox event. If the provider throws, runMetered releases the full reservation.

Capabilities

  • Every mutating command requires an idempotency key. Replaying the same key and payload returns the original result, and reusing the key with different input raises a conflict.
  • Version 1.3.1 supports linear, graduated, and package price components with integer-only rating.
  • Each usage receipt records the price version, line items, final charge, released credits, and resulting balance.
  • SQLite serves local and single-node deployments. Multi-process deployments use the bundled Postgres adapter with a separate outbox worker.
  • A self-hosted Operator Console searches customers, traces charges through receipts and price versions, and reconciles saved operation results without repeating the AI call.

When to use it

  • Use it to add prepaid credits to an AI SaaS product while keeping subscriptions, checkout, and invoices in an existing billing stack.
  • Use it to reserve a budget for an agent run and then charge for its final steps, tools, tokens, or runtime.
  • Use it to authorize AI API requests before execution and reconcile each customer charge to provider usage.