LLM MeasurementGitHub
Guides

LiteLLM spend tracking: see who drove a spend increase

fleetdiff reads your LiteLLM spend logs and tells you what changed between the last two weeks: which models and keys drove it, and which records look incomplete. It runs on your machine and only reads.

Need database access?

Create a read-only login

LiteLLM keeps its spend logs in the Postgres database named in the proxy's DATABASE_URL setting. Ask whoever runs the proxy for a read-only login on that database. These statements create one that can read only the columns fleetdiff uses:

CREATE ROLE fleetdiff_reader LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE
  NOINHERIT NOREPLICATION NOBYPASSRLS;
GRANT CONNECT ON DATABASE litellm TO fleetdiff_reader;
GRANT USAGE ON SCHEMA public TO fleetdiff_reader;
GRANT SELECT (
  request_id, call_type, api_key, "user", team_id, organization_id, end_user,
  model, model_id, model_group, custom_llm_provider,
  prompt_tokens, completion_tokens, total_tokens, spend, status,
  session_id, agent_id, "startTime", "endTime", metadata
) ON TABLE public."LiteLLM_SpendLogs" TO fleetdiff_reader;
ALTER ROLE fleetdiff_reader SET default_transaction_read_only = on;

For --daily:

GRANT SELECT (date, api_requests, successful_requests, failed_requests)
  ON TABLE public."LiteLLM_DailyUserSpend" TO fleetdiff_reader;

Remote databases need TLS with certificate checks (sslmode=verify-full).

Already have an export file?

If you already export LiteLLM's spend logs as CSV, JSON or JSONL, point fleetdiff at the file:

./bin/fleetdiff investigate --litellm-spend ./spend.csv --group-by key
Export with psql instead

Set BEFORE and AFTER to 16 days of RFC3339 UTC bounds, as below.

set -eu
umask 077
# Replace these RFC3339 UTC bounds with 16 days of your data; end is exclusive.
# File analysis leaves out the potentially partial first and last days.
BEFORE=2026-09-23T00:00:00Z
AFTER=2026-10-09T00:00:00Z
curl -fsSLo export.sql https://raw.githubusercontent.com/llm-measurement/fleetdiff/v0.14.1/examples/litellm-spend/export.sql
mkdir ./litellm-export
psql 'service=litellm_readonly' -Xq -v ON_ERROR_STOP=1 \
  -v start_utc="$BEFORE" \
  -v end_utc="$AFTER" \
  -v csv_file='./litellm-export/spend.csv' -f export.sql \
  >./litellm-export/private-psql.out 2>./litellm-export/private-psql.err
printf 'Exported request-level rows to ./litellm-export/spend.csv\n'

Or use its exported path:

./bin/fleetdiff investigate --litellm-spend ./litellm-export/spend.csv --group-by key
Security and access
  • fleetdiff reads one read-only snapshot. It never writes to your database, and it doesn't read prompts or responses.
  • Remote databases must use sslmode=verify-full. Only a local socket may skip TLS.
  • The connection URL comes from an owner-only file or the FLEETDIFF_LITELLM_DATABASE_URL environment variable, never from the command line.
  • Analysis happens on your machine. Nothing is sent anywhere else. Reports use aliases instead of raw keys.

Full details: security review.

Try the sample

Linux or macOS; needs curl, gh, shasum and tar. The installer checks the release before unpacking it.

curl -fsSLo fleetdiff-source.tar.gz https://github.com/llm-measurement/fleetdiff/archive/refs/tags/v0.14.1.tar.gz
tar -xzf fleetdiff-source.tar.gz
cd fleetdiff-0.14.1
sh scripts/install.sh v0.14.1 ./release
./release/fleetdiff investigate --litellm-spend examples/litellm-spend/synthetic.csv \
  --before-period 2026-10-07 --after-period 2026-10-08

What you'll see

Example output from this synthetic sample; your values will reflect your input.

Recorded tokens doubled (8,000 -> 16,000).
model-1 accounts for 100% of the net recorded increase (+8,000 tokens).
Logged model requests: 8 -> 12.

Recorded tokens doubled, while logged model requests grew from eight to twelve. fleetdiff separates model-by-model usage changes from contributor rankings and completeness.

Who drove the increase?
  key-1: 5,000 -> 10,000 tokens; change +5,000.
  key-2: 1,000 -> 4,000 tokens; change +3,000.
  key-3: 2,000 -> 2,000 tokens; change +0.
  2 leading tracked keys account for 100% of the net recorded increase.
  Attributed tokens: 8,000 -> 16,000.

Two keys account for the increase. The contributor section uses local aliases for the keys.

How complete is the export?
  Records needing usage review (categories may overlap): 2 -> 4.
  Zero-only records, origin unknown: 2 -> 4.
  Failed records (overlap usage categories): 1 -> 2.

The completeness section points to zero-only and failed records worth checking in LiteLLM. To check usage and identity fields in your telemetry, see Do my LLM traces record token usage and user IDs?

To compare the number of exported rows with LiteLLM's daily request counts, see Are all our requests actually in the spend log?. To see the model mix behind an original route, use the routing audit. To re-price the recorded usage under another model mix, see What would switching models have cost?

Source and reproduction: released synthetic CSV and accounting and privacy checks. Verification record.

What the numbers mean

these are the tokens and spend LiteLLM recorded, not your provider invoice. A change between periods shows what moved, not why.
Measurement notes

evijay+fleetdiff@gmail.com · Questions · Ran it on your data? Tell us what it found · Security issues (private)