Money
The typed meta-tool wrappers: charge, ship, ledger, issue and shop.
Money
Five methods that call a meta-tool with a typed argument and hand back a typed result instead of a ToolResult to cast. Each one is execute("codespar_<tool>", args) on the wire, so what a page under Meta-tools says about the tool's actions and providers applies here unchanged; what these pages add is the TypeScript shape and what the wrapper throws.
All five share one failure rule: when the tool result is not success, the wrapper throws a plain Error whose message is <method> failed: <error>. Network failures and timeouts surface as they do on execute.
charge
charge(args: ChargeArgs): Promise<ChargeResult>Inbound charge: the buyer pays the merchant. Routes to the tenant's connected charge-issuing providers.
Creates something the buyer pays: a Pix QR, a boleto, a hosted card checkout or a wallet redirect. Distinct from codespar_pay, which is an outbound transfer and has no typed wrapper. amount is in major units.
| Parameter | Type | Required | Description |
|---|---|---|---|
args | ChargeArgs | yes | Amount, currency, method, description and the buyer |
ChargeArgs field | Type | Required | Description |
|---|---|---|---|
amount | number | yes | Major currency units: R$ 125.00 is 125 |
currency | string | yes | ISO 4217: BRL, USD, EUR |
method | "pix" | "boleto" | "card" | "wallet" | yes | The rail |
description | string | yes | Shown to the buyer |
buyer | { name: string; email?: string; document?: string; phone?: string } | yes | Charges are merchant-issued, so the buyer is always named |
due_date | string | no | ISO 8601; boleto due date or Pix expiration |
const = await .({
: 150,
: "BRL",
: "pix",
: "Order 0000",
: { : "Example Buyer", : "buyer@example.com" },
});
.(., ., .);interface ChargeResult {
id: string;
status: string;
amount: number;
currency: string;
method: string;
/** Hosted payment URL when the provider issues one */
charge_url?: string;
pix_qr_code?: string;
pix_copy_paste?: string;
raw?: unknown;
}Throws Error("charge failed: ...") when the tool result is not success; otherwise as execute.
Related codespar_charge. Settlement is asynchronous: correlate it with paymentStatus using the tool_call_id that execute returns for the same call.
ship
ship(args: ShipArgs): Promise<ShipResult>Quote carriers, buy a label, or track a shipment, over one address-and-items envelope. Routes BR domestic shipments through Melhor Envio (Correios and private carriers); the router picks the cheapest carrier unless service_level says otherwise.
| Parameter | Type | Required | Description |
|---|---|---|---|
args | ShipArgs | yes | action plus what that action needs |
ShipArgs field | Type | Required | Description |
|---|---|---|---|
action | "label" | "track" | "quote" | yes | Buy a label, track, or price a route |
origin | ShipAddress | for label and quote | { postal_code, city?, state?, country?, line_1?, number? } |
destination | ShipAddress | for label and quote | same shape |
items | ShipItem[] | for label and quote | { weight_g, width_cm?, height_cm?, length_cm?, quantity?, declared_value?, description? } |
service_level | "fastest" | "cheapest" | "standard" | no | Default cheapest |
tracking_code | string | for track | The code a label returned |
metadata | Record<string, unknown> | no | Provider overrides: Melhor Envio service id, NF-e key for declared value |
const = await .({
: "quote",
: { : "01310100" },
: { : "20040020" },
: [{ : 500, : 20, : 10, : 30 }],
});
.(., ., .);interface ShipResult {
id: string;
status: string;
tracking_code?: string;
label_url?: string;
carrier?: string;
estimated_delivery?: string;
/** Minor units */
cost_minor?: number;
raw?: unknown;
}Throws Error("ship failed: ...") when the tool result is not success; otherwise as execute.
Related codespar_ship.
ledger
ledger(args: LedgerArgs): Promise<LedgerResult>The books, not the money: post a double-entry journal entry, read an account's balances, create an account, or read an agentic receipt, on the tenant's self-hosted Lerian Midaz ledger. Source debits must equal destination credits in the same asset. Amounts are in minor units.
| Parameter | Type | Required | Description |
|---|---|---|---|
args | LedgerArgs | yes | action plus what that action needs |
LedgerArgs field | Type | Required | Description |
|---|---|---|---|
action | "entry" | "balance" | "account" | "receipt" | "receipts" | yes | Which operation |
asset | string | for entry and account | BRL, USD, USDC, ... |
scale | number | no | Decimal places; default 2 |
source, destination | { account: string; amount: number }[] | for entry | Debit and credit legs; account is an alias such as @wallet/user_0000 |
description | string | no | Entry description |
account | string | for balance | Account UUID |
alias, name, type | string | for account | Alias, display name, Midaz account type (default deposit) |
receipt_id | string | for receipt | rcpt_... |
consumer_id, limit | string, number | for receipts | Whose receipts, how many (default 50) |
metadata | Record<string, unknown> | no | Stored on the entry or account |
const = await .({
: "entry",
: "BRL",
: 2,
: [{ : "@wallet/user_0000", : 15000 }],
: [{ : "@revenue/store", : 15000 }],
: "Order 0000 settled",
});
.(., .);interface LedgerResult {
/** Transaction or account id (entry / account) */
id?: string | null;
status?: string;
account_id?: string | null;
alias?: string | null;
/** Per-asset available + on-hold amounts (balance) */
balances?: unknown;
raw?: unknown;
}
// action=receipt and action=receipts return these instead:
interface LedgerReceiptResult { found: boolean; receipt?: AgenticReceipt; receipt_id?: string }
interface LedgerReceiptsResult { receipts: AgenticReceipt[]; count: number }The return type is LedgerResult for every action; for receipt and receipts the value on the wire has the LedgerReceiptResult and LedgerReceiptsResult shapes, which @codespar/types exports for the cast.
Throws Error("ledger failed: ...") when the tool result is not success; otherwise as execute.
Related codespar_ledger, Audit chain for what an agentic receipt proves.
issue
issue(args: IssueArgs): Promise<IssueResult>Issue a virtual or physical card, freeze, unfreeze or cancel one, or read its status, on the tenant's card-issuing program. Creates spend instruments; it does not move money by itself.
| Parameter | Type | Required | Description |
|---|---|---|---|
args | IssueArgs | yes | action plus what that action needs |
IssueArgs field | Type | Required | Description |
|---|---|---|---|
action | "card-virtual" | "card-physical" | "card-control" | "card-get" | yes | Which operation |
cardholder_id | string | to issue | The issuer's user id |
program_id | string | to issue | The card program (BIN) |
card_id | string | for card-control and card-get | |
control | "freeze" | "unfreeze" | "cancel" | for card-control | |
reason | string | no | Stamped on a control action |
shipping_address | Record<string, unknown> | for card-physical | |
metadata | Record<string, unknown> | no |
const = await .({
: "card-virtual",
: "chd_0000",
: "prg_0000",
});
.(., ., .);interface IssueResult {
id?: string | null;
status?: string | null;
card_type?: string | null;
last_four?: string | null;
cardholder_id?: string | null;
program_id?: string | null;
raw?: unknown;
}Throws Error("issue failed: ...") when the tool result is not success; otherwise as execute.
Related codespar_issue.
shop
shop(args: ShopArgs): Promise<ShopResult>Checkout mints the store's real Pix copia-e-cola, to be settled from the agent's governed wallet; the contract stops at the Pix and performs no settlement.
Buy-side shopping: search a store's live catalog, start a checkout, poll it to a payable Pix. The argument and result are discriminated on action, so the result type follows the action without a cast. Checkout is asynchronous: checkout returns in_progress at once; poll checkout_status until ready_for_payment (which carries pix_copia_e_cola and total_minor) or canceled (which carries error). Requires a runtime with a registered codespar_shop implementation; a self-hosted runtime without one answers Tool not registered.
| Parameter | Type | Required | Description |
|---|---|---|---|
args | ShopSearchArgs | ShopCheckoutArgs | ShopStatusArgs | yes | Discriminated on action |
action | Fields | Result |
|---|---|---|
"search" | query (required), limit? (1..20, default 10), merchant? | ShopSearchResult: { rail, products: ShopOffer[] } |
"checkout" | items? (VTEX rail, by variant_id) or url? (Mercado Livre PDP), never both; merchant?, consumer_id?, buyer?, address? | ShopCheckoutResult: { checkout_session_id, status: "in_progress", message? } |
"checkout_status" | checkout_session_id (required) | ShopStatusResult: { checkout_session_id, status, rail?, total_minor?, pix_copia_e_cola?, order_status?, error? } |
const = await .({ : "search", : "dog food", : "cobasi" });
if ("products" in ) {
const = .[0]?.[0]?.;
.();
}
const = await .({
: "checkout",
: "cobasi",
: [{ : "sku_0000", : 1 }],
});
if ("checkout_session_id" in ) {
const = await .({
: "checkout_status",
: .,
});
if ("pix_copia_e_cola" in ) .(.);
}interface ShopOffer {
product_id: string;
/** Offer-level SKU when there is a single buyable SKU */
sku_id?: string;
title?: string;
/** Minor units */
price_minor?: number;
currency?: string;
image?: string;
url?: string;
available: boolean;
variants: ShopVariant[];
}
interface ShopVariant {
/** Pass this as the checkout item's variant_id; the product id is not buyable */
sku_id: string;
title?: string;
price_minor?: number;
currency?: string;
available: boolean;
}Throws Error("shop failed: ...") when the tool result is not success, including Tool not registered; otherwise as execute. A canceled checkout is a value with error set, not a throw.
Related codespar_shop for the rails, the cancel reasons and the state machine; settle the Pix with codespar_pay through execute.
Tools, execute and send
The session object and the methods that list, run and talk to tools: tools, findTools, execute, proxyExecute, send, sendStream.
Status and streams
Settlement and KYC dispositions after the call returns: paymentStatus, paymentStatusStream, verificationStatus, verificationStatusStream.