Static cost analysis for LLM workloads. Estimate spend, enforce budgets, diff costs in CI/CD.
# No config needed
llm-cost estimate prompt.txt --model gpt-4oprompt.txt
Tokens: 1,847 input + 523 output (est.)
Cost: $0.0041 (gpt-4o)
llm-cost estimate prompt.txt --model gpt-4o --scenario cached --cache-hit-ratio 0.6Scenario Cost Savings
default $0.0052 —
cached@60% $0.0033 -37%
curl -sSfL https://get.llm-cost.dev | shWindows is not currently supported via the install script.
Options:
- WSL2 (recommended): Use the Linux install method.
- Manual: Download
llm-cost-windows-x86_64.exefrom Releases.
CI/CD on Windows:
- name: Install llm-cost
run: |
Invoke-WebRequest -Uri "https://github.com/rul1an/llm-cost/releases/latest/download/llm-cost-windows-x86_64.exe" -OutFile "llm-cost.exe"
.\llm-cost.exe --versionllm-cost provides a native GitHub Action for seamless integration.
Fails the build on policy violations and uploads results to GitHub Advanced Security.
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- name: llm-cost check (SARIF)
uses: Rul1an/llm-cost@v1
with:
command: check
format: sarif
# Optional: path to actuals
# actuals: usage.csv
# Fail build on error-level violations
fail-on-error: true
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: llm-cost.sarif
category: llm-costPerforms budget checks and posts a sticky comment on the PR.
- uses: Rul1an/llm-cost@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Optional: absolute budget enforcement
budget: "10.00"
# Optional: fail if cost increases
fail-on-increase: truellm-cost init # Generate manifest from prompt files
llm-cost check --budget 5.00 # Local budget enforcement
llm-cost diff --base main # Compare costs vs branchExample llm-cost.toml:
[defaults]
model = "gpt-4o"
[[prompts]]
path = "prompts/search.txt"
prompt_id = "search"
tags = { team = "platform", app = "search" }Close the loop by comparing your estimates against actual billing data (FOCUS v1.0 CSV). Detect "Shadow AI" (unapproved usage) and drift.
# 1. Generate estimates map
llm-cost export --format=json > estimates.json
# 2. Compare against actuals (with fuzzy matching)
llm-cost calibrate \
--estimates estimates.json \
--actuals billing-data.csv \
--match fuzzy > factors.tomlOutput factors.toml contains drift multipliers (e.g., 1.05 for +5% drift) and confidence scores.
Export FOCUS 1.0 CSV for Vantage, CloudZero, or any FOCUS-compliant tool:
llm-cost export --format focus -o costs.csvFilter and group by Tags.team, Tags.app, or Tags.model in your FinOps dashboard.
| Command | Purpose |
|---|---|
estimate |
Cost estimate for prompt files (alias: price is deprecated) |
count |
Token count only |
check |
Budget/policy enforcement |
diff |
Cost comparison between git refs |
calibrate |
Drift analysis vs actual billing data |
export |
FOCUS CSV for FinOps tools |
pipe |
Stream JSON usage → cost output |
update-db |
Refresh pricing database |
Note: Global flags (--quiet, --verbose) can be placed anywhere in the command.
- Offline: No API keys, no telemetry. Network only for explicit
update-db. - Exact: BPE tokenizer with tiktoken parity (o200k_base, cl100k_base).
- Signed: Pricing updates verified via Ed25519/TUF-lite manifest system.
- Fast: ~10 MB/s throughput, O(N) complexity.
- SLSA Level 2 build provenance
- Artifact attestations via Sigstore
- Minisign-verified pricing database
- Zero runtime network calls
src/core/pricing/pricing_db.json contains standard rates.
Note: For Anthropic prompt caching, we default to the 5-minute cache write tier.
- OpenAI: Updated to latest rates (see
src/core/pricing/pricing_db.json). - Anthropic: Claude 3.5 Sonnet supports prompt caching rates.
llm-cost is engineered for Enterprise FinOps. It goes beyond simple estimation to provide audit-grade validation.
- P0/P1 Validation Suite: Every commit is verified against a rigorous regression test suite covering determinism, schema integrity, and scale (1M+ rows).
- Cost Integrity Reporting: Automated "Cost Integrity Cards" in GitHub Pull Requests report drift (BPS), logic hashes, and PII leakage.
- Fail-Fast Policy: Strict exit codes (
2) ensures no "garbage-in/garbage-out" in data pipelines. - FOCUS Compliant: Native support for the FinOps Open Cost & Usage Specification (v1.0).
| Metric | Status |
|---|---|
| Schema | 🟢 PASS |
| Logic | 🟢 PASS |
| Drift | 🟢 PASS |
Verify releases:
gh attestation verify llm-cost-linux-amd64 --repo Rul1an/llm-costSee docs/VERIFICATION.md.
MIT