open_spend_session
Before a run of small paid calls to one seller (a stream of x402 calls at a cent each, say), open one budget for the run instead of checking every call. Your owner's spend policy judges the session like a purchase of max_amount: allow holds that maximum against today's cap and returns reservation.id, the session id; ask means a person approves the budget first, then send the same request again; deny means do not start. Then call draw_session_spend right before paying each call, and close_spend_session when done, which gives back what you did not draw. A session left open gives its remainder back when it expires. Only where the workspace has sessions switched on (else an error with code not_released: use check_purchase per purchase). Needs a Last Price credential with price compute scope. Needs a claimed workspace: a sandbox key from self-registration is refused (403) until a person claims the workspace.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item | No | Optional: what the calls buy. | |
| intent | No | Optional: what the buyer approved for this purchase, from an American Express intent, an AP2 intent mandate, or declared by you. A purchase that names another seller, costs more than max_amount (counting every purchase under the same intent_id), is in another currency or comes after expires_at is denied, whatever the policy allows. evidence (the token or mandate) is kept only as a hash and is not verified yet. Only where the workspace has intents switched on (else an error with code not_released). | |
| pay_to | No | Optional: the wallet address (bare or CAIP-10) or merchant account id the calls pay. Every draw_session_spend must then name the same one: another is refused with code payee_changed. Only where the workspace has payee binding switched on (else an error with code not_released). | |
| seller | Yes | Who the calls pay: an API, domain or wallet name. | |
| agent_id | No | Only with a workspace-wide key: open it on behalf of this agent. An agent key always acts as itself. | |
| category | No | Optional: its category, when the policy limits or budgets categories. | |
| currency | No | Three-letter ISO currency code. Defaults to USD. | |
| max_amount | Yes | The most the whole run may spend. | |
| ttl_seconds | No | How long the session stays open, in seconds. Defaults to 3600. | |
| agentid_token | No | Your AgentID ID token, issued for Last Price, when your owner's policy lets only verified agents spend. Sent as the AgentID-Token header. |