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).

noclick.usage(
    period='month', *, group_by=None, agent=None, user=..., client=None
) -> Usage

Spend for period ("month"), optionally split group_by "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), and narrowed to one agent (an Agent or its id). Needs the usage scope.

Parameters
periodstrdefault 'month'
group_bystr | Nonedefault None
agentAnydefault None
userAny

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

(defaults to the current user)
clientClient | None

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

(default None)
Returns
Usage

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.

Usage

See this month's spend per user:

month = noclick.usage(group_by="user")
print(month.total_usd)
for group in month.groups:
    print(group.id, group.usd, group.events)

Inside as_user, it covers only that user:

with noclick.as_user("user_42"):
    print(noclick.usage().total_usd)

What one agent cost this month, per user it talked to:

support = noclick.Agent.from_name("support")
by_user = noclick.usage(group_by="user", agent=support)
print(by_user.total_usd, by_user["user_42"].usd)

What each app spent, to bill its user on:

booking = noclick.Project.from_name("booking", user="user_42")
by_app = noclick.usage(group_by="project")
print(by_app[booking.id].usd)

Who on your team spent what:

for person in noclick.usage(group_by="person").groups:
    print(person.name, person.usd)

What each line of work cost:

for workstream in noclick.usage(group_by="workstream").groups:
    print(workstream.name or "(unnamed)", workstream.usd)

Usage

class Usage

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

Attributes
periodAny
total_usdfloat
groupslist[UsageGroup]
rawdict[str, Any]

The response JSON exactly as the API sent it.

__getitem__

usage[group_id] -> UsageGroup

The spend of one user, key, agent, app or person id in a grouped usage (None is the account's own).

Parameters
group_idstr | Nonerequired
Returns
UsageGroup

That id's spend and event count; an id that spent nothing reads as $0 with no events.

Usage
user = noclick.User.from_id("user_42")
month = noclick.usage(group_by="user")
print(month[user.id].usd)   # 0.0 for a user who spent nothing

get

usage.get(group_id, default=None) -> Any

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

Parameters
group_idstr | Nonerequired
defaultAnydefault None
Returns
Any

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

Usage
support = noclick.Agent.from_name("support")
month = noclick.usage(group_by="agent")
if month.get(support.id) is None:
    print("support has cost nothing this month")

seriesstaticasync

noclick.Usage.series(
    *, from_=None, to=None, interval=None, group_by=None, key=None, agent=None,
    user_filter=None, user=..., client=None
) -> UsageSeries

Daily spend between from_ and to (default: the current month, at most 92 days), one line per group_by key, user, agent, type, project (an app), person (who each charge was for, labelled with their name) or workstream (the line of work it belongs to, labelled with its name). key is a key id or prefix.

Parameters
from_Anydefault None
toAnydefault None
intervalstr | Nonedefault None
group_bystr | Nonedefault None
keystr | Nonedefault None
agentAnydefault None
user_filterAny

Which users a read covers: noclick.ALL_USERS, noclick.NO_USER, a User, or your id for one. It filters without acting as that user.

(default None)
userAny

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

(defaults to the current user)
clientClient | None

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

(default None)
Returns
UsageSeries

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

Usage

Chart this month's spend by what it was for:

series = noclick.Usage.series(group_by="type")
for line in series.series:
    print(line.label, line.total_usd, [point.usd for point in line.points])

Or one agent's last 30 days, one line per user:

from datetime import datetime, timedelta, timezone

support = noclick.Agent.from_name("support")
now = datetime.now(timezone.utc)
series = noclick.Usage.series(from_=now - timedelta(days=30), to=now, group_by="user", agent=support)

ledgerstaticasync

noclick.Usage.ledger(*, tz=None, client=None) -> 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 (an IANA zone, default UTC) 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; noclick.usage() reads only what its keys and agents spent.

Parameters
tzstr | Nonedefault None
clientClient | None

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

(default None)
Returns
UsageLedger

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.

Usage
ledger = noclick.Usage.ledger(tz="Europe/London")
this_period = [g for g in ledger.groups if g.current and not g.own_resource]
print(sum(g.usd for g in this_period))

chargesstaticasync

noclick.Usage.charges(
    *, from_=None, to=None, keys=None, day=None, tz=None, cursor=None, limit=None,
    client=None
) -> UsageCharges

A page of the ledger's charges, newest first: the billing period's by default (from_, to), narrowed to groups (keys: LedgerGroup.key) or a day (YYYY-MM-DD) in tz, up to limit (500; default 50) a page.

Parameters
from_Anydefault None
toAnydefault None
keyslist[str] | Nonedefault None
daystr | Nonedefault None
tzstr | Nonedefault None
cursorstr | None

The next_cursor of the page before; omit it for the first page.

(default None)
limitint | None

Return at most this many.

(default None)
clientClient | None

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

(default None)
Returns
UsageCharges

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

Usage
ledger = noclick.Usage.ledger()
calls = [g.key for g in ledger.groups if g.current and g.subtype == "voice/call"]
page = noclick.Usage.charges(keys=calls)
while page.next:
    page = noclick.Usage.charges(keys=calls, cursor=page.next)

set_auto_top_upstaticasync

noclick.Usage.set_auto_top_up(
    *, threshold_usd, amount_usd, monthly_cap_usd, enabled=None, client=None
) -> dict[str, Any]

Change auto top-up, as the app's billing settings do (the signed-in owner's alone: it charges their saved method): refill amount_usd when the balance falls below threshold_usd, at most monthly_cap_usd 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; None keeps it as it is.

Parameters
threshold_usdfloatrequired
amount_usdfloatrequired
monthly_cap_usdfloatrequired
enabledbool | Nonedefault None
clientClient | None

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

(default None)
Returns
dict[str, Any]

Auto top-up as it stands.

Usage
noclick.Usage.set_auto_top_up(threshold_usd=10, amount_usd=50, monthly_cap_usd=200)

billingstaticasync

noclick.Usage.billing(*, client=None) -> UsageBilling | None

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. One of the account's own keys reads those; the signed-in owner also reads auto top-up and friends' credit.

Parameters
clientClient | None

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

(default None)
Returns
UsageBilling | None

The money, or None where nobody is billed.

Usage
money = noclick.Usage.billing()
if money is not None:
    print(money.balance_usd, money.plan.get("included_usd"))

billing_detailsstaticasync

noclick.Usage.billing_details(*, organization_id=None, client=None) -> BillingDetails

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

Parameters
organization_idstr | Nonedefault None
clientClient | None

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

(default None)
Usage
details = noclick.Usage.billing_details()
if details.payment_method:
    print(details.payment_method["brand"], details.payment_method["last4"])

billing_portalstaticasync

noclick.Usage.billing_portal(*, organization_id=None, client=None) -> str

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. organization_id names a team workspace they own or administer.

Parameters
organization_idstr | Nonedefault None
clientClient | None

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

(default None)
Returns
str

The portal's URL.

Usage
print(noclick.Usage.billing_portal())

creditsstaticasync

noclick.Usage.credits(*, organization_id=None, client=None) -> UsageCredits

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

Parameters
organization_idstr | Nonedefault None
clientClient | None

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

(default None)
Usage
meter = noclick.Usage.credits()
print(meter.used, meter.limit, meter.period, meter.balance_usd)

limitsstaticasync

noclick.Usage.limits(*, client=None) -> UsageLimits

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

Parameters
clientClient | None

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

(default None)
Returns
UsageLimits

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.

Usage
limits = noclick.Usage.limits()
for cap in limits.users:
    print(cap.id, cap.spent, cap.cap)
for app in limits.projects:
    print(app.name, app.user_id, app.spent, app.budget)
print(limits.resets_at)
print(limits.account.cap_usd, limits.account.spent_usd)   # None, None while no cap is set

set_account_capstaticasync

noclick.Usage.set_account_cap(cap_usd, *, client=None) -> AccountCap

Set your account's monthly spending cap, in whole dollars; None removes it. Past it, every call that costs money raises noclick.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 raises noclick.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.

Parameters
cap_usdint | Nonerequired
clientClient | None

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

(default None)
Returns
AccountCap

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

Usage
cap = noclick.Usage.set_account_cap(50)
print(cap.cap_usd, cap.spent_usd, cap.resets_at)

UsageGroup

class 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
idstr | None
usdfloat
eventsint
rawdict[str, Any]

The response JSON exactly as the API sent it.

namestr | None

UsageSeries

class UsageSeries
Attributes
intervalstr
from_Any
toAny
total_usdfloat
serieslist[UsageSeriesLine]
rawdict[str, Any]

The response JSON exactly as the API sent it.

UsageSeriesLine

class UsageSeriesLine

One key, user, agent or usage type's spend over the period. label is a key name (Console for the console key), your id for a user, an agent name or a type label.

Attributes
idstr | None
labelstr | None
total_usdfloat
eventsint
pointslist[UsagePoint]
rawdict[str, Any]

The response JSON exactly as the API sent it.

UsagePoint

class UsagePoint

Spend in one interval starting at t.

Attributes
tAny
usdfloat
eventsint

UsageLimits

class UsageLimits

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

Attributes
period_startAny
resets_atAny
keyslist[KeyCap]
userslist[UserCap]
agentslist[AgentBudget]
projectslist[ProjectBudget]

Each app with a budget_usd_per_month.

rawdict[str, Any]

The response JSON exactly as the API sent it.

accountAccountCap | None

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

KeyCap

class KeyCap

A capped key's spend this month.

Attributes
idstr
namestr | None
capfloat | None
spentfloat
rawdict[str, Any]

The response JSON exactly as the API sent it.

UserCap

class UserCap

A capped user's spend this month; id is your id for the user.

Attributes
idstr
capfloat | None
spentfloat
rawdict[str, Any]

The response JSON exactly as the API sent it.

AgentBudget

class AgentBudget

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

Attributes
idstr
namestr | None
budgetfloat | None
spentfloat
subtree_spentfloat
rawdict[str, Any]

The response JSON exactly as the API sent it.

ProjectBudget

class ProjectBudget

A budgeted app's spend this month: id and name are the app's, user_id the user it belongs to (None for your account's own).

Attributes
idstr
namestr | None
user_idstr | None
budgetfloat | None
spentfloat
rawdict[str, Any]

The response JSON exactly as the API sent it.

UsageLedger

class UsageLedger

The account's ledger: every charge it was billed in its billing period (period_start to period_end) and the one before (from previous_start), grouped; directory names what the groups name, by kind (workflows, agents, people, projects, keys…) and id.

Attributes
period_startAny
period_endAny
previous_startAny
fieldslist[str]
groupslist[LedgerGroup]
directorydict[str, dict[str, Any]]
rawdict[str, Any]

The response JSON exactly as the API sent it.

LedgerGroup

class LedgerGroup

One group of the account's ledger: its charges in one period (this billing period or the one before), one day (in the zone the ledger was read in) and one set of breakdown fields, added up. key lists its charges (Usage.charges(keys=[group.key])); subtype is what was charged for (a model's id, or a service like voice/call); own_resource means nobody was charged (the account's own key or resource); fields is every breakdown field by name (UsageLedger.fields): the automation, agent step, person, app or key it names.

Attributes
keystr
currentbool
daystr
usage_typestr
subtypestr
unitstr
own_resourcebool
chargesint
quantityfloat
usdfloat
fieldsdict[str, Any]
rawdict[str, Any]

The response JSON exactly as the API sent it.

UsageCharges

class UsageCharges

A page of the ledger's charges, newest first, with the runs they were recorded in by run id; pass next back as cursor for the next page (None at the end).

Attributes
chargeslist[LedgerCharge]
runsdict[str, dict[str, Any]]
nextstr | None
rawdict[str, Any]

The response JSON exactly as the API sent it.

LedgerCharge

class LedgerCharge

One charge in the account's ledger; key is its group's, metadata what it was for (the automation, agent step and run, the number, sender, key or app it names).

Attributes
idstr
atAny
usage_typestr
subtypestr
unitstr
quantityfloat
usdfloat
own_resourcebool
keystr
metadatadict[str, Any]
rawdict[str, Any]

The response JSON exactly as the API sent it.

UsageBilling

class UsageBilling

The money behind the ledger, as the credit gate reads it: the plan with its window and pools (included usage, Free's daily share, an older plan's top-up), the balance (below zero is owed), funds added this period and the plan's fee on them, and what's scheduled (recurring: a number's month, a connection's hours; domains that renew soon). auto_top_up is the signed-in owner's alone, as friends' credit (in raw) is.

Attributes
plandict[str, Any]
balance_usdfloat
funds_usdfloat
fees_usdfloat
recurringlist[dict[str, Any]]
domainslist[dict[str, Any]]
auto_top_updict[str, Any] | None
rawdict[str, Any]

The response JSON exactly as the API sent it.

BillingDetails

class BillingDetails

The plan's Stripe subscription (status, current_period_end: when it renews, or ends when cancel_at_period_end), an older plan's credit topup_subscription (also its credits_per_month, interval and subscription_id) and the default card (payment_method: brand, last4, exp_month, exp_year), each None where there's none.

Attributes
subscriptiondict[str, Any] | None
topup_subscriptiondict[str, Any] | None
payment_methoddict[str, Any] | None

UsageCredits

class 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 monthly_used against monthly_cap, and the dollar balance drawn after it. pool_user_id is whose pool it is; is_org_credits when that's the owner of a team workspace you're in, not you.

Attributes
usedfloat
limitfloat | None
periodstr
monthly_usedfloat | None
monthly_capfloat | None
balance_usdfloat | None
tierstr | None
pool_user_idstr
is_org_creditsbool
rawdict[str, Any]

The response JSON exactly as the API sent it.

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(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.

Attributes
idstr
namestr

As it was first written; matched whatever its case.

spent_usdfloat

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

eventsint
created_atAny
rawdict[str, Any]

The response JSON exactly as the API sent it.

archivedbool

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

liststaticasync

noclick.Workstream.list(*, archived=False, user=..., client=None) -> list[Workstream]

Your open workstreams (archived=True: the ones put away), most spent this month first, each with what it spent (as noclick.usage(group_by="workstream") counts it). Needs the usage scope.

Parameters
archivedbooldefault False
userAny

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

(defaults to the current user)
clientClient | None

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

(default None)
Returns
list[Workstream]

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

Usage
for workstream in noclick.Workstream.list():
    print(workstream.name, workstream.spent_usd)

renamestaticasync

noclick.Workstream.rename(workstream, name, *, client=None) -> 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. Needs the usage scope.

Parameters
workstreamAnyrequired
namestrrequired
clientClient | None

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

(default None)
Returns
Workstream

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

Usage
noclick.Workstream.rename("website", "Bakery site")
noclick.Workstream.rename("Menu", "Bakery site")   # merges Menu into it

archivestaticasync

noclick.Workstream.archive(workstream, *, client=None) -> 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
workstreamAnyrequired
clientClient | None

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

(default None)
Returns
Workstream

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

Usage
noclick.Workstream.archive("Q3 launch")

unarchivestaticasync

noclick.Workstream.unarchive(workstream, *, client=None) -> Workstream

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

Parameters
workstreamAnyrequired
clientClient | None

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

(default None)
Returns
Workstream

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

Usage
noclick.Workstream.unarchive("Q3 launch")

AccountCap

class AccountCap

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

Attributes
cap_usdfloat | None
spent_usdfloat | None
period_startAny
resets_atAny
reachedbool
rawdict[str, Any]

The response JSON exactly as the API sent it.

set_byCapChange | None

CapChange

class 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 (responsible_user_id: 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 (grant_id) and agent (agent_id, its turn_id) it came through and their name (client), the approval a raise ran on, the cap before and after, and when.

Attributes
bystr
responsible_user_idstr | None
key_idstr | None
grant_idstr | None
agent_idstr | None
turn_idstr | None
clientstr | None
approval_idstr | None
cap_before_usdfloat | None
cap_after_usdfloat | None
atAny
rawdict[str, Any]

The response JSON exactly as the API sent it.