cfaicost

command module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cfaicost

cfaicost fetches Cloudflare AI Gateway logs and prints a cost report for one user.

Install

go install github.com/almahoozi/cfaicost@latest

Make sure Go's install directory is in your PATH, then run:

cfaicost setup

Setup asks for your Cloudflare account ID, gateway name, user ID, and API token. The account, gateway, and user ID are saved in the user configuration directory. The token is saved in the operating system keychain.

To replace the token later:

cfaicost set-token

Usage

With no arguments, cfaicost fetches the last 30 days and prints a report grouped by session and provider/model:

cfaicost

The report includes request counts, sessions, costs, and totals by model. Historical days are cached locally; today is always fetched. Use -f to fetch everything again.

For session grouping and filtering to work, your requests must include an x-session-id metadata header.

Options
  • -d 7d — look back over a duration. Go durations such as 168h also work.
  • --start TIME --end TIME — use an explicit RFC3339 time range.
  • --daily — include daily totals.
  • --all — include daily totals for each provider/model. Requires --daily.
  • --tokens — show input and output token counts.
  • --join — combine all models used in a session into one row.
  • -u USER — fetch the report for a different user ID than the configured user.
  • --session ID — show only one session.
  • --ua — show user-agent values.
  • --column LABEL:KEY — add a metadata column, for example --column Region:cf.region.
  • --raw — print the report's Markdown source.
  • --utc — display times in UTC instead of local time.
  • -f — refetch data instead of using cached historical days.

For example:

cfaicost -d 7d --daily --tokens

To fetch a report for another user:

cfaicost -u USER_ID

Saved defaults

Set the report options you want to use every time:

cfaicost set-defaults --mode=base --ua --join

This saves settings like:

"defaults": {
  "mode": "base",
  "ua": true,
  "join": true
}

With default mode, saved options are used only when you run cfaicost without other report options. With base mode, saved options are used first and can be combined with other options. The --force and --session options do not disable saved defaults.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL