Optimize
optimize replays your observed token mix against one or more candidate model prices.
llm-usage optimize <daily|weekly|monthly> --candidate-model <model> [options]Examples
Section titled “Examples”# Compare two OpenAI candidates for monthly usagellm-usage optimize monthly \ --provider openai \ --candidate-model gpt-4.1 \ --candidate-model gpt-5-codex
# Keep only the cheapest candidate in outputllm-usage optimize weekly \ --provider openai \ --candidate-model gpt-4.1,gpt-5-codex \ --top 1 \ --json
# Write an interactive HTML reportllm-usage optimize monthly \ --provider openai \ --candidate-model gpt-4.1 \ --candidate-model gpt-5-codex \ --shareCommand behavior
Section titled “Command behavior”- 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
--provideris given, the provider of the candidate models is used if it is one of them; otherwise narrow with--provider. --providermatches canonical billing entities after provider normalization.- Provider aliases are normalized to billing roots first (for example,
openai-codexis treated asopenai). - Candidate ranking is deterministic and based on
ALLperiod hypothetical cost; every candidate you pass is listed;--top Nkeeps the N cheapest (--top 0lists all). - Without date flags, the report covers your full history;
--last Ncovers the last N periods of the granularity (days, weeks, or months), counting the current one. The shared filters apply, including--repoto price only some projects.
Missing pricing and incomplete baselines
Section titled “Missing pricing and incomplete baselines”- 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_inputnote. - 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.
Output formats
Section titled “Output formats”--jsonemits optimize rows underdatain the versioned report envelope.--markdownemits aProvider scope:line, then a Markdown table.- Default terminal output renders a titled table under the provider scope, the
ALLbaseline 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. --sharewrites an interactive reportoptimize-<granularity>-share.html, with the candidate comparison as a panel, to the current working directory.- Diagnostics and warnings always go to
stderr.