Skip to content

feat(cli): project the in-force usage term and report amounts in the term's unit [show] - #1615

Merged
ejanusevicius merged 2 commits into
mainfrom
feat/usage-projections-current-term
Nov 23, 2026
Merged

ejanusevicius merged 2 commits into
mainfrom
feat/usage-projections-current-term

Conversation

@ejanusevicius

@ejanusevicius ejanusevicius commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

checkly account usage projections [id] now uses the new GET /v2/usage/projections endpoint (monorepo #6984, TREE-1280):

  • The term ID is now optional. Without it, the API projects the term in force today, and the CLI looks up that term's name for human output. You no longer need to run checkly account usage terms first.
  • With an ID, the CLI sends it as ?usageTermsId=. --as-of works as before.
  • If no term is in force today, NO_USAGE_TERMS now explains how to find a term ID and pass it.
  • Older CLI versions still call /v2/usage/terms/{id}/projections. The plan is to make that public route return 410 with a message to upgrade, in a separate monorepo PR.

Formatters now use the unit fields instead of the deprecated credit* fields. v2 amounts are in the term's unit: credits for contracts, usdCents for Stripe-billed self-service plans. Before this change, the CLI showed self-service cents labelled as credits.

  • REST types: unit, unitBudget, unitsUsed, unitsRemaining, budgetedDailyUnits, averageDailyUnits, projectedUnitsAtContractEnd, projectedUnitsRemaining. The deprecated credit* fields are removed from the types.
  • Human output: labels say "credits" or "USD" depending on the unit (for example "USD used", "Remaining USD", "Coverage gaps (USD unavailable)"). usdCents amounts print as dollars and keep the API's sub-cent precision. Terms show Budget and Unit instead of Credit budget.
  • Pricing-rule rates follow the term's unit too. On a usdCents term they print as a price in dollars (Price: $0.00025 per run, Annual price, Applied daily price), and the contract-only Standard/Premium credits / unit rows are hidden. Contract terms keep their credit labels. The API field names (credits, annualCredits, appliedDailyCredits*) are unchanged.
  • --pricing-rule accepts the self-service run products apiAndMultistepChecks and browserAndPlaywrightChecks (added in #6984). It previously rejected them before sending the request.
  • series --output json now includes unit in its envelope. Other JSON output passes the API response through unchanged.

Notes

  • --as-of without an ID projects the term the API considers in force today, as of that date. That's the backend's behaviour, not the CLI's.

Validation against live APIs (read-only)

  • Prod, contract term (credits): every command in every output format, plus the error paths. Projections with no ID resolve the in-force term through the new route. After the pricing fix, term detail output is byte-for-byte unchanged.
  • Staging, Team plan (usdCents): every command in every output format. Labels read USD and amounts print as dollars; JSON carries "unit": "usdCents"; pricing rules show Price: $0.00025 / $0.00625; summary --pricing-rule apiAndMultistepChecks works.
  • Not seen live: non-zero or negative dollar charges, because the staging account's runs are all inside the included allowance. Unit tests cover them.

Test plan

  • pnpm lint, tsc --noEmit
  • Usage unit tests (formatters, REST client, helpers, commands, command metadata): 258 passed
  • New tests: projection with no ID and with an ID, an error when no term is in force, an invalid ID rejected before any request, usdCents formatting for terms, summary, series, projections, pricing-rule prices and calculation daily rates, and the new --pricing-rule keys

Testing:

Annual % of budget: #%
USD at contract end: $#.##
Remaining USD at contract end: $#.##
% at contract end: #%
Weeks until exhausted: -

…


```text
$ checkly account usage projections -o json
{
  "usageTermsId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "asOf": "####-##-##",
  "period": {
    "from": "####-##-##",
    "to": "####-##-##"
  },
  "weeksSinceStart": #,
  "weeksRemaining": ##,
  "unit": "usdCents",
  "creditsUsed": #,
  "unitsUsed": #,
  "remainingCredits": ##,
  "unitsRemaining": ##,
  "budgetedDailyCredits": #.####,
  "budgetedDailyUnits": #.####,
  "windows": {
…
$ checkly account usage projections -o detail
Usage projections

Usage term:                 <name>         (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
As of (completed UTC day):  ####-##-##
Period:                     ####-##-## to ####-##-##
Weeks since usage start:    ##
Weeks remaining:            ##
Credits used:               ###,###,###.####
Remaining credits:          ###,###,###.####
Budgeted daily credits:     #,###,###.###

…

--pricing-rule

Before

$ checkly account usage summary --pricing-rule apiAndMultistepChecks
✖ Failed to load usage summary.

  --pricing-rule must be one of: apiChecks, multistepChecks, browserChecks, playwrightCheckSuites, uptimeMonitors, aiInvocations, statusPages, statusPageAdditionalServices, statusPageAdditionalSubscribers, additionalSms, additionalPhoneAlerts.

[exit 2]

After

$ checkly account usage summary --pricing-rule apiAndMultistepChecks
Usage summary

Period:          ####-##-## to ####-##-##
Usage term IDs:  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
USD used:        $#.##

Usage breakdown

PERIOD                    PRICING RULE           USD USED
####-##-## to ####-##-##  apiAndMultistepChecks     $#.##

  Daily series: checkly account usage series --from ####-##-## --to ####-##-## --interval day --group-by account,checkType --pricing-rule apiAndMultistepChecks
  Terms:        checkly account usage terms
[exit 0]

Errors

$ checkly account usage projections
✖ Failed to load usage projections.

  No usage term is in force today. Run "checkly account usage terms" to find a
  term ID, then pass it to "checkly account usage projections <id>".

[exit 1]
$ checkly account usage projections not-a-uuid
✖ Failed to load usage projections.

  Usage term ID must be a valid UUID.

[exit 2]
$ checkly account usage projections xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
✖ Failed to load usage projections.

  Usage term xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx was not found. Run "checkly
  account usage terms" to discover available term IDs.

[exit 1]
$ checkly account usage projections --as-of ####-##-##
✖ Failed to load usage projections.

  --as-of must be a completed UTC date, before today. Defaults to yesterday UTC.

[exit 2]

ejanusevicius and others added 2 commits November 23, 2026 10:33
…term's unit

`checkly account usage projections` now calls `GET /v2/usage/projections`.
The term ID argument is optional: without it, the API projects the term in
force today, and the CLI names the term it picked. With an ID, the ID goes
in the `usageTermsId` query parameter.

Usage v2 amounts are now in each term's `unit` (`credits` for contracts,
`usdCents` for self-service plans). The REST types and formatters read
`unit`, `unitBudget`, `unitsUsed`, `unitsRemaining` and the other `units*`
fields instead of the deprecated `credit*` fields. Human output labels
amounts in credits or USD and prints cents as dollars. The series JSON
envelope also includes `unit`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f-service rule keys

On a usdCents term, pricing-rule rates and calculation daily rates were
labelled as credits and printed as raw cents. They now read as a price in
dollars (for example `Price: $0.00025` per run). Contract terms keep their
credit labels, and the contract-only standard/premium credit conversion
rows are hidden on usdCents terms.

`--pricing-rule` now accepts `apiAndMultistepChecks` and
`browserAndPlaywrightChecks`, the run products of a self-service term,
which it previously rejected before sending the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejanusevicius ejanusevicius changed the title feat(cli): project the in-force usage term and report amounts in the term's unit feat(cli): project the in-force usage term and report amounts in the term's unit [show] Nov 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved: ship/show PR from a same-repo branch.

@ejanusevicius
ejanusevicius merged commit 72f4b66 into main Nov 23, 2026
21 checks passed
@ejanusevicius
ejanusevicius deleted the feat/usage-projections-current-term branch November 23, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant