Skip to content

Optimize

optimize replays your observed token mix against one or more candidate model prices.

llm-usage optimize <daily|weekly|monthly> --candidate-model <model> [options]
Terminal window
# Compare two OpenAI candidates for monthly usage
llm-usage optimize monthly \
--provider openai \
--candidate-model gpt-4.1 \
--candidate-model gpt-5-codex
# Keep only the cheapest candidate in output
llm-usage optimize weekly \
--provider openai \
--candidate-model gpt-4.1,gpt-5-codex \
--top 1 \
--json
# Write an interactive HTML report
llm-usage optimize monthly \
--provider openai \
--candidate-model gpt-4.1 \
--candidate-model gpt-5-codex \
--share
  • Uses the same source discovery and filtering pipeline as usage reports.
  • Requires at least one --candidate-model.
  • Prices one provider’s usage. When several providers remain after filtering and no --provider is given, the provider of the candidate models is used if it is one of them; otherwise narrow with --provider.
  • --provider matches canonical billing entities after provider normalization.
  • Provider aliases are normalized to billing roots first (for example, openai-codex is treated as openai).
  • Candidate ranking is deterministic and based on ALL period hypothetical cost; every candidate you pass is listed; --top N keeps the N cheapest (--top 0 lists all).
  • Without date flags, the report covers your full history; --last N covers the last N periods of the granularity (days, weeks, or months), counting the current one. The shared filters apply, including --repo to price only some projects.
  • Missing candidate pricing on non-zero token periods marks candidate cost as incomplete.
  • A candidate without a published cache-write rate bills cache creation as regular input (as OpenAI-style automatic caching does), so baseline cache writes are priced at its input rate and the row carries the cache_write_priced_as_input note.
  • If baseline cost is incomplete, savings fields are omitted.
  • If all billable token buckets are zero but baseline has cost, savings are omitted and a warning is emitted to stderr.
  • --json emits optimize rows under data in the versioned report envelope.
  • --markdown emits a Provider scope: line, then a Markdown table.
  • Default terminal output renders a titled table under the provider scope, the ALL baseline cost and the best candidate. When the table is wider than the terminal, it leaves out Hypothetical Cost if every row still shows it to the cent as Baseline Cost minus Savings, and lists each row on its own if it still does not fit. Notes are never left out; on a terminal they wrap between note codes.
  • --share writes an interactive report optimize-<granularity>-share.html, with the candidate comparison as a panel, to the current working directory.
  • Diagnostics and warnings always go to stderr.