Capxul Docs
Core client

CapxulClient

Reference for the core SDK client — createCapxulClient, the CapxulResult contract, and the method bundles the React hooks wrap.

@capxul/sdk exposes one factory: createCapxulClient. It resolves the platform bootstrap for your publishable key and returns a CapxulClient — imperative method bundles covering auth, accounts, payments, receivables, organizations, payroll, and onboarding. Every React hook wraps one of these methods; in a React app, CapxulProvider creates and owns the client for you.

Use the client directly when there is no React tree — a script, a server, an agent backend. See Node & servers.

Create a client

import { createCapxulClient } from "@capxul/sdk";

const result = await createCapxulClient({
  publishableKey: process.env.CAPXUL_PUBLISHABLE_KEY!,
  requirement: "counterfactual",
});

if (!result.ok) {
  throw result.error;
}

const client = result.value;
await client.auth.signIn({ email: "user@example.com" });

createCapxulClient returns Promise<CapxulResult<CapxulClient>> — a failed bootstrap comes back as an error value, not an exception.

Parameters

The factory accepts a single CapxulClientInput object with exactly three fields. The SDK resolves everything else — the bootstrap host, the runtime, request timeouts, and session caching — internally.

publishableKey

string — required.

The key that identifies your app to the platform. Create sandbox keys with the @capxul/sandbox CLI.

requirement

"none" | "counterfactual" | "deployed" — optional, defaults to "none".

The account-readiness target the SDK works toward after sign-in. With "none" no account setup runs at all; the other two values start the account lane automatically once a user signs in. Full semantics are on Node & servers.

signer

CapxulSigner — optional.

The consumer-held signing key for requirement: "deployed". Required outside the browser; browser apps omit it and the SDK provisions one automatically.

These three fields are the entire public input. Overrides such as origin, bootstrapBaseUrl, runtime, fetch, invokeTimeoutMs, authCache, and telemetry are internal production and test seams — they are not consumer API and are not accepted here.

Results, not exceptions

Every method on every bundle returns Promise<CapxulResult<T>>:

import type { CapxulResult } from "@capxul/sdk";

type CapxulResult<T> =
  | { readonly ok: true; readonly value: T }
  | { readonly ok: false; readonly error: CapxulError };

Check ok to narrow the result; on failure, error is always a structured CapxulError. The React hooks unwrap this shape into TanStack Query data / error fields for you — explicit narrowing is only needed when you call the client directly:

const account = await client.accounts.read();
if (!account.ok) {
  console.error(account.error.code, account.error.message);
  return;
}
console.log(`${account.value.balance.value} ${account.value.balance.currency}`);

See Error handling for the error catalog and recovery patterns.

Method bundles

The client groups its methods into domain bundles. Each row links the hook family that wraps it. Bundles marked client-only have no hooks yet — in a React app, reach them through useCapxulClientOrNull.

BundleWhat it doesReact hooks
client.authEmail OTP auth: canSendOtp, signIn, verifyOtp, getSession, signOut.Auth
client.accountPost-sign-in setup lifecycle (getLifecycle, retrySetup) plus the personal actor scope — address book, requests, inbox, insights.Account
client.accountsRead the personal Accountbalance and available, both Money.Account
client.currentUser, client.meWho is signed in: profile, payment link, and org memberships (currentUser.get); profile plus deposit instructions (me).Auth
client.identityLoad the signed-in user's stored profile.Auth
client.handlesResolve a handle to a payable recipient.Client-only — pay accepts handles directly (Payments)
client.payeesCreate, fetch, and resolve saved payees.Client-only
client.targetsResolve any target reference — handle, email, org, payee, or destination — with its pay / request / payout capabilities.Client-only
client.destinationsSave, list, and remove external payout destinations.Destinations
client.paymentsMove money: pay, payout, withdraw, plus list, get, and cancel.Payments
client.activityThe paginated activity feed — payments, payouts, withdrawals, deposits, claims.Activity
client.offrampQuote and track a cash-out to a saved destination.Offramp
client.paymentDocumentsVerify a payment document's integrity and render it to HTML by document hash.Client-only
client.paymentRequestsReceivables: fixed-amount payment links with a draft → sent → viewed → paid lifecycle, plus collect and reconcile.Client-only — the Requests hooks cover the actor-scoped request surface, a different bundle
client.workbenchThe agent payment workbench: draftsimulaterequestApprovalexecute, with a human approval step in between.Built for agents — see MCP
client.subAccountsEnvelopes under an Account: create, list, rename, delete, transfer.Sub-accounts
client.createOrg, client.orgs, client.org(orgId)Create organizations, list memberships, and resolve the entity-scoped bundle — treasury, members, roles, invites, spend, payroll.Organizations, Payroll
client.onboardingComplete personal or organization onboarding after the first sign-in: completePersonal, completeOrganization.Onboarding

Org scoping is explicit: client.org(orgId) resolves a bundle for that one organization on every call — there is no stateful "active org" on the client.

Not every bundle is equally proven in a product surface yet. Check Capability status before you build on one.

Off the surface

The client also carries a _internal namespace — an observation and testing seam. Nothing under _internal is consumer API; do not build on it. Likewise, factory inputs beyond the three documented above (self-hosted origins, fetch and runtime overrides, timeout and cache tuning) live on internal entrypoints for hermetic tests and platform tooling — never on createCapxulClient.

On this page