DFINITY
Console
On this page
Documentation · API reference Candid · Internet Computer

API reference

Buy cycles from code by calling CyclePay's canisters: a card order paid on a Stripe Payment Link, or ck-USDC paid straight to the backend canister. Prices, order status, balances and history are queries.

Backend canister
2bwus-iiaaa-aaaac-bee3a-cai

On mainnet, through https://icp-api.io, with any IC agent. Public queries need no identity (with icp-cli, pass --identity anonymous); a purchase is signed by the buyer's identity. See Calling the canisters.

There is no REST API.

CyclePay runs entirely on Internet Computer canisters. Call the methods on this page with Candid; the site at https://www.cyclepay.org serves only pages, and a /v1 request there gets this site's HTML, not JSON.

Calling the canisters

Candid calls, signed by the buyer.#

Every method below is a Candid query or update on a canister on mainnet. A query answers at once and changes nothing; an update goes through consensus. Public queries (prices, the terms of a ck-USDC payment, a Checkout Session's status) take the anonymous identity: with icp-cli, pass --identity anonymous, or it signs with your default identity, which may stop to ask for its password (and, with no terminal to ask in, fail). A purchase is an update signed by the buyer's identity, and the order or payment belongs to that principal. A card order's details are read by its owner, by the backend's controllers (CyclePay's operators) and by the canisters they allow to read, such as the console, which shows a project's orders to the project's members. A ck-USDC payment's status (topup_ckusdc_status) answers its payer only; the order its delivery records is readable by the same controllers and canisters. The anonymous principal cannot buy.

From a terminal, icp identity link web cyclepay --app 4w3yu-fyaaa-aaaac-beeoa-cai.icp0.io signs icp-cli in with Internet Identity as the same principal this site shows you (see the CLI quick start), so what you buy with --identity cyclepay shows up under My purchases here. Any other identity works too, and owns what it buys. In a browser, Internet Identity gives each website its own principal, so a sign-in on another site is a different buyer. With icp-cli 1.7.0 or later, icp cycles buy makes a card order for the identity and waits for it in one command (see Examples).

A query from JavaScript (@icp-sdk/core)
// npm install @icp-sdk/core, then run this as an ES module (a .mjs file,
// or "type": "module" in package.json): it awaits at the top level.
import { Actor, HttpAgent } from '@icp-sdk/core/agent';

// Anonymous for public queries; pass { identity } to sign purchases.
const agent = HttpAgent.createSync({ host: 'https://icp-api.io' });

// Only the fields you read: Candid decodes a record into a smaller one.
const backend = Actor.createActor(({ IDL }) => IDL.Service({
  get_xdr_rate_status: IDL.Func([], [IDL.Record({ xdr_usd_x10000: IDL.Nat64 })], ['query']),
}), { agent, canisterId: '2bwus-iiaaa-aaaac-bee3a-cai' });

const { xdr_usd_x10000 } = await backend.get_xdr_rate_status();
const usdPerXdr = Number(xdr_usd_x10000) / 10_000; // 1T cycles costs this
Prices

The rate every order is priced at.#

query get_xdr_rate_status # backend · public

get_xdr_rate_status : () -> (XdrRateStatus) query. The USD price of one XDR (the IMF's Special Drawing Rights, a basket of currencies) the backend prices every order with, refreshed from the Exchange Rate Canister every 6 hours. 1T cycles (T is a trillion) costs 1 XDR, set by the protocol, so an order mints net_usd / (xdr_usd_x10000 / 10000) trillion cycles. net_usd is the whole amount for ck-USDC, and for a card the amount minus Stripe's fee of 2.9% plus $0.30, rounded to the cent: $25 funds $23.98. The CMC's ICP/XDR rate cancels out: the backend buys the ICP at it and the CMC mints at it. A Cycles Ledger delivery is 0.0002T less (two Cycles Ledger fees). CyclePay adds no fee.

Returns, among other fields
xdr_usd_x10000
nat64 USD per XDR times 10,000: for example, 13520 is $1.352. The rate moves, so read it for every quote.
source
variant { Xrc; Legacy; Manual } Xrc: read from the Exchange Rate Canister; Manual: set by an operator
updated_at
opt nat64 when it was set, in seconds
stale
bool no set time, or older than 24 hours
Card

Pay by card on a Payment Link.#

query get_card_terms # backend · public

get_card_terms : () -> (CardTerms) query. Everything a client needs to buy by card, from the backend itself: the Payment Link, the order limits, the card fee and the Cycles Ledger delivery fee. Read it before create_order to quote and to check the amount; a client that implements get_xdr_rate_status, get_card_terms, create_order and order_status against another canister id is pointed at that gateway with nothing else to know.

Returns
payment_link
text the signed-in Payment Link, https://buy.stripe.com/6oU7sLg7t4ih4LtgwX3VC00 today, for information: a query is one replica's answer, so pay on the payment_url that create_order (an update the subnet agrees on) returns, this link with the order's reference and amount
min_order_usd_cents, max_order_usd_cents
nat64 $1 to $200; outside them create_order answers AMOUNT_OUT_OF_RANGE
fee_bps, fee_fixed_usd_cents
nat64 the card fee, 290 and 30 (2.9% plus $0.30): fee = amount * fee_bps / 10_000 + fee_fixed_usd_cents, rounded to the cent as the backend rounds, gives net_usd_cents
ledger_delivery_fee_cycles
nat taken off a delivery to a Cycles Ledger account: two ledger fees, 200_000_000 (0.0002T); a canister top-up pays none
deliveries_paused
bool while true, create_order refuses every order: PAUSED or CARDS_UNAVAILABLE
update create_order # backend · signed

create_order : (CreateOrderArgs) -> (variant { Ok : CreatedOrder; Err : OrderError }). Makes a card order owned by the caller. Pay it by opening its payment_url: CyclePay's Payment Link (get_card_terms) with the order's client_reference_id, https://buy.stripe.com/6oU7sLg7t4ih4LtgwX3VC00?client_reference_id=<client_reference_id>&prefilled_amount=<amount_usd_cents>. Stripe's page lets the buyer change the amount within $1 to $200, and the cycles are delivered for what is paid. Asking again with the same destination, amount and project while the order is unpaid and less than an hour old returns the same order; after that, or once it is paid, a new one is made. An unpaid order expires at expires_at; a second payment of a paid order is refunded.

Argument
destination
variant { Canister : principal; Ledger } required a canister to top up, or a Cycles Ledger account
beneficiary
opt principal Ledger only: whose account is credited (default: the caller); the order stays the caller's
escrow_spender
opt principal Ledger only, no beneficiary: the flow for an agent on the ICP MCP, which makes no ledger transaction of its own. The cycles are held in an escrow account (CyclePay's, with escrow_principal or the caller's principal padded as subaccount), approved to this principal for a month with icrc2_approve; what it leaves goes back to the caller once the allowance expires. Three ledger fees instead of two
escrow_principal
opt principal with escrow_spender: the principal the escrow account's subaccount is padded from (as the CMC pads one), for a spender that knows the buyer by another principal than the caller's here: the one it signs them in under on its own origin. Default: the caller. One buyer per account until its leftover is swept
amount_usd_cents
nat64 required 100 to 20000 ($1 to $200)
project_id
opt text a console project the caller has a role in; its members see the order
confirm_system_canister
opt bool opt true to top up a known system canister after the buyer confirms; see destination checks
Returns (Ok)
order_id
text
payment_url
text where to pay: open it for the buyer as it is
client_reference_id
text o_<order_id>: what the Payment Link URL carries
amount_usd_cents
nat64
net_usd_cents
nat64 what the payment funds after Stripe's fee
destination
variant { Canister : principal; Ledger : principal }
expires_at
nat64 seconds; unpaid by then, the order is forgotten
escrow
opt EscrowView an escrowed order: the account the cycles wait in and the spender; order_status adds the allowance, its expires_at and swept_at once the leftover went back to the caller
query order_status # backend · the order's owner

order_status : (text) -> (opt OrderStatusView), by order_id. Null for anyone but the order's owner, the backend's controllers (CyclePay's operators) and the canisters they allow to read, such as the console. Poll it every second or few while the buyer pays, until Delivered, Refunded, RefundOwed or NeedsReview; an order still AwaitingPayment after its expires_at has expired (null once it is forgotten). A payment the backend refuses (over the limit for one order, say) shows as the order's Refunding, Refunded or RefundOwed, with no paid_usd_cents and its detail saying why but not what was paid; the order stays payable until its expires_at, since whoever paid the link may not be its owner.

Returns, among other fields
status
AwaitingPayment, PaymentPending, Processing, Delivered, NeedsReview, Refunding, Refunded, RefundOwed PaymentPending: a delayed payment method not settled yet; NeedsReview: stopped for an operator and not refunded meanwhile; RefundOwed: an operator refunds it by hand
cycles_delivered
opt nat64 in cycles, not T: 17_730_000_000_000 is 17.73T
paid_usd_cents
opt nat64 what was paid, once paid
amount_refunded_usd_cents
nat64
detail
opt text why delivery waits or stopped, or why a refund is owed
destination
variant { Canister : principal; Ledger : principal }
link /c/<canister id>/<usd> # no sign-in · $5 to $100

A card payment of $5 to $100 needs no identity and no canister call. Send the buyer to https://www.cyclepay.org/c/<canister id>/<usd> to top up a canister, or https://www.cyclepay.org/b/<principal>/<usd> to credit that principal's Cycles Ledger account; the path may be in any case, for QR codes. The Buy page shows that destination's full ID beside Pay and opens CyclePay's guest Payment Link for it when the buyer taps Pay, never by itself. The buyer pays on Stripe's page, and Stripe brings them back to /?status=success&session=<Checkout Session id>, which follows the payment to delivery and names the kind of destination only: anyone who holds a session id can open that page. The order belongs to no principal. Every payment of such a link is a purchase of its own, delivered in full: offer the buyer one way to pay it (a QR code or a link to open), and tell them to pay once. Over $100, the page asks the buyer to sign in. The long forms are /?dest=canister&to=<canister id>&usd=<1..200> and /?dest=ledger&to=<principal>&usd=<1..200>.

query order_status_by_session # backend · public

order_status_by_session : (text) -> (opt PublicOrderStatus), by the Checkout Session id Stripe returns (cs_live_...). Anyone holding the id can read it, and it says nothing about the buyer. Null until Stripe's payment has reached CyclePay.

Returns
status
as order_status
amount_usd_cents
nat64
cycles_delivered
opt nat64 in cycles, not T
destination_kind
variant { Canister; Ledger } the kind only, not the ID
detail
opt text for Refunding, Refunded and RefundOwed only: why the payment was not delivered, in plain words with no ids
ck-USDC

Pay with ck-USDC, straight to the backend.#

query get_ckusdc_terms # backend · public

get_ckusdc_terms : () -> (CkUsdcTerms) query. What to approve and how much may be paid. ck-USDC has 6 decimals: 1_000_000 atoms is $1.

Returns, among other fields
spender
record { owner : principal; subaccount : opt blob } the account to approve: the backend canister, no subaccount
ledger
principal the ck-USDC ledger, xevnm-gaaaa-aaaar-qafnq-cai
fee_atomic
nat64 the ledger's fee as last read (fee_read_at), 10_000 today (0.01 ck-USDC)
min_amount_atomic, max_amount_atomic
nat64 $1 to $200
step_atomic
nat64 amounts are multiples of this (1 cent)
update icrc2_approve # ck-USDC ledger · signed

On the ck-USDC ledger (xevnm-gaaaa-aaaar-qafnq-cai), from the identity that will pay: approve spender for amount_atomic + fee_atomic, the amount plus the fee of the pull. The approve costs one more fee, so a $25 payment costs 25.02 ck-USDC. Set expires_at to keep an unused approval from lingering. From icp-cli 1.4.0 on, icp token xevnm-gaaaa-aaaar-qafnq-cai approve 25.01 2bwus-iiaaa-aaaac-bee3a-cai --expires-in 10m makes this approve, in whole ck-USDC, with expires_at 10 minutes on.

update topup_ckusdc # backend · signed by the payer

topup_ckusdc : (TopupCkUsdcArgs) -> (variant { Ok : CkUsdcPayment; Err : TopupCkUsdcError }). Pulls amount_atomic from the caller's ck-USDC account with icrc2_transfer_from and delivers the cycles, usually before it returns. One call per caller at a time.

Argument
request_id
text required 1 to 64 characters of A-Z, a-z, 0-9, - and _: fresh per purchase (a uuidgen UUID fits) and the same on every retry of it; a retry reports that payment and never pays it twice
amount_atomic
nat required 1_000_000 to 200_000_000, a multiple of 10_000
destination
variant { Canister : principal; Ledger } required
beneficiary
opt principal Ledger only; defaults to the caller
project_id
opt text a console project the caller is a member of
confirm_system_canister
opt bool
Returns (Ok), among other fields
status
Delivered, Pulling, Pulled, Fulfilling, Deferred, Rejected, Refunding, Refunded Delivered: done; Pulling, Pulled and Fulfilling finish on a timer; Deferred: the ck-USDC is in and waits for the buyer's daily limit to reset; Rejected: nothing moved (error says why)
cycles
opt nat64 in cycles, not T
order_id
opt text
deferred_until
opt nat64 Deferred: when the limit resets, in seconds
error
opt text
Returns (Err)
code, message
text nothing was written or pulled; see errors
resets_at
opt nat64 DAILY_CAP_REACHED only: when the buyer's daily limit resets, in seconds
query topup_ckusdc_status # backend · the payer

topup_ckusdc_status : (text) -> (opt CkUsdcPayment), by request_id: the caller's payment. Ask it when topup_ckusdc returned no answer, or until a timer finishes the payment. A payment the cycles cannot reach is refunded to the payer, minus one ledger fee. It also answers the order's payment of a checkout, under the checkout's request_id.

update create_ckusdc_checkout # backend · signed

create_ckusdc_checkout : (TopupCkUsdcArgs) -> (variant { Ok : CkUsdcCheckout; Err : TopupCkUsdcError }). The other way to pay ck-USDC: one plain transfer from any wallet, with nothing approved and nothing pulled. It takes topup_ckusdc's arguments and runs every check topup_ckusdc makes before its pull, then fixes the order's terms under the caller (the checkout's owner, whose order it is) and names the account to send the price to. The same request_id with the same terms answers the same checkout until it expires; with other terms, REQUEST_ID_REUSED; after its expiry, until it is dropped, CHECKOUT_EXPIRED (make a new one under another request_id). A request_id names one payment of the caller, pulled or paid by a transfer: topup_ckusdc refuses one that names a checkout, and this method one that names a pulled payment. The anonymous principal cannot make a checkout.

Returns (Ok), among other fields
deposit_account
record { owner : principal; subaccount : opt blob } the backend canister, under a subaccount of the checkout's own (a hash of the owner and the request_id)
amount_atomic
nat64 the price: what the transfer must bring
created_at, expires_at
nat64 seconds; the checkout takes a transfer for 30 minutes
owner, request_id
principal, text what notify_ckusdc_checkout names it by
paid_by
opt nat64 the block that paid it, once claimed
update icrc1_transfer # ck-USDC ledger · any wallet

On the ck-USDC ledger (xevnm-gaaaa-aaaar-qafnq-cai), from any account: one transfer of exactly amount_atomic to deposit_account, which the ledger must timestamp no later than expires_at. The Buy page sends it with created_at_time set to the checkout's created_at in nanoseconds, the same on every retry, so a retry of a transfer that landed answers Duplicate with its block; with memo null; with fee null, so the ledger takes its own fee from the sender on top; and only while 2 minutes are left before expires_at. The reply is the block to notify.

What comes back
At least the price
it pays the order, and any excess goes back less the ledger fee (an excess of no more than the fee stays)
Short, late or extra
less than the price, timestamped after expires_at, made more than 5 minutes before created_at, or after a block already paid the order: it goes back less the ledger fee
No more than the fee
nothing can be sent back (DEPOSIT_TOO_SMALL)
Not delivered
an order the cycles cannot reach goes back less two ledger fees

Everything goes back to the account the transfer came from. A transfer to a checkout's deposit account after the checkout is gone still goes back: for 7 days on its own, after that once anyone notifies its block.

update notify_ckusdc_checkout # backend · anyone

notify_ckusdc_checkout : (NotifyCkUsdcCheckoutArgs) -> (variant { Ok : CkUsdcPayment; Err : TopupCkUsdcError }). Claims the transfer in block_index for the checkout named by owner and request_id: the backend reads the block from the ledger and checks that it is a transfer to that checkout's deposit account. Each block is claimed once. The owner's call returns the payment the block settles, taken as far as it goes now, as topup_ckusdc returns it (or the payment sending the transfer back); anyone else's only claims, and answers CLAIMED with the payment's status. Notifying is optional: every 30 seconds the backend reads the ledger's new blocks and claims every transfer to a checkout it watches.

Argument
owner
principal required the checkout's owner
request_id
text required
block_index
nat64 required the transfer's block on the ck-USDC ledger
query ckusdc_checkout_status # backend · the owner

ckusdc_checkout_status : (text) -> (opt CkUsdcCheckoutView), by request_id: the caller's checkout and its payments, the order's first, then each transfer sent back. Null once the checkout is dropped, 2 minutes after expires_at at the soonest, once the backend has read the ledger through it and none of its payments still moves; the order's payment is then topup_ckusdc_status's.

Account

Balances, history and auto-refill.#

query icrc1_balance_of # Cycles Ledger · public

A Cycles Ledger balance, from the Cycles Ledger itself (um5iw-rqaaa-aaaaq-qaaba-cai): icrc1_balance_of(record { owner = principal "<principal>"; subaccount = null }), in cycles, not T. Anyone may ask, as the anonymous identity. Spend it with icp canister top-up.

composite query my_orders # console · signed

On the console canister (to2ii-4iaaa-aaaac-bgdma-cai): my_orders : (nat32, opt text) -> (variant { Ok : History; Err : ConsoleError }), the caller's orders on every rail and the refills auto-refill ran, newest first. The first argument is the page size (100 at most); the second is null for the first page, then opt "<next_page>" with the reply's next_page for the next, older one. The last page has no next_page. See the examples for the call.

Each history entry, among other fields
id, status
text orders: pending, paid, fulfilling, completed, failed, refunded; refills: pending, succeeded, failed, needsreview
source
variant { Order; PrepaidRefill }
canister_id
opt text empty for a Cycles Ledger order
cycles, amount_usd_cents
opt nat, opt nat64 cycles in cycles, not T
project_id
opt text
created_at
nat64 nanoseconds, for orders and refills alike, which sort together by it
update subscription_create # console · signed

subscription_create : (CreateSubscriptionArgs) -> (variant { Ok : SubscriptionView; Err : ConsoleError }). Prepaid auto-refill: the console tops a canister (or a Cycles Ledger account) up to refill_to_cycles when it drops below threshold_cycles, drawing on the owner's own Cycles Ledger balance, at most monthly_cap_cycles a month. Three steps, which the console walks through: for a canister, first let the console read its balance (icp canister settings update <canister> --add-status-viewer to2ii-4iaaa-aaaac-bgdma-cai -n ic, with icp-cli 1.4.0 or later; skip it if the canister's status is already public; the console refuses a canister it cannot read); then subscription_create; then an icrc2_approve on the Cycles Ledger of the subscription's spender (in the returned funding, unique per subscription). A principal has at most 10 subscriptions, one per destination, of them one to a Cycles Ledger account (a second is refused with LimitExceeded). Once a canister has 5, only its controllers can add more; once its controllers name who may refill it with destination_claim, only they and those owners can, at any count (the claim removes everyone else's), and a controller of the canister can always subscribe it. Cards are not charged for auto-refill.

Argument
destination
variant { Canister : principal; LedgerAccount : Account }
threshold_cycles, refill_to_cycles
nat
funding
variant { Prepaid : record { monthly_cap_cycles : nat; from_subaccount : opt blob } }
project_id
opt text
Errors and limits

Limits, destination checks, error codes.#

Limits
Per order
$1 to $200 on every rail; $5 to $100 for a card payment without a sign-in
Per UTC day, card
$1,000 per buyer (a signed-in buyer, or one destination of payments without a sign-in), $1,000 per card, $1,000 for all payments without a sign-in together, and $5,000 for all card payments. A card payment over a cap is charged, then refunded in full.
Automatic card refunds
A card payment refused for something the payer did (an expired or already paid order, an amount out of range, a full daily cap) is refunded automatically up to 3 times per card in 24 hours. After that, its refund is held for an operator, who makes it by hand, and it is never kept; securitybugs@dfinity.org answers questions about one.
Per UTC day, ck-USDC
$2,000 per buyer. topup_ckusdc and create_ckusdc_checkout refuse a payment that would pass it before anything moves (DAILY_CAP_REACHED, with resets_at); a payment that comes in just as the cap filled is delivered when the day resets (Deferred).
Card orders
create_order: 5 a minute and 50 a UTC day per buyer, and a ceiling a minute for everyone (RATE_LIMITED); 10 unpaid orders per buyer at a time, and a ceiling in total (TOO_MANY_OPEN_ORDERS). An unpaid order expires 25 hours after it was made.
ck-USDC payments
one call per caller at a time (CALLER_BUSY), 5 open payments per caller (TOO_MANY_OPEN_PAYMENTS; a new checkout counts the caller's checkouts that still take a transfer with them), and 5 new payments a minute per caller with a ceiling a minute for everyone (RATE_LIMITED)
ck-USDC checkouts
30 minutes to pay one; 5 new checkouts a minute per caller, with no shared ceiling, and 5 notifications a minute per caller within a shared 60 a minute for known buyers and 60 for everyone else (RATE_LIMITED; a known buyer is a caller with a delivered order). A ceiling on the checkouts CyclePay holds at once: a call made then is usually turned away before it runs (the call itself is rejected), and one admitted just before answers CHECKOUTS_FULL.
Destination checks

On create_order, topup_ckusdc and create_ckusdc_checkout. Nothing is charged when a check fails.

SYSTEM_CANISTER_WARNING
The canister is one of 10 known system canisters (NNS dapp, CMC, ICP Ledger, Internet Identity, Cycles Ledger, NNS Governance, NNS Root, CyclePay frontend, CyclePay console, CyclePay Stripe gateway). Ask the buyer, then send the call again with confirm_system_canister = opt true.
DESTINATION_BLOCKED
aaaaa-aa (the management canister) and CyclePay's backend cannot be topped up, and a beneficiary that is anonymous, the management canister or a system canister cannot be credited. No override.
CANISTER_ID_INVALID, INVALID_DESTINATION
the principal is not a canister ID (CANISTER_ID_INVALID from create_order, INVALID_DESTINATION from topup_ckusdc). topup_ckusdc also answers INVALID_DESTINATION for a beneficiary on a canister destination, which create_order answers with BENEFICIARY_NOT_ALLOWED.

Both purchase methods answer a refusal as a record of code : text and message : text; topup_ckusdc's also has resets_at : opt nat64, set for DAILY_CAP_REACHED. Nothing moved for any of them.

create_order (OrderError)
ANONYMOUS
the anonymous principal cannot make an order
AMOUNT_OUT_OF_RANGE
outside $1 to $200
BENEFICIARY_NOT_ALLOWED
a beneficiary on a canister destination
ESCROW_NOT_ALLOWED
an escrow spender on a canister destination, or with a beneficiary
ESCROW_SPENDER_INVALID
the anonymous principal, the management canister or CyclePay's backend cannot be the spender
ESCROW_SPENDER_BUSY
another spender's allowance on the caller's escrow account is still live: order for that spender, or wait for it to expire
NOT_PROJECT_MEMBER
the caller has no role in project_id, or it is not a project ID
PROJECTS_UNAVAILABLE
the console could not be asked about project_id; try again later
TOO_MANY_OPEN_ORDERS
10 unpaid orders already, or the ceiling in total: pay one or let it expire
RATE_LIMITED
5 orders this minute or 50 this UTC day from the caller, or too many from everyone this minute: try again in a minute, or the next day
PAUSED, CARDS_UNAVAILABLE
CyclePay or card payments are paused; try again later
topup_ckusdc (TopupCkUsdcError)
AUTH_REQUIRED
the anonymous principal cannot pay
INVALID_AMOUNT, INVALID_REQUEST_ID
see the arguments
REQUEST_ID_REUSED
the request_id names a payment with other arguments
CALLER_BUSY
another call of the caller is running
DAILY_CAP_REACHED
the payment would pass the buyer's $2,000 a day; resets_at says when the limit resets
TOO_MANY_OPEN_PAYMENTS, RATE_LIMITED
5 payments of the caller still open, or too many calls this minute: try again shortly
INVALID_PROJECT_ID
project_id is not 1 to 128 printable ASCII characters, no spaces
NOT_PROJECT_MEMBER, PROJECTS_UNAVAILABLE
the caller has no role in project_id, or the console could not be asked
PAUSED
CyclePay is paused; try again later

create_ckusdc_checkout answers topup_ckusdc's codes and two more; nothing moved for any of them. notify_ckusdc_checkout claims nothing for any of its codes but CLAIMED and DEPOSIT_TOO_SMALL.

create_ckusdc_checkout
CHECKOUT_EXPIRED
the request_id names a checkout past its expires_at, not yet dropped: make a new one under another request_id
CHECKOUTS_FULL
CyclePay holds as many checkouts as it keeps room for: a call made then is usually turned away before it runs (the call itself is rejected), and one admitted just before answers CHECKOUTS_FULL. Try again in a few minutes, or pay another way.
notify_ckusdc_checkout
CLAIMED
for anyone but the owner: the block is claimed, by this call or an earlier one, and the message says how its payment stands
NOT_A_DEPOSIT, MINTED_DEPOSIT
the block is not a transfer to that checkout's deposit account, or settles another checkout; a mint into it is settled by hand
DEPOSIT_TOO_SMALL
the transfer is no more than the ledger fee: claimed, with nothing to send back
BLOCK_NOT_FOUND, LEDGER_UNAVAILABLE, RATE_LIMITED, PAUSED
try again shortly, or let the backend find the transfer
INVALID_REQUEST_ID
see the arguments
Examples

Call the canisters from icp-cli.#

Buy by card with icp-cli 1.7.0
# icp-cli 1.7.0 or later: npm install -g @icp-sdk/icp-cli@latest,
# or brew install icp-cli. Then, as the identity that spends the cycles:
icp cycles buy --amount 10 -n ic --identity cyclepay
# Or pay the least, to the cent, that buys 5T cycles at the quoted rate:
icp cycles buy --cycles 5T -n ic --identity cyclepay
# It shows the price, the card fee and about how many cycles it buys, and
# asks to confirm. Then it prints the order's payment_url with a QR code
# for a phone, and waits until the cycles land on the identity's Cycles
# Ledger account. Ctrl-C stops the wait, not the order.
icp cycles buy --amount 10 -n ic in a terminal: identity demo, gateway 2bwus-iiaaa-aaaac-bee3a-cai (CyclePay), price 10.00 USD (9.41 USD after a 0.59 USD card fee), about 6.936T cycles at 1.3566 USD per 1T cycles, and the prompt: Create this order? Nothing is charged until you pay on Stripe. icp cycles buy --amount 10 -n ic in a terminal: identity demo, gateway 2bwus-iiaaa-aaaac-bee3a-cai (CyclePay), price 10.00 USD (9.41 USD after a 0.59 USD card fee), about 6.936T cycles at 1.3566 USD per 1T cycles, and the prompt: Create this order? Nothing is charged until you pay on Stripe.
The pay screen of a demo order from a local stand-in gateway: order co-1-2d3e9c969dcee5c9d27197e25253265a is payable until 2026-10-16T18:15:13Z at https://www.cyclepay.org, shown as a link and a QR code, and the command waits for payment; Ctrl-C leaves the order payable. The pay screen of a demo order from a local stand-in gateway: order co-1-2d3e9c969dcee5c9d27197e25253265a is payable until 2026-10-16T18:15:13Z at https://www.cyclepay.org, shown as a link and a QR code, and the command waits for payment; Ctrl-C leaves the order payable.

The second screen is a demo order from a local stand-in gateway, so its link and QR code open www.cyclepay.org. A real order's link and QR code open Stripe's payment page.

The price
icp canister call --identity anonymous --query -n ic 2bwus-iiaaa-aaaac-bee3a-cai \
  get_xdr_rate_status '()'
# For example, xdr_usd_x10000 = 13_520 : nat64 means $1.352 an XDR:
# $25 by card buys (25 - 1.025, rounded to the cent) / 1.352
# = 23.98 / 1.352 = 17.73T cycles, rounded down.
# The rate moves: read it for every quote.
A card order, paid on the Payment Link
icp canister call --identity cyclepay -n ic 2bwus-iiaaa-aaaac-bee3a-cai \
  create_order '(record {
    destination = variant { Canister = principal "<your-canister-id>" };
    beneficiary = null;
    escrow_spender = null;
    escrow_principal = null;
    project_id = null;
    amount_usd_cents = 2_500 : nat64;
    confirm_system_canister = null;
  })'
# Ok: open its payment_url, as it is, in a browser for the buyer to pay,
# then follow the order with order_status '("<order_id>")'.
ck-USDC: fund, approve, then pay
# Send ck-USDC to the principal this prints, then check it arrived:
icp identity principal --identity cyclepay
icp token xevnm-gaaaa-aaaar-qafnq-cai balance --identity cyclepay -n ic
# Approve the backend for 25.00 plus the 0.01 fee of the pull, for 10 minutes:
icp token xevnm-gaaaa-aaaar-qafnq-cai approve 25.01 2bwus-iiaaa-aaaac-bee3a-cai \
  --expires-in 10m --identity cyclepay -n ic
# A fresh id for this purchase; on a retry, send the same one:
REQUEST_ID=$(uuidgen)
icp canister call --identity cyclepay -n ic 2bwus-iiaaa-aaaac-bee3a-cai \
  topup_ckusdc '(record {
    request_id = "'"$REQUEST_ID"'";
    amount_atomic = 25_000_000 : nat;
    destination = variant { Canister = principal "<your-canister-id>" };
    beneficiary = null; project_id = null; confirm_system_canister = null;
  })'
ck-USDC by one transfer: a checkout
REQUEST_ID=$(uuidgen)
icp canister call --identity cyclepay -n ic 2bwus-iiaaa-aaaac-bee3a-cai \
  create_ckusdc_checkout '(record {
    request_id = "'"$REQUEST_ID"'";
    amount_atomic = 25_000_000 : nat;
    destination = variant { Canister = principal "<your-canister-id>" };
    beneficiary = null; project_id = null; confirm_system_canister = null;
  })'
# Ok: deposit_account, created_at, expires_at (30 minutes on).
# Send exactly the price to deposit_account (its subaccount blob as the
# reply prints it), stamped with created_at in nanoseconds:
icp canister call --identity cyclepay -n ic xevnm-gaaaa-aaaar-qafnq-cai \
  icrc1_transfer '(record {
    to = record { owner = principal "2bwus-iiaaa-aaaac-bee3a-cai"; subaccount = opt blob "<deposit subaccount>" };
    amount = 25_000_000 : nat;
    from_subaccount = null; fee = null; memo = null;
    created_at_time = opt (<created_at * 1_000_000_000> : nat64);
  })'
# Ok = <block>. Then, or let the backend find it:
OWNER=$(icp identity principal --identity cyclepay)
icp canister call --identity cyclepay -n ic 2bwus-iiaaa-aaaac-bee3a-cai \
  notify_ckusdc_checkout '(record { owner = principal "'"$OWNER"'"; request_id = "'"$REQUEST_ID"'"; block_index = <block> : nat64 })'
A Cycles Ledger balance
icp canister call --identity anonymous --query -n ic um5iw-rqaaa-aaaaq-qaaba-cai \
  icrc1_balance_of '(record { owner = principal "<principal>"; subaccount = null })'
# In cycles, not T. Or, for your own identity:
icp cycles balance --identity cyclepay -n ic
Your purchase history
# The newest 20 of your orders and refills:
icp canister call --query --identity cyclepay -n ic to2ii-4iaaa-aaaac-bgdma-cai \
  my_orders '(20 : nat32, null)'
# The next, older page, with the reply's next_page:
icp canister call --query --identity cyclepay -n ic to2ii-4iaaa-aaaac-bgdma-cai \
  my_orders '(20 : nat32, opt "<next_page>")'
For AI agents

Top up canisters, programmatically.#

An agent buys cycles one of three ways. It can give its user a link to pay by card with no sign-in; it can make a card order with its own identity, with icp cycles buy or create_order, and give its user the order's payment_url; or it can pay ck-USDC itself, from an identity that holds a ck-USDC budget, with no human at all. A card payment always ends on Stripe's page, in the user's browser. The buy-cycles skill has more on the icp cycles buy flow for agents.

Keep the agent's budget small. An identity that pays ck-USDC can spend everything it holds. Give an agent its own identity with only the ck-USDC it may spend, and see agent security for what a sign-in lets its holder do.
01
Link

No sign-in, by card

The agent shows https://www.cyclepay.org/c/<canister id>/<usd> ($5 to $100). The user pays on Stripe's page, and the cycles land on the canister.

02
Order

An order, by card

The agent runs icp cycles buy (icp-cli 1.7.0 or later) or calls create_order, shows its user the price, then the payment_url. The user pays; the agent never does. It follows the order with order_status.

03
ck-USDC

Paid by the agent

The agent approves the backend on the ck-USDC ledger and calls topup_ckusdc, or sends one transfer to a create_ckusdc_checkout checkout with no approve. The cycles usually land in seconds.

CLAUDE.md / agent config

Drop this into your agent's context.

CLAUDE.md
Buying ICP cycles: CyclePay (www.cyclepay.org)

When you need ICP cycles, fetch the index first:
https://www.cyclepay.org/llms.txt (or https://4w3yu-fyaaa-aaaac-beeoa-cai.icp0.io/llms.txt)

CyclePay runs on canisters, and there is no REST API: call the backend
2bwus-iiaaa-aaaac-bee3a-cai with Candid on mainnet (icp-cli -n ic, or an IC
agent with host https://icp-api.io). Give public queries --identity anonymous,
so icp-cli never stops to ask for a password.

The price, USD per XDR times 10,000 (1T cycles = 1 XDR). It moves: read it for
every quote.

```sh
icp canister call --identity anonymous --query -n ic 2bwus-iiaaa-aaaac-bee3a-cai get_xdr_rate_status '()'
```

Card, no sign-in ($5 to $100): show the user
https://www.cyclepay.org/c/<canister-id>/<usd> for a canister, or
https://www.cyclepay.org/b/<principal>/<usd> for a Cycles Ledger account.
They pay on Stripe's page.

Card, as your identity ($1 to $200), with icp-cli 1.7.0 or later
(npm install -g @icp-sdk/icp-cli@latest, or brew install icp-cli). The
buy-cycles skill at https://skills.internetcomputer.org has more on the
flow.

1. Quote. With no terminal and no --yes, this prints the price, the card fee
   and the cycles on stderr, creates nothing and exits 1. Show it to the user,
   and go on only on their yes. With --cycles, order in step 2 with
   --amount <the Price it showed>, so the order is the one they said yes to:
   ```sh
   icp cycles buy --amount 10 -n ic --identity <id> < /dev/null
   ```
2. Order. This prints one JSON line and returns at once:
   ```sh
   icp cycles buy --amount 10 -n ic --identity <id> --yes --no-open --no-wait --json
   ```
   Give the user its checkout_url exactly as printed, to pay once, on any
   device. Never pay it yourself, never open or fill in the payment page, and
   never ask for card details.
3. Poll order_status '("<order_id>")' on the backend as <id> until Delivered,
   Refunded, RefundOwed or NeedsReview, or until expires_at (in the JSON line)
   passes with the order still AwaitingPayment: it has expired. For
   NeedsReview or RefundOwed, give the user the order id and CyclePay's
   contact, securitybugs@dfinity.org, and stop. Running step 2 again within
   the hour, before the user pays, gives back the same order; after payment,
   or after an hour, it makes a new one, so never run it again to check on a
   payment.

The cycles land on the Cycles Ledger account of <id>, which both icp deploy
and icp canister top-up spend from.

Without icp-cli 1.7.0 or later, or to top up a canister directly, make the
order:

```sh
icp canister call --identity <id> -n ic 2bwus-iiaaa-aaaac-bee3a-cai create_order '(record { destination = variant { Canister = principal "<canister-id>" }; beneficiary = null; escrow_spender = null; escrow_principal = null; project_id = null; amount_usd_cents = 1_000 : nat64; confirm_system_canister = null })'
```

Then show the user the payment_url it returns, exactly as returned, and poll
order_status '("<order_id>")' the same way, or until expires_at passes unpaid.
For a Cycles Ledger account, use destination = variant { Ledger }
(beneficiary = opt principal "<principal>" to credit someone else; 0.0002T
less in ledger fees).

ck-USDC, paid by your identity (no human needed):

1. get_ckusdc_terms '()' on the backend (a public query) gives the spender and
   fee_atomic, the ledger's fee (10_000 = 0.01 ck-USDC today).
2. Approve the backend on the ck-USDC ledger for amount_atomic + fee_atomic
   (the approve costs one more fee), with an expiry:
   ```sh
   icp token xevnm-gaaaa-aaaar-qafnq-cai approve 25.01 2bwus-iiaaa-aaaac-bee3a-cai --expires-in 10m --identity <id> -n ic
   ```
3. topup_ckusdc on the backend with a fresh request_id (1 to 64 of
   A-Z a-z 0-9 - _; a uuidgen UUID fits), the same one on every retry;
   amount_atomic in 6-decimal atoms, a multiple of 10_000, $1 to $200.
4. If no answer came back, read topup_ckusdc_status '("<request_id>")'.

Or, with no approve: create_ckusdc_checkout (the same arguments), then one
icrc1_transfer of exactly amount_atomic to its deposit_account, fee and memo
null, created_at_time = created_at in nanoseconds (the same on every retry),
with 2 minutes to spare before expires_at (30 minutes on); then
notify_ckusdc_checkout with the block. A late, short or extra transfer comes
back less the fee. Never let the identity hold more ck-USDC than you may spend.
Compatible with any agent that can run icp-cli or an IC agent

One index. Every harness.

Point your agent's context file at llms.txt. The agent calls the canisters, and card payments finish in your browser.

Claude
via CLAUDE.md
ChatGPT
via system prompt
Cursor
via .cursor/rules
Devin
via knowledge base
Copilot
via instructions
Windsurf
via rules file
Claude Code
via CLAUDE.md
OpenCode
via config
Any CLI agent
via icp-cli
Custom scripts
via an IC agent

Get started

Try the API.

Call the canisters above from icp-cli, a script or an AI agent.

For agents Machine-readable copy of cyclepay.org
.md