usage

Spend: noclick.usage(group_by="user"), noclick.Usage.series(group_by="agent"), noclick.Usage.limits().

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

Spend for period (default month), optionally split groupBy user, key, agent or project (each app), 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);
Parameters
options.groupBy"user" | "key" | "agent" | "project"
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 or app that spent, largest first. Without group_by, groups is empty.

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.

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 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"

project: one line per app.

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.

limitsstatic

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

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

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, and when the caps reset (resets_at).

groupTypeScript only

group(id: string | null): UsageGroup

The spend of one user, key, agent or app 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 or app (id) in the period.

Attributes
idstring | null
usdnumber
eventsnumber
rawJsonObject

The response JSON exactly as the API sent it.

UsageSeries

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

The response JSON exactly as the API sent it.

UsageSeriesLine

interface UsageSeriesLine

One key, user, agent, app 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 or a type label.

totalUsdnumber
eventsnumber
pointsUsagePoint[]
rawJsonObject

The response JSON exactly as the API sent it.

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, and every app with a budget.

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

Each app with a budgetUsdPerMonth.

rawJsonObject

The response JSON exactly as the API sent it.

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.

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.

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.

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.