Skip to content

Crypto payments for API credits: build safe prepaid top-ups

Accept crypto payments for API credits without confusing payments with usage. Design top-up orders, a credit ledger, spending limits and refund controls.

API creditsPay, then use

To accept crypto payments for API credits, treat the payment and the service balance as separate records. The customer pays for a defined credit package or a server-approved top-up amount. Your application verifies payment, records the credit once, and controls how later API requests spend it.

This guide is for developers selling AI generation, data access or other metered services. It covers prepaid service units, not transferable tokens, a customer crypto wallet or an investment product. The credit ledger, usage meter and spending rules described below are recommended merchant-side controls, not built-in Yolfi features.

Choose prepaid credits rather than pretending every request is a payment

Prepayment separates a relatively infrequent purchase from frequent service use. A customer can buy a package, then make API requests against its remaining allowance. Your service still needs to define what one unit buys and what happens when the balance runs out.

Crypto payments for SaaS covers the wider choice between subscriptions and one-time sales. Here the purchase increases a service allowance; it does not by itself start a subscription or authorize future wallet debits.

Before launch, publish the unit definition, pricing, any expiry, refund rules and whether credits can be transferred. Explain limits and eligibility plainly. Do not market a closed-loop service allowance as money held for the customer. Legal, tax and consumer obligations depend on the product and jurisdiction; a payment integration does not resolve them.

Choose the collection flow for your top-up

Yolfi payment links suit a reusable fixed-price credit package. For a variable amount approved by your application, Yolfi's current API Checkout documentation explicitly includes top-ups among its use cases. Your server creates a Checkout Session with the final amount and currency; the buyer chooses from the payment methods currently available.

Offer Collection starting point Record in your application
A saved package with a fixed price Reusable Paylink Package version and promised service units
A customer-selected top-up within your limits Standalone Checkout Session Validated amount and agreed credit conversion
A fixed package needing per-attempt context Paylink-backed Checkout Session Package reference, account and payment attempt

Keep provider credentials on your server. Never let a browser choose the credited account, unit count or price without authorization and validation. The dynamic checkout pricing guide covers amount calculation and session-creation retries; this guide focuses on what happens to the service allowance afterward.

USDC and USDT can be familiar payment choices, but do not promise a particular asset and network from a generic coin page. Use the methods actually offered by the live payment configuration, and follow the Invoice's amount rather than assuming stablecoins always trade at exactly one dollar.

Save the credit agreement before payment

Create a top-up order tied to an authenticated account. Save the package or conversion version, promised units, amount, pricing currency and payment-attempt references. This is your commercial record; a blockchain transfer alone does not identify how much service the buyer purchased.

If you later change prices, preserve the earlier agreement for existing orders. Do not silently recalculate an already-paid package using today's rate. Keep promotional credits separate from purchased credits so expiry and refund treatment remain explainable.

Distinguish these records:

  • The top-up order says what the customer agreed to buy.
  • The payment attempt says how that purchase was collected.
  • The credit entry says which service units became available.
  • The usage entry says which request consumed or reserved those units.

Store exact quantities using integer service units or an exact decimal representation suited to your unit definition. Do not use binary floating point for balances. An internal credit unit is not a crypto token amount and should not share an ambiguous currency label.

Credit only after verified payment confirmation

Yolfi's Checkout lifecycle states that a Checkout Session marked COMPLETED is linked to an Invoice; payment may still be pending. A visit to a success URL is not proof of payment either. Fulfill only after verifying and processing payment.confirmed idempotently.

Bind the verified payment to the expected top-up order and account. Check the payment against the agreed purchase using the authenticated provider record. An account identifier supplied by a browser or public URL is not sufficient authorization to credit another account.

Within your own database, make the transition to a paid top-up and insertion of its purchased-credit entry atomic. Use a unique business reference so another delivery cannot add the same package twice. The webhook idempotency guide explains signature verification and duplicate-event handling; order-level protection is still needed when two distinct attempts pay for the same purchase.

A failed or partial payment must not create the full promised allowance automatically. Route unresolved amounts to the underpayment and overpayment process rather than guessing which package to grant.

Reserve units before running costly requests

A balance check followed by a later debit can overspend under concurrency. Several requests may all observe the same available units before any of them records usage.

Use an atomic reservation or debit enforced by your database. For work whose final cost is not yet known, reserve a defined maximum under your published rules, settle the measured cost once, and release unused units. If the service cannot reserve enough, reject or defer the request before starting paid upstream work.

Keep a stable request reference. A client retry should recover the same job or result where your API contract promises that behavior, not charge again simply because the HTTP response was lost. A deliberate new generation is different from a retry of an existing generation.

Define failure charging explicitly. If a worker crashes or an upstream service fails, reconcile the reservation against durable job state. Do not release reservations on a timer alone while work may still complete, and do not leave abandoned reservations locked indefinitely. Payment confirmation cannot solve these usage-accounting problems.

Keep an explainable ledger and refund boundary

Record purchased credits, promotional grants, reservations, settled usage, releases and adjustments as traceable entries. Preserve history with compensating adjustments instead of silently editing old entries. A cached balance can speed up reads, but it must reconcile with the underlying records.

Show customers separate purchase and usage histories. A crypto transaction proves a transfer; it does not explain which API requests consumed a prepaid allowance. Keep request identifiers and cost summaries, but avoid storing API secrets, prompts or personal data unnecessarily in the billing ledger.

Before approving a refund, check unused purchased units and any in-flight reservations. Prevent those units being spent while the refund is processed, and record the final adjustment with the refund reference. Do not automatically reverse the whole package after part has been consumed, or promise refunds without regard to your terms and applicable law. Follow the crypto refund checklist for the separate transfer and verification steps.

Test payment and usage failures separately

Test Expected application behavior
Browser opens the success page without paying No purchased credits appear
Same confirmed top-up is processed again Exactly one purchased-credit entry
Two requests compete for the last available units Atomic rules prevent spending beyond the allowed balance
Client retries after losing a job response Same logical request does not incur a duplicate charge
Worker fails after reserving units Durable job reconciliation settles or releases the reservation
Refund begins while usage is in progress Refundable units and active reservations cannot be spent twice

Also test account isolation: one customer's API key must not spend another customer's allowance by changing an account parameter. Set request limits and alert on unexplained ledger differences. These are application tests, not a claim that Yolfi provides a public sandbox, a metering engine or automatic refunds.

Frequently asked questions

Does accepting USDC mean my credits must be denominated in USDC?

No. Service credits and payment assets are different units. Define the purchased allowance and price clearly, then use the Invoice's current payment instructions. Do not imply a redeemable crypto balance unless that is genuinely your product and legally supported.

Does Yolfi meter API usage or maintain my credit balance?

This design does not rely on either feature. Yolfi documents payment collection and confirmation; your application implements the service ledger, usage measurement, reservations and access decisions.

Can I automatically top up from the customer's wallet?

Do not assume a previous payment authorizes another transfer. This prepaid flow asks the customer to make a new purchase when needed. Automatic spending would require a separately supported and explicitly authorized mechanism, not merely a saved payment reference.

What if the same customer makes two separate top-ups?

Two genuine purchases can both increase the balance. Deduplicate by the top-up order, not by customer account. If two payment attempts belong to one order, grant that order once and review the extra receipt separately.

Conclusion: collect once, account for every unit

Use a payment record to establish that a top-up was paid, and an application ledger to establish what remains usable. Keep price agreements, payment attempts and usage identities distinct; make both credit grants and spending safe under retries and concurrency. Start with Yolfi payment links for fixed packages or the documented API Checkout flow for variable top-ups, then build and test the service accounting in your own product.

Start accepting crypto payments today

Connect a wallet, create your first link and get paid in minutes.

Business owner working at a laptop
Payment received+120.00 USDT