Skip to main content
SDK reference@codespar/sdk v0.16.11

One session per user. Every operation typed.

The session is what an agent calls, with charge, ship, ledger, issue and shop as typed methods. cs.api is the same client over REST, with one typed call per HTTP operation. The Python package, codespar, carries the same session under snake_case names.

Two halves, one client. cs.create(userId) opens a session for one end user; cs.api is the REST client on the same key, base URL and project scope. Nothing is configured twice.

A charge in sixty seconds

import {  } from "@codespar/sdk";

const  = new ({ : .. });

const  = await .("user_0000", { : "brazilian" });
try {
  const charge = await .({
const charge: ChargeResult
: 150, : "BRL", : "pix", : "Order 0000", : { : "Example Buyer" }, }); .(.); } finally { await .(); }

Amounts follow the wire, and the two halves differ. charge takes major units, so R$ 150.00 is 150. PayArgs, ledger legs and every *_minor field take minor units, so R$ 1.50 is 150. Timeouts are milliseconds in this package and seconds in the Python one.

↻ WHAT A SESSION CALL DOES
From cs.create to a result you can act on
1 · SESSION
cs.create(userId)
one session per end user · scopes and connected providers resolve here
→
2 · METHOD
session.charge(args)
the typed wrapper over the codespar_charge meta-tool
→
3 · DISPATCH
whichever provider is connected
routed server-side from the tenant's connections, not chosen in your code
→
4 · RESULT
a typed result, or a thrown Error
charge.pix_copy_paste · `<method> failed: <error>` when the tool refuses
cs.api skips steps 2 and 3: it is the HTTP operation itself, typed

The same money over REST

cs.api is on the client you already built: same key, same base URL, same project scope. The path and the shape of both arguments are checked against the served document, so a wrong parameter name is a type error rather than a 400.

const wallet = await ..("/v1/wallets/{id}", {
const wallet: {
    id: string;
    org_id: string;
    project_id: string;
    agent_id: string | null;
    display_name: string;
    status: "active" | "frozen" | "closed";
    created_at: string;
    closed_at: string | null;
    metadata: {
        [key: string]: unknown;
    };
    balances?: components["schemas"]["WalletBalance"][];
}
: { : "wlt_0000000000000000" }, });

Every operation the API serves has a call like this one. The REST client pages list them by resource group, the same grouping the HTTP reference uses.

Reading a method page

Each method opens with a bar that says what kind of call it is, whether it can move money, the version it appeared in and the Python name; below it come the parameters, an example, the result type and what it throws. Every method also takes a trailing opts?: CallOptions ({ timeout, signal }), documented once on the client page.

The same operations, elsewhere

Overview | CodeSpar