Skip to content

feat(billing): add billing:usage command#153

Open
Frostist wants to merge 5 commits intolaravel:mainfrom
Frostist:main
Open

feat(billing): add billing:usage command#153
Frostist wants to merge 5 commits intolaravel:mainfrom
Frostist:main

Conversation

@Frostist
Copy link
Copy Markdown

@Frostist Frostist commented Apr 21, 2026

Surfaces billing and usage data from GET /api/usage. Supports period offsets (0–3), optional environment filter, --detailed breakdown (per-app, per-resource, per-addon tables), and --json for CI/scripting use.

Got this idea from the Issue at #105

Summary

  • Adds cloud billing:usage to surface billing and usage data from GET /api/usage without leaving the terminal
  • Supports --period (0–3 offsets), --environment filter, --detailed for full per-app/per-resource/add-on tables, and --json for CI/scripting
  • Period label shows actual billing cycle date range (e.g. Apr 1, 2026 – Apr 30, 2026) from meta.available_periods

New files

File Purpose
app/Client/Resources/Usage/GetUsageRequest.php Saloon request for GET /api/usage
app/Client/Resources/UsageResource.php Resource wrapper on the connector
app/Dto/BillingUsage.php DTO mapping the full API response, including alert, credits, bandwidth, environment usage, and available periods
app/Commands/BillingUsage.php billing:usage command with summary and --detailed views
app/Client/Connector.php added the usage() method that returns a new UsageResource

Modified files

  • app/Client/Connector.php — wires in usage() resource method
  • README.md — documents the new billing commands

Usage

# Summary view
cloud billing:usage

# Full breakdown
cloud billing:usage --detailed

# Previous billing period
cloud billing:usage --period=1

# Filter by environment
cloud billing:usage --environment=<id>

# Machine-readable output
cloud billing:usage --json

I have tested this and it does work for me, I will include screenshots below.

Surfaces billing and usage data from GET /api/usage without
requiring a browser. Supports period offsets (0–3), optional
environment filter, --detailed breakdown (per-app, per-resource,
per-addon tables), and --json for CI/scripting use.
@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

Update BillingUsage to format item amounts using the `total_cents` field rather than `cost_cents`. This aligns the displayed values with the API response (which provides `total_cents`) and prevents showing incorrect/zero costs when `cost_cents` is absent.
@Frostist Frostist marked this pull request as ready for review April 21, 2026 10:43
@Frostist
Copy link
Copy Markdown
Author

One aspect I found is that application names are returned as a UUID. Not a human readable name. It is possible to create a name lookup map if the user has ran: cloud application:list

But what do you guys think? Could always do a background call if the user had to run: cloud billing:usage --detailed and then match the UUID's and print names instead.

@Frostist
Copy link
Copy Markdown
Author

Running the commands:

cloud billing:usage
image

cloud billing:usage --detailed
image

cloud billing:usage --period=1
image

cloud billing:usage --json
This just outputs everything as json

Allow the BillingUsage command to continue when an environmentId is provided even if the --detailed flag is not set, and add rendering for environment usage items. The change adds an environment usage table (Identifier, Type, Profile, CPU Hours, Cost) formatted with numeric CPU hours and cents via formatCents, and only shows it when environment usage data is present.
@Frostist
Copy link
Copy Markdown
Author

For the command: cloud billing:usage --environment=

I had to do some tweaking to get the data to come through nicely but here it is:
image2

Removed note about JSON output support for billing commands.
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