Skip to content

tokenmeter CLI and Go client - #23

Merged
coyl merged 2 commits into
mainfrom
feat/tokenmeter-cli
Oct 24, 2026
Merged

coyl merged 2 commits into
mainfrom
feat/tokenmeter-cli

Conversation

@coyl

@coyl coyl commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Closes ai-process/docs#132 (epic ai-process/docs#137), except tokenmeter mcp (#133).

  • CLI cmd/tokenmeter: usage summary|top|by-meta|export, token new|hash, event send, health, context set|use|list|delete|store-token, completion, version.
    • Windows --last 7d or --from/--to (RFC 3339 or YYYY-MM-DD, UTC). A truncated window is split in halves down to an hour and merged, so totals are complete.
    • Tables with USD; -o json (protojson fields), -o csv with exact dollars (cost_nanousd / 1e9 without float rounding).
    • Token from --token-file, TOKENMETER_TOKEN or the context (env, 0600 file, macOS Keychain / secret-tool); never from a flag value.
    • Exit codes by class as in ktms: 2 usage, 4 auth, 5 not found, 6 rejected, 7 retry.
  • pkg/client: New, Record (batches of 500), Summary (window splitting), ByMeta, Merge, ParseDuration.
  • /healthz reports version.
  • Release: .goreleaser.yaml puts CLI archives, SBOMs and a cosign-signed checksums.txt on the draft release (binaries job, before publish); coyl/tokenmeter-cli image in the docker matrix; Homebrew formula skipped until HOMEBREW_TAP_TOKEN exists. SECURITY.md covers verifying the archives.
  • Tests: CLI against the real gRPC and HTTP servers on Postgres (scopes, sums, CSV, by-meta, health); client splitting and merging; scripts/cli-e2e.sh (CI job cli-e2e) against a built image on Postgres alone and with ClickHouse, checking USD against cost_nanousd.
  • README section, pkg/client and CLI marked Experimental until 1.2.

coyl added 2 commits October 24, 2026 02:20
usage summary, top, by-meta and export with totals in USD, fetching
windows the server caps in parts; token new and hash for
TOKENMETER_TOKENS; event send; health, now with the version in /healthz.
Contexts keep the token in the environment, a 0600 file or the system
keychain. pkg/client wraps the gRPC API. Released as archives with signed
checksums, the coyl/tokenmeter-cli image and a Homebrew formula; an
end-to-end job runs the CLI against a built service with and without
ClickHouse.
Private files are written through a fresh temporary file; a context named
on the command line beats the environment; keychain writes are read back,
as security -i exits 0 on failure; capped windows are fetched with up to
eight calls in flight; long durations are refused, not wrapped; exports
to a file are renamed into place only when complete; TOKENMETER_TLS must
be a boolean.
@coyl
coyl merged commit cbfdef7 into main Oct 24, 2026
6 checks passed
@coyl
coyl deleted the feat/tokenmeter-cli branch October 24, 2026 00:29
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