// concepts — wallet state transitions for agent payments

Wallet lifecycle

Follow one wallet from creation to settlement. Each stage shows the human meaning, the state change, the API call, and concrete balances in cents.

5 lifecycle stagesUSD centsledger-backed
base urlhttps://agentkit-2.polsia.app

// lifecycle model

AgentKit keeps a wallet’s total balance separate from temporary holds. In every example below, amounts are integer US cents, and the API key is an example value only.

available balanceavailable = current_balance_cents - reserved_balance_cents

current_balance_cents is the wallet total. A reservation reduces what can be spent now without reducing that total.

reservation stateactive → committed | released

Every reservation starts as active. Commit or release closes the hold and writes a ledger record.

// five stages

The primary path is provision → fund → reserve → commit. Release is the safe alternative when a hold should not become spend; split is a separate multi-wallet settlement path.

01

create the account boundary

Provision

Create one wallet for an agent and receive the credential that authorizes later wallet operations.

plain-English

Provision creates the wallet record, applies its spending limit and optional provider allowlist, and returns an API key exactly once. Nothing is reserved yet.

state transition

no wallet → active wallet with reserved_balance_cents = 0.

api callPOST · no auth
curl -X POST https://agentkit-2.polsia.app/api/wallets \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "my-agent-001",
    "spending_limit_cents": 50000,
    "initial_balance_cents": 10000,
    "allowed_providers": ["openai", "anthropic"]
  }'
before / after wallet stateall amounts in cents
before
{
  "wallet": null,
  "available_cents": 0,
  "reservation": null
}
after
{
  "wallet_id": 12,
  "agent_id": "my-agent-001",
  "spending_limit_cents": 50000,
  "current_balance_cents": 10000,
  "reserved_balance_cents": 0,
  "available_cents": 10000,
  "status": "active",
  "allowed_providers": [
    "openai",
    "anthropic"
  ],
  "api_key": "ak_live_0123456789abcdef0123456789abcdef"
}

Need provisioning without an issued key? Compare the no-key v1 alternative at Provision a wallet (v1).

API reference: Create a wallet →
02

put spendable funds in place

Fund

Increase the wallet total before a payment is held or spent.

plain-English

This deterministic example credits the wallet directly. Because no reservation exists, the full top-up is immediately available.

state transition

current_balance_cents: 10000 → 15000; reserved cents stay at 0.

api callPOST · API key
curl -X POST https://agentkit-2.polsia.app/api/wallets/12/credit \
  -H "X-API-Key: ak_live_0123456789abcdef0123456789abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "amount_cents": 5000
  }'
before / after wallet stateall amounts in cents
before
{
  "wallet_id": 12,
  "current_balance_cents": 10000,
  "reserved_balance_cents": 0,
  "available_cents": 10000
}
after
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 0,
  "available_cents": 15000
}

Production Stripe path: POST /api/v1/wallets/:agentId/fund creates a funding intent and checkout URL; it does not change the wallet balance. After payment, POST /api/v1/wallets/:agentId/fund/claim verifies the session and posts the credit.

API reference: Credit a wallet →
03

place a temporary hold

Reserve

Move funds from available to reserved while keeping the wallet total unchanged.

plain-English

Reserve creates a bounded hold for a future payment. The 300-second TTL gives the caller time to finish the operation, and the idempotency key makes retries safe.

state transition

reserved_balance_cents: 0 → 2000; available falls from 15000 to 13000.

api callPOST · API key · reservation 71
curl -X POST https://agentkit-2.polsia.app/api/v1/wallets/my-agent-001/reservations \
  -H "X-API-Key: ak_live_0123456789abcdef0123456789abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "amount_cents": 2000,
    "currency": "USD",
    "ttl_seconds": 300,
    "memo": "pre-auth openai",
    "idempotency_key": "rsv-2026-001"
  }'
before / after wallet stateall amounts in cents
before
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 0,
  "available_cents": 15000,
  "reservation": null
}
after
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 2000,
  "available_cents": 13000,
  "reservation": {
    "reservation_id": 71,
    "status": "active",
    "amount_cents": 2000,
    "ttl_seconds": 300,
    "idempotency_key": "rsv-2026-001"
  }
}
API reference: Create a fund reservation →
04

turn the hold into spend

Commit

Finalize the active reservation, debit the held amount, and record the settlement in the ledger.

plain-English

Commit consumes the hold. The reservation becomes committed, both the total and reserved balances decrease by 2,000 cents, and the corresponding ledger entry is labeled reservation_commit.

state transition

active → committed; 15000 / 2000 becomes 13000 / 0, so available remains 13000.

api callPOST · API key · no body
curl -X POST https://agentkit-2.polsia.app/api/v1/wallets/my-agent-001/reservations/71/commit \
  -H "X-API-Key: ak_live_0123456789abcdef0123456789abcdef"
before / after wallet stateall amounts in cents
before
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 2000,
  "available_cents": 13000,
  "reservation": {
    "reservation_id": 71,
    "status": "active"
  }
}
after
{
  "wallet_id": 12,
  "current_balance_cents": 13000,
  "reserved_balance_cents": 0,
  "available_cents": 13000,
  "reservation": {
    "reservation_id": 71,
    "status": "committed"
  },
  "transaction_id": 4895,
  "ledger_entry": {
    "provider": "reservation_commit",
    "amount_cents": 2000,
    "status": "approved"
  }
}

Commit is replay-safe for the same reservation ID. A retry returns the existing transaction instead of debiting the wallet a second time.

API reference: Commit a reservation →
05

settle or route the payment

Release / split

Release returns an unused hold. Split is a separate all-or-nothing settlement branch for multiple child wallets.

plain-English

Choose release when the reserved payment will not happen. Choose split when one charge should debit multiple agent wallets by defined allocations.

state transition

Release is active → released. Split does not change a reservation status; it writes payment_split child ledger rows and debits each child by its allocation.

reservation alternative

Release

plain-English

Cancel the hold without spending it. The 2,000 cents return to available balance, while the wallet total stays at 15,000.

state transition

active → released; reserved_balance_cents falls to 0.

api callPOST · API key · no body
curl -X POST https://agentkit-2.polsia.app/api/v1/wallets/my-agent-001/reservations/71/release \
  -H "X-API-Key: ak_live_0123456789abcdef0123456789abcdef"
before / after wallet stateall amounts in cents
before
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 2000,
  "available_cents": 13000,
  "reservation": {
    "reservation_id": 71,
    "status": "active"
  }
}
after
{
  "wallet_id": 12,
  "current_balance_cents": 15000,
  "reserved_balance_cents": 0,
  "available_cents": 15000,
  "reservation": {
    "reservation_id": 71,
    "status": "released"
  },
  "transaction_id": 4896,
  "ledger_entry": {
    "provider": "reservation_release",
    "amount_cents": 2000,
    "status": "approved"
  }
}
API reference: Release a reservation →
multi-wallet settlement

Split

plain-English

Split one 1,000-cent charge into two 500-cent allocations. Each child wallet is debited only by its share.

state transition

There is no reservation status transition. Both child debits and their payment_split ledger rows commit together or roll back together.

api callPOST · API key · 50% each
curl -X POST https://agentkit-2.polsia.app/api/v1/payments/split \
  -H "X-API-Key: ak_live_0123456789abcdef0123456789abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "openai",
    "charge_amount_cents": 1000,
    "routing_rule": {"type": "percentage", "value": 50},
    "agents": ["agent-A", "agent-B"],
    "idempotency_key": "split-2026-001",
    "memo": "shared inference cost"
  }'
before / after wallet stateall amounts in cents
before
{
  "charge_amount_cents": 1000,
  "child_wallets": [
    {
      "agent_id": "agent-A",
      "wallet_id": 21,
      "current_balance_cents": 5000,
      "reserved_balance_cents": 0,
      "available_cents": 5000
    },
    {
      "agent_id": "agent-B",
      "wallet_id": 22,
      "current_balance_cents": 3000,
      "reserved_balance_cents": 0,
      "available_cents": 3000
    }
  ]
}
after
{
  "payment_id": 77,
  "status": "completed",
  "charge_amount_cents": 1000,
  "allocations": [
    {
      "agent_id": "agent-A",
      "wallet_id": 21,
      "amount_cents": 500,
      "status": "approved"
    },
    {
      "agent_id": "agent-B",
      "wallet_id": 22,
      "amount_cents": 500,
      "status": "approved"
    }
  ],
  "ledger_provider": "payment_split",
  "child_wallets": [
    {
      "agent_id": "agent-A",
      "current_balance_cents": 4500,
      "available_cents": 4500
    },
    {
      "agent_id": "agent-B",
      "current_balance_cents": 2500,
      "available_cents": 2500
    }
  ]
}

The split is all-or-nothing: if either child wallet cannot cover its 500-cent allocation, no child debit is kept. Retry the same payment with its idempotency key to receive the original allocations.

API reference: Split a payment across agents →

// trace the cycle

Start with an active wallet, add funds, hold the amount you need, then choose the settlement branch that matches the payment.

provision→fund→reserve→commit

branch: reserve → release returns funds to available, while split settles one charge across child wallets without changing reservation status.