x402 exact vs. upto: Designing Secure Payment Flows for Fixed-Price and Usage-Based APIs
When the final cost of an API request cannot be determined before execution, the traditional "quote first, pay later" process encounters a fundamental problem: How much should the client sign for? If the amount signed is too low, the request may be impossible to settle after execution; if it is too high, the authorized ceiling should not be mistaken for the actual charge.
Ace Data Cloud's x402 integration uses two billing schemes to handle these two types of requests:
exact: The price can be determined before request execution, and the signed amount is the final charge;upto: The client signs an acceptable spending ceiling, and settlement is based on actual usage after the request is completed, with the actual charge never exceeding the ceiling.
This article explains the differences between the two, the complete request flow, the prerequisites for Base upto Permit2, and the most common mistakes in production environments.
Capability Status (as of the time of writing)
Baseexact: Live / On-chain verification completed; Baseupto: Live / On-chain verification completed; SKALEexact: Live / On-chain verification completed; Solanaexact: HTTP paid retry verified. Currently, only Base supportsupto. During actual integration, always refer to the real-time402 acceptsreturned by the target request.
¶ What Does HTTP 402 Do in This Flow?
x402 is based on 402 Payment Required. When a client makes its first unpaid request to the target API, the server returns acceptable payment requirements; the client generates a signature based on the network, asset, billing scheme, and amount contained in the response, then retries with PAYMENT-SIGNATURE.
When using the official Ace Data Cloud SDK, the transport layer can automatically handle:
- Sending an unpaid request;
- Parsing
acceptsin the402response; - Calling the payment handler to generate a signature;
- Retrying once with
PAYMENT-SIGNATURE; - Returning the business response and settlement information.
Developers usually do not need to write a 402 retry state machine manually, but they must still understand whether they are signing for the "final amount" or the "maximum limit."
¶ exact: Whatever You Sign Is What You Pay
exact is used for scenarios where the cost can be determined before request execution, such as fixed-price image generation, video task creation, search or tool APIs, and order payments.
On EVM networks, exact uses USDC EIP-3009 TransferWithAuthorization. The Facilitator verifies the signature and amount during the /verify stage and submits the on-chain authorization during the /settle stage.
The core invariant is:
signed amount = final deduction
The client should treat the current request's accepts[].maxAmountRequired as the amount payable for that request, rather than copying historical numbers from documentation examples.
If the server can already determine the price when the request parameters are submitted, successful execution will not change the fee based on output length or execution time, and the client is willing to confirm the full amount before execution, exact should generally be used.
¶ upto: Sign a Ceiling and Settle Based on Actual Usage
For requests such as chat completions and streaming output, the actual token usage can only be determined after execution. upto allows the client to authorize a maximum spending limit first, then settle based on actual usage:
actual settlement <= signed ceiling
Base upto uses Permit2 PermitWitnessTransferFrom. The permitted.amount in the signature represents the ceiling, not a fixed transfer amount; after the request is completed, the gateway converts actual usage into a settlement amount and submits it to the Facilitator, which can only settle an amount that does not exceed the authorized ceiling.
The on-chain verification example in Ace Data Cloud documentation demonstrates this difference: the client signed a ceiling of 95215 atomic USDC, while the final actual settlement was only 3 atomic USDC. This example illustrates protocol behavior and does not mean that all requests will use the same ceiling or charge.
¶ Why Does upto Require Permit2 Approval?
Before using upto on Base for the first time, the payment wallet must authorize Permit2 to use Base USDC. The CLI method is as follows:
pip install 'acedatacloud-x402[cli]'
X402_PRIVATE_KEY=0x... acedatacloud-x402 approve-permit2 --network base
Programmatic method:
from acedatacloud_x402 import EVMAccountSigner, approve_permit2
approve_permit2(
rpc_url="https://mainnet.base.org",
signer=EVMAccountSigner.from_private_key("0x..."),
token_address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
)
Permit2 allowance is a prerequisite authorization, but every upto request still requires a new signature, because the nonce, deadline, witness, and spending limit all change. Private keys should never be written into frontends, logs, or repositories.
¶ How to Choose: Don't Hardcode Based on Service Type
The safest basis for choosing is not "this is chat, so it must use upto," but rather the current request's 402 accepts. Service capabilities, network support, and billing methods may change, so clients should read the real-time returned values.
| Request Characteristics | Recommended Scheme | Reason |
|---|---|---|
| Fixed-price image, video, search, and tool APIs | exact |
Final price is known before execution |
| Order payments | exact |
Payable amount has been determined |
| Token-based chat completions | Base upto |
Actual usage is only known after completion |
| Streaming responses | Base upto |
Output length is unknown in advance |
| Post-usage metering on SKALE | Currently unsupported | SKALE currently only provides exact |
| Permit2 approval not yet completed | Start with exact |
Reduces initial integration complexity |
If you use the TypeScript SDK and explicitly want to select the post-usage settlement scheme, you can configure preferScheme: 'upto'. Otherwise, the SDK will match the available payment requirements returned by the server under the selected network.
¶ Credits Are the Source of Cost, While x402 Is the Settlement Path
One conceptual confusion must be avoided: x402 is not an independent API pricing system parallel to Credits. Each API call still has a base cost expressed in Credits, and x402 converts that cost into on-chain USDC according to the platform exchange rate.
The conversion relationship provided in the current documentation is:
X402 price (USDC) = Credits cost × 0.095215
atomic = floor(Credits × 0.095215 × 1,000,000)
For exact, maxAmountRequired is the final amount payable; for upto, it is the maximum authorization limit, while the actual cost.amount in the successful response is the amount settled based on usage.
A production system should not hardcode model prices, contract addresses, or limits from the documentation. The correct approach is:
- Read
acceptsfrom the402response returned by each target request; - For
exact, read the amount payable for the current request; - For
upto, treatmaxAmountRequiredas the risk ceiling rather than a predicted bill; - Record the actual settlement value in the successful response for reconciliation.
¶ A Safer Client-Side Decision Process
The following pseudocode emphasizes "validate constraints first, then sign":
const response = await callWithoutPayment(request)
if (response.status !== 402) return response
const requirements = parseAccepts(response)
const choice = selectRequirement(requirements, {
allowedNetworks: ['eip155:8453'],
preferredScheme: request.isMetered ? 'upto' : 'exact',
maxAtomicUsdc: policy.perRequestCeiling,
})
assert(choice.asset === policy.expectedUsdcAsset)
assert(BigInt(choice.maxAmountRequired) <= policy.perRequestCeiling)
const signature = await wallet.sign(choice)
return retryOnce(request, signature)
There are four production-level constraints here:
- Network whitelist: Do not automatically sign for unknown chain IDs;
- Asset validation: Use the USDC address returned by the current 402 response and verify it against the expected network configuration;
- Per-request limit: Enforce local policy checks before signing with the wallet;
- At most one automatic retry: Avoid repeated signatures or payment loops caused by error states.
¶ Base upto Verification Checklist
Before signing, ensure that these fields come from the same 402 response and remain consistent:
networkis Base's CAIP-2 identifiereip155:8453;schemeisupto;extra.chainIdis8453;assetuses the Base USDC contract returned by that response;extra.facilitatorAddressis consistent with the witness and Facilitator support information;- The payment wallet has completed the Permit2 allowance for Base USDC.
¶ Three Common Errors and How to Handle Them
¶ PERMIT2_ALLOWANCE_REQUIRED
The wallet has not authorized Permit2 to use USDC on the target chain. Complete the approval for the correct network and asset, then submit the business request again. Do not bypass the prerequisite authorization through unlimited retries.
¶ invalid_upto_evm_payload_invalid_signature
Common causes include inconsistencies in the chain ID, Facilitator address, Permit2 domain, spender, signing account, or witness compared with the current 402 response. Discard the old response, retrieve a new 402 response, and ensure that all signature fields come from the same challenge.
¶ amount exceeds permitted amount
Actual usage exceeds the limit signed by the client. The policy layer should determine whether a higher limit is permitted and trigger a new explicit authorization; do not automatically increase the budget without limits in the background.
¶ Zero-Amount Settlement Is Not an Exception
upto supports an actual settlement amount of 0. For example, when the target API generates no billable usage, the gateway can submit amount = "0". The Facilitator returns success but does not create an on-chain transaction.
A failed business request should not automatically be equated with "a charge must have occurred on-chain." The reconciliation system should examine the business status, actual cost, and on-chain transaction together, rather than relying solely on whether a signature was created.
¶ Minimum Test Matrix Before Deployment
At a minimum, cover:
- Fixed-price request: 402 → signature → 200, with the quote matching the cost in the successful response;
- Usage-based request: Authorization limit greater than actual settlement;
- Insufficient balance;
- Permit2 not authorized;
- Expired signature;
- Network or asset mismatch;
- Actual usage exceeding the limit;
- Business failure with an actual settlement of 0;
- SDK performs only one paid retry;
- Reconciliation records can associate the request ID, cost, and on-chain transaction.
¶ Conclusion
exact addresses "how to make a one-time payment when the price is known," while upto addresses "how to authorize unknown final usage within a budget limit." The difference between them is not syntax but the risk model: the former confirms the final amount, while the latter confirms the maximum exposure.
The key to a secure implementation is not blindly automating payments, but ensuring that every signature passes network, asset, per-request limit, and retry policy checks, and using the real-time 402 response as the sole basis for signing.

