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);Who the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
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 UsageWhat the account (or the current user) spent in period.
| period | string | |
| totalUsd | number | |
| groups | UsageGroup[] | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
get
get(id: string | null): UsageGroup | nullThe group of an id that spent something in a grouped usage, else null.
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.
Default: the current month (at most 92 days).
project: one line per app.
A key id or prefix.
An Agent or agent id.
Which users the read covers (user_id query), instead of acting as one (user).
undefined = the ambient user (asUser), null = the account itself.
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
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.
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
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): UsageGroupThe 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.
UsageGroup
interface UsageGroupSpend of one user, key, agent or app (id) in the period.
| id | string | null | |
| usd | number | |
| events | number | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
UsageSeries
interface UsageSeries| interval | string | |
| from | Date | null | |
| to | Date | null | |
| totalUsd | number | |
| series | UsageSeriesLine[] | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
UsageSeriesLine
interface UsageSeriesLineOne key, user, agent, app or usage type's spend over the period.
| id | string | null | |
| label | string | null | A key name ( |
| totalUsd | number | |
| events | number | |
| points | UsagePoint[] | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
UsagePoint
interface UsagePointSpend in one interval starting at t.
| t | Date | null | The start of the interval. |
| usd | number | |
| events | number |
UsageLimits
interface UsageLimitsEvery capped key, user and agent with this month's spend, and every app with a budget.
| periodStart | Date | null | |
| resetsAt | Date | null | |
| keys | KeyCap[] | |
| users | UserCap[] | |
| agents | AgentBudget[] | |
| projects | ProjectBudget[] | Each app with a |
| raw | JsonObject | The response JSON exactly as the API sent it. |
KeyCap
interface KeyCapA capped key's spend this month.
| id | string | |
| name | string | null | |
| cap | number | null | |
| spent | number | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
UserCap
interface UserCapA capped user's spend this month.
| id | string | Your id for the user. |
| cap | number | null | |
| spent | number | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
AgentBudget
interface AgentBudgetA budgeted agent's spend this month; subtreeSpent adds the agents it spawned.
| id | string | |
| name | string | null | |
| budget | number | null | |
| spent | number | |
| subtreeSpent | number | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
ProjectBudget
interface ProjectBudgetA budgeted app's spend this month; userId is the user it belongs to (null: your account's own).
| id | string | |
| name | string | null | |
| userId | string | null | |
| budget | number | null | |
| spent | number | |
| raw | JsonObject | The response JSON exactly as the API sent it. |