usage

Spend: noclick.usage(group_by="user"), noclick.Usage.series(group_by="agent"), noclick.Usage.limits(), noclick.Usage.set_account_cap(50), the account's ledger: noclick.Usage.ledger(), noclick.Usage.charges(), noclick.Usage.billing(), and the workstreams it's counted under (noclick.Workstream).

function usage(options?: UsageOptions): Promise<Usage>

Spend for period (default month), optionally split groupBy user, key, agent, project (each app), person (who each charge was for: the person whose message, click or key started the work; the account's owner for work nobody else started) or workstream (the line of work it belongs to, as the agent that started it named it; the null one is work nobody named one for), and narrowed to one agent. Needs the usage scope. Without groupBy, groups is empty.

const month = await usage({ groupBy: "user" });
console.log(month.totalUsd, month.groups);

for (const person of (await usage({ groupBy: "person" })).groups) console.log(person.name, person.usd);

for (const line of (await usage({ groupBy: "workstream" })).groups) console.log(line.name ?? "(unnamed)", line.usd);
Parameters
options.groupBy"user" | "key" | "agent" | "project" | "person" | "workstream"
options.agentstring | ApiObject
options.userUserOption

Who the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

options.periodstring
Returns

The period's total_usd and, with group_by, one group per user, key, agent, app, person or workstream that spent, largest first; a person's or workstream's group has its name (the None workstream is work nobody named one for). Without group_by, groups is empty.

Types
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

Usage

class Usage

What the account (or the current user) spent in period.

Attributes
periodstring
totalUsdnumber
groupsUsageGroup[]
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

get

get(id: string | null): UsageGroup | null

The group of an id that spent something in a grouped usage, else null.

Parameters
idstring | nullrequired
Returns

The UsageGroup, or default when the id spent nothing in the period.

seriesstatic

static series(options?: UsageSeriesOptions): Promise<UsageSeries>

Daily spend between from and to, one line per key, user, agent, app, person, workstream or usage type.

Parameters
options.fromDate | string

Default: the current month (at most 92 days).

options.toDate | string
options.interval"day"
options.groupBy"key" | "user" | "agent" | "type" | "project" | "person" | "workstream"

project: one line per app; person: one per person each charge was for; workstream: one per workstream.

options.keystring

A key id or prefix.

options.agentstring | ApiObject

An Agent or agent id.

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The lines, largest first, each with its label, total_usd and daily points. A day with no spend has no point.

Types
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

ledgerstatic

static ledger(options?: { tz?: string; client?: NoClick }): Promise<UsageLedger>

The account's ledger, as Settings → Usage reads it: every charge it was billed in its billing period and the one before (its automations' runs, its chat with NoClick, a teammate's work it pays for, its keys' and agents' calls), grouped by day in tz and by every field a breakdown splits by, with names for what they were for. For the signed-in owner and the account's own secret keys. usage() reads only what its keys and agents spent.

const ledger = await Usage.ledger({ tz: "Europe/London" });
const thisPeriod = ledger.groups.filter((g) => g.current && !g.ownResource);
console.log(thisPeriod.reduce((sum, g) => sum + g.usd, 0));
Parameters
options.tzstring
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The period, the fields groups are split by, the groups (each with its key, day, usd and fields) and the directory naming what they name.

chargesstatic

static charges(options?: UsageChargesOptions): Promise<UsageCharges>

A page of the ledger's charges, newest first, narrowed to groups (keys) or a day; the billing period's by default. Pass next back as cursor for the page after it.

const ledger = await Usage.ledger();
const calls = ledger.groups.filter((g) => g.current && g.subtype === "voice/call").map((g) => g.key);
let page = await Usage.charges({ keys: calls });
while (page.next) page = await Usage.charges({ keys: calls, cursor: page.next });
Parameters
options.fromDate | string

Default: the billing period's start.

options.toDate | string

Default: the billing period's end.

options.keysstring[]

Only charges in these groups (LedgerGroup.key).

options.daystring

Only charges on this day (YYYY-MM-DD) in tz.

options.tzstring

The IANA time zone the ledger was read in.

options.cursorstring

The previous page's next.

options.limitnumber

Charges per page, up to 500 (default 50).

options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The charges, the runs they were recorded in, and next: pass it as cursor for the next page.

setAutoTopUpstatic

static setAutoTopUp(
  settings: {
    enabled?: boolean;
    thresholdUsd: number;
    amountUsd: number;
    monthlyCapUsd: number;
  },
  options?: { client?: NoClick },
): Promise<JsonObject>

Change auto top-up, as the app's billing settings do (the signed-in owner's alone: it charges their saved method): refill amountUsd when the balance falls below thresholdUsd, at most monthlyCapUsd a month, all whole dollars within the funds checkout's rules; enabled turns it on (only with a method saved during a payment made with Refill automatically) or off, and left out keeps it as it is. Resolves with it as it stands.

Parameters
settings{ enabled?: boolean; thresholdUsd: number; amountUsd: number; monthlyCapUsd: number }required
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

Auto top-up as it stands.

Types
type JsonObject = { [key: string]: unknown };

billingstatic

static billing(options?: { client?: NoClick }): Promise<UsageBilling | null>

The money behind the ledger, as the credit gate reads it: the plan and its pools, the balance, funds added and what's scheduled to be charged; null where nobody is billed.

Parameters
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The money, or None where nobody is billed.

billingDetailsstatic

static billingDetails(
  options?: { organizationId?: string; client?: NoClick },
): Promise<BillingDetails>

The plan's Stripe subscription, an older plan's credit top-up subscription and the default card. The signed-in owner's alone; organizationId names a team workspace they own or administer.

const { subscription, paymentMethod } = await Usage.billingDetails();
Parameters
options.organizationIdstring
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

billingPortalstatic

static billingPortal(
  options?: { organizationId?: string; client?: NoClick },
): Promise<string>

A session on Stripe's customer portal, where the signed-in owner changes their plan, card and invoices: open its URL within a few minutes. organizationId names a team workspace they own or administer.

window.location.href = await Usage.billingPortal();
Parameters
options.organizationIdstring
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The portal's URL.

creditsstatic

static credits(
  options?: { organizationId?: string; client?: NoClick },
): Promise<UsageCredits>

What NoClick's balance meter shows: the included usage used and its cap, the balance, and whose pool it is. organizationId names a team workspace you're in, whose work draws on its owner's pool.

Parameters
options.organizationIdstring
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

limitsstatic

static limits(options?: { client?: NoClick }): Promise<UsageLimits>

This month's spend of every capped key, user and agent (account principals), of every budgeted app, and your account's own monthly cap (account).

Parameters
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

Each capped key and user with its cap and spent, each budgeted agent with its budget, spent and subtree_spent, each budgeted app (projects) with its budget and spent, when the caps reset (resets_at), and the account's cap (account), over its billing period.

setAccountCapstatic

static setAccountCap(
  capUsd: number | null,
  options?: { client?: NoClick },
): Promise<AccountCap>

Set your account's monthly spending cap, in whole dollars; null removes it. Past it, every call that costs money rejects with SpendCapExceeded until the billing period resets. Your account's own keys lower the cap, or set one where there's none; raising or removing it is your account's owner's (in Settings → Plan and billing in the NoClick app), so from a key it rejects with PermissionDenied and changes nothing. Through MCP, and from an agent on the word of the person whose message started its turn, a raise or a removal waits for the owner's approval. Needs the usage scope. Resolves to the cap as it stands, with who set it (setBy).

const cap = await Usage.setAccountCap(50);
console.log(cap.capUsd, cap.spentUsd, cap.resetsAt);
Parameters
capUsdnumber | nullrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The cap as it now stands, with what its billing period has spent and who set it (set_by).

groupTypeScript only

group(id: string | null): UsageGroup

The spend of one user, key, agent, app or person id in a grouped usage (null is the account's own); an id that spent nothing reads as $0 with no events.

Parameters
idstring | nullrequired

UsageGroup

interface UsageGroup

Spend of one user, key, agent, app, person or workstream (id) in the period. name is a person's name, with group_by="person", or a workstream's, with group_by="workstream".

Attributes
idstring | null
usdnumber
eventsnumber
rawJsonObject

The response JSON exactly as the API sent it.

namestring | null

A person's name, with groupBy: "person", or a workstream's, with groupBy: "workstream"; otherwise null.

Types
type JsonObject = { [key: string]: unknown };

UsageSeries

interface UsageSeries
Attributes
intervalstring
fromDate | null
toDate | null
totalUsdnumber
seriesUsageSeriesLine[]
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UsageSeriesLine

interface UsageSeriesLine

One key, user, agent, app, person, workstream or usage type's spend over the period.

Attributes
idstring | null
labelstring | null

A key name (Console for the console key), a user's id, an agent name, a person's name, a workstream's name or a type label.

totalUsdnumber
eventsnumber
pointsUsagePoint[]
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UsagePoint

interface UsagePoint

Spend in one interval starting at t.

Attributes
tDate | null

The start of the interval.

usdnumber
eventsnumber

UsageLimits

interface UsageLimits

Every capped key, user and agent with this month's spend, every app with a budget, and your account's own cap.

Attributes
periodStartDate | null
resetsAtDate | null
keysKeyCap[]
usersUserCap[]
agentsAgentBudget[]
projectsProjectBudget[]

Each app with a budgetUsdPerMonth.

rawJsonObject

The response JSON exactly as the API sent it.

accountAccountCap | null

Your account's monthly spending cap, over its billing period.

Types
type JsonObject = { [key: string]: unknown };

KeyCap

interface KeyCap

A capped key's spend this month.

Attributes
idstring
namestring | null
capnumber | null
spentnumber
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UserCap

interface UserCap

A capped user's spend this month.

Attributes
idstring

Your id for the user.

capnumber | null
spentnumber
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

AgentBudget

interface AgentBudget

A budgeted agent's spend this month; subtreeSpent adds the agents it spawned.

Attributes
idstring
namestring | null
budgetnumber | null
spentnumber
subtreeSpentnumber
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

ProjectBudget

interface ProjectBudget

A budgeted app's spend this month; userId is the user it belongs to (null: your account's own).

Attributes
idstring
namestring | null
userIdstring | null
budgetnumber | null
spentnumber
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UsageLedger

interface UsageLedger

The account's ledger: every charge it was billed in its billing period and the one before, grouped.

Attributes
periodStartDate | null
periodEndDate | null
previousStartDate | null

Where the period before starts.

fieldsstring[]

The fields each group is split by.

groupsLedgerGroup[]
directoryRecord<string, Record<string, JsonObject>>

Names for what the groups name, by kind (workflows, agents, people, projects, keys…) and id.

rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

LedgerGroup

interface LedgerGroup

One group of the account's ledger: its charges in one period (this billing period or the one before), one day and one set of breakdown fields, added up.

Attributes
keystring

The group's key: list its charges with Usage.charges({ keys: [key] }).

currentboolean

In this billing period (true) or the one before.

daystring

Its day (YYYY-MM-DD) in the zone the ledger was read in.

usageTypestring
subtypestring

What was charged for: a model's id, or a service like voice/call or apps/hosting.

unitstring
ownResourceboolean

On the account's own key or resource: nobody was charged.

chargesnumber

How many charges it holds.

quantitynumber
usdnumber
fieldsRecord<string, unknown>

Every breakdown field (UsageLedger.fields) by name: the automation, agent step, person, app, key… it names.

rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UsageCharges

interface UsageCharges

A page of the ledger's charges, newest first.

Attributes
chargesLedgerCharge[]
runsRecord<string, JsonObject>

The runs the charges were recorded in, by run id.

nextstring | null

Pass as cursor for the next page; null at the end.

rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

LedgerCharge

interface LedgerCharge

One charge in the account's ledger.

Attributes
idstring
atDate | null
usageTypestring
subtypestring
unitstring
quantitynumber
usdnumber
ownResourceboolean
keystring

Its group's key.

metadataJsonObject

What it was for: the automation, agent step and run, the number, sender, key or app it names.

rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

UsageBilling

interface UsageBilling

The money behind the ledger, as the credit gate reads it. One of the account's own keys reads the plan, the balance, funds added and what's scheduled; autoTopUp and friends' credit (in raw) are the signed-in owner's.

Attributes
planJsonObject

The plan, its window and its pools: included usage, Free's daily share, an older plan's top-up.

balanceUsdnumber

What was added less what it paid for; below zero is owed.

fundsUsdnumber

Funds added this period, and the plan's fee on them.

feesUsdnumber
recurringJsonObject[]

Charges that come on a date: a number's month, a connection's hours.

domainsJsonObject[]

Domains that renew soon.

autoTopUpJsonObject | null

Auto top-up, for the signed-in owner; null otherwise.

rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

BillingDetails

interface BillingDetails

The plan's subscription, an older plan's credit top-up subscription and the default card, as Stripe holds them for the signed-in owner (or a team workspace they own or administer); each null where there's none.

Attributes
subscription{ status: string; /** When it renews, or ends when it's set to end; ISO 8601. */ currentPeriodEnd: string | null; cancelAtPeriodEnd: boolean; } | null
topupSubscription{ status: string; currentPeriodEnd: string | null; cancelAtPeriodEnd: boolean; creditsPerMonth: number; interval: "month" | "year"; subscriptionId: string; } | null
paymentMethod{ brand: string; last4: string; expMonth: number; expYear: number } | null

UsageCredits

interface UsageCredits

The pool a workspace's work draws on, as NoClick's balance meter reads it, in credits: the included usage used against limit in the period (day where the plan counts by day, else month), the month's monthlyUsed against monthlyCap, and the dollar balance drawn after it. poolUserId is whose pool it is; isOrgCredits when that's the owner of a team workspace you're in, not you.

Attributes
usednumber
limitnumber | null
periodstring
monthlyUsednumber | null
monthlyCapnumber | null
balanceUsdnumber | null
tierstring | null
poolUserIdstring
isOrgCreditsboolean
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };

Workstream

class Workstream

A line of work your spend is counted under. An agent names one when it starts work (a child's task, a message it hands another agent, an app's coding job; agent.spawn(task, { workstream })), from your workstreams or a new name, and every charge of that work, and of what it starts, belongs to it. A person renames one, or archives it once its work is done: its charges still read under it, and it leaves the workstreams agents choose from until it's brought back or an agent names it again.

for (const workstream of await Workstream.list()) console.log(workstream.name, workstream.spentUsd);
await Workstream.rename("Menu", "Bakery site");   // merges Menu into Bakery site
await Workstream.archive("Q3 launch");
Attributes
idstring
namestring

As it was first written; matched whatever its case.

spentUsdnumber

What it spent this month (a call acting for one of your users: that user's share).

eventsnumber
createdAtDate | null
rawJsonObject

The response JSON exactly as the API sent it.

archivedboolean

Put away: out of the workstreams agents choose from, its charges still under it.

Types
type JsonObject = { [key: string]: unknown };

liststatic

static list(
  options?: { archived?: boolean; user?: UserOption; client?: NoClick },
): Promise<Workstream[]>

Your open workstreams (archived: true: the ones put away), most spent this month first, each with what it spent (as usage({ groupBy: "workstream" }) counts it). Needs the usage scope.

Parameters
options.archivedboolean
options.userUserOption

Who the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

Each workstream's id, name, spent_usd and events. What work nobody named one for spent is the None group of noclick.usage(group_by="workstream").

Types
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

renamestatic

static rename(
  workstream: string | Workstream,
  name: string,
  options?: { client?: NoClick },
): Promise<Workstream>

Rename workstream (a Workstream, its name in any case, or its id) to name. Renamed onto another workstream's name, it merges into that one: its charges so far read as that one's (none is rewritten), and raw.merged_from names it. Your account's alone: a call acting for one of your users can't. Answers the workstream it reads as now, without this month's spend (Workstream.list() reads it). Needs the usage scope.

Parameters
workstreamstring | Workstreamrequired
namestringrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The workstream it reads as now, without this month's spend (spent_usd 0; Workstream.list() reads it).

archivestatic

static archive(
  workstream: string | Workstream,
  options?: { client?: NoClick },
): Promise<Workstream>

Archive workstream (a Workstream, its name in any case, or its id) once its work is done: its charges still read under it, and it leaves Workstream.list() ({ archived: true } lists it) and the workstreams agents choose from, until unarchive brings it back or an agent names it again. Your account's alone. Needs the usage scope.

Parameters
workstreamstring | Workstreamrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The workstream, archived, without this month's spend.

unarchivestatic

static unarchive(
  workstream: string | Workstream,
  options?: { client?: NoClick },
): Promise<Workstream>

Bring an archived workstream back among your open ones. Your account's alone. Needs the usage scope.

Parameters
workstreamstring | Workstreamrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The workstream, open again, without this month's spend.

AccountCap

interface AccountCap

Your account's monthly spending cap: capUsd (null while none is set) and, where one is set, what its billing period has spent (spentUsd), when that period started and resets, and whether it's reached: then every call that costs money rejects with SpendCapExceeded. setBy says who set it last (null: nobody has, or only NoClick's own hold on an account no person has claimed).

Attributes
capUsdnumber | null
spentUsdnumber | null
periodStartDate | null
resetsAtDate | null
reachedboolean
rawJsonObject

The response JSON exactly as the API sent it.

setByCapChange | null
Types
type JsonObject = { [key: string]: unknown };

CapChange

interface CapChange

Who set your account's monthly cap last: by (owner, signed in; key, one of your account's keys; connection, an MCP connection; agent, an agent's turn; assistant, your NoClick assistant), the person it was for (responsibleUserId: the person whose message started the agent's turn, the person a connection acts for, else your account's owner), the key it was made with, the connection (grantId) and agent (agentId, its turnId) it came through and their name (client), the approval a raise ran on, the cap before and after, and when.

Attributes
bystring
responsibleUserIdstring | null
keyIdstring | null
grantIdstring | null
agentIdstring | null
turnIdstring | null
clientstring | null
approvalIdstring | null
capBeforeUsdnumber | null
capAfterUsdnumber | null
atDate | null
rawJsonObject

The response JSON exactly as the API sent it.

Types
type JsonObject = { [key: string]: unknown };