Skip to main content

Documentation Index

Fetch the complete documentation index at: https://neverminedag-docs-auto-order-x402.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

By default, subscribers purchase a plan first and then generate an access token. Auto-order removes the manual purchase step: when you call getX402AccessToken / get_x402_access_token with a delegation and the subscriber has no credits, the system purchases credits for the plan automatically before returning the token.

Manual flow vs. auto-order

// Manual flow — check balance, order if needed, wait for settlement
const balance = await payments.plans.getPlanBalance(planId)
if (Number(balance.balance) <= 0) {
  await payments.plans.orderPlan(planId)
  await new Promise(resolve => setTimeout(resolve, 5000)) // wait for on-chain confirmation
}
const { accessToken } = await payments.x402.getX402AccessToken(planId, agentId, {
  delegationConfig: { spendingLimitCents: 10000, durationSecs: 604800 }
})

// Auto-order — one step: if no credits, the system purchases them automatically
const { accessToken } = await payments.x402.getX402AccessToken(planId, agentId, {
  delegationConfig: { spendingLimitCents: 10000, durationSecs: 604800 }
})
The code is identical — the difference is that with a delegation in place you can skip the explicit order_plan / orderPlan call. If the subscriber already has credits the token is returned immediately; if not, the purchase happens first.

Setting up the delegation

The delegation authorizes the system to spend on the subscriber’s behalf. The two required fields when creating a new delegation are:
FieldDescription
spendingLimitCentsTotal spending cap for this delegation’s lifetime, in cents. 10000 = $100.
durationSecsHow long the delegation is valid in seconds. 604800 = 7 days.
For long-running agents, create the delegation once and reuse its ID across requests:
// Create once
const delegation = await payments.delegation.createDelegation({
  provider: 'erc4337',
  spendingLimitCents: 50000, // $500 total budget
  durationSecs: 2592000       // 30 days
})

// Reuse across all requests — spending tracked cumulatively
const { accessToken } = await payments.x402.getX402AccessToken(planId, agentId, {
  delegationConfig: { delegationId: delegation.delegationId }
})

Fiat plans (nvm:card-delegation)

Auto-order works the same way for card-delegation plans. If the subscriber has no credits, the system creates a Stripe charge automatically when get_x402_access_token is called. The spendingLimitCents in the delegation controls the total charge ceiling. See Fiat Payments and Nevermined Pay for how to enroll a card.

When auto-order stops

ConditionWhat happens
Delegation spendingLimitCents exhaustedPurchase is rejected. Token generation fails with a payment error.
Delegation expired (durationSecs elapsed)Delegation is invalid. Token generation fails.
Subscriber wallet has insufficient token balance (crypto)On-chain purchase fails. Token generation fails.
In A2A pipelines, handle token generation failures explicitly. When a delegation is exhausted or expired, surface a clear payment error to the orchestrator rather than retrying indefinitely.

Next steps

Stablecoin Payments

Understand the crypto payment model and how delegations work on-chain

Fiat Payments

Accept cards via Stripe or Visa with per-request auto-charging

Nevermined x402

Deep dive into the x402 protocol, session keys, and settlement flow

A2A Monetization

Build autonomous agent pipelines with built-in payment rails