Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Static cost analysis for LLM workloads. Catch budget overruns before they hit production — like Infracost, but for AI. Offline-first, single binary.

License

Notifications You must be signed in to change notification settings

Rul1an/llm-cost

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

222 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

llm-cost

Static cost analysis for LLM workloads. Estimate spend, enforce budgets, diff costs in CI/CD.

CI Release License Website

30 Seconds to Value

# No config needed
llm-cost estimate prompt.txt --model gpt-4o
prompt.txt
  Tokens: 1,847 input + 523 output (est.)
  Cost:   $0.0041 (gpt-4o)

See Cache Impact

llm-cost estimate prompt.txt --model gpt-4o --scenario cached --cache-hit-ratio 0.6
Scenario    Cost      Savings
default     $0.0052   —
cached@60%  $0.0033   -37%

Installation

Linux & macOS

curl -sSfL https://get.llm-cost.dev | sh

Windows

Windows is not currently supported via the install script.

Options:

  1. WSL2 (recommended): Use the Linux install method.
  2. Manual: Download llm-cost-windows-x86_64.exe from 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 --version

CI/CD Integration

llm-cost provides a native GitHub Action for seamless integration.

1. CI-Native (SARIF Reporting)

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-cost

2. Pull Request Commenter (Legacy)

Performs 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: true

Project Setup

llm-cost init                      # Generate manifest from prompt files
llm-cost check --budget 5.00       # Local budget enforcement
llm-cost diff --base main          # Compare costs vs branch

Example llm-cost.toml:

[defaults]
model = "gpt-4o"

[[prompts]]
path = "prompts/search.txt"
prompt_id = "search"
tags = { team = "platform", app = "search" }

Calibration (Drift Analysis)

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.toml

Output factors.toml contains drift multipliers (e.g., 1.05 for +5% drift) and confidence scores.

FinOps Export

Export FOCUS 1.0 CSV for Vantage, CloudZero, or any FOCUS-compliant tool:

llm-cost export --format focus -o costs.csv

Filter and group by Tags.team, Tags.app, or Tags.model in your FinOps dashboard.

Commands

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.

How It Works

  • 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.

Security

  • SLSA Level 2 build provenance
  • Artifact attestations via Sigstore
  • Minisign-verified pricing database
  • Zero runtime network calls

Pricing Database

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.

🛡️ FinOps Certified (v1.3.0)

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-cost

See docs/VERIFICATION.md.

Documentation

License

MIT

About

Static cost analysis for LLM workloads. Catch budget overruns before they hit production — like Infracost, but for AI. Offline-first, single binary.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •