MergeCost

How the estimate works

MergeCost measures what your code does, scales it to production, and prices the difference. Here is every step.

1. Measure

While your tests run, the MergeCost recorder wraps your framework’s request handling. For every request a test makes it records:

  • the endpoint (method and route template) and the view or handler,
  • each SQL statement, normalized into a fingerprint (id = 5 → id = ?), with the project line that ran it,
  • outbound HTTP calls by host,
  • LLM calls with real token usage from the SDK response,
  • log bytes at your production log level, and response size.

Queries run by test fixtures outside a request are ignored.

2. Compare base and head

The tests run twice: on the pull request’s base commit and on its head commit. Per endpoint, the median of each metric is compared. A new query repeated from one line (by default three or more times in a request) is reported as an N+1, with a fix suggestion for your stack.

3. Scale to production

Tests create a few rows; production pages show more. Anything that runs once per item — an N+1 query group, an LLM or HTTP call per item, a log line per item — is rescaled from the test item count to collection_size. Example: 5 posts in a test, 50 per page in production, so 5 author queries become 50.

4. Price

monthly requests = requests per day × 30.44

LLM        = Δ input tokens × input price + Δ output tokens × output price   (±10%; ±50% if tokens unknown)
Database   = Δ queries × monthly requests × 0.3–1.5 ms × (DB monthly cost ÷ usable DB milliseconds per month)
Logs       = Δ bytes × monthly requests ÷ 10⁹ × $ per GB ingested           (±20%)
Egress     = Δ response bytes × external fraction × monthly requests ÷ 10⁹ × $ per GB   (±20%)
Paid APIs  = Δ calls × monthly requests × $ per call

Unit prices come from a regularly verified table — AWS CloudWatch Logs, data transfer and Aurora I/O; OpenAI and Anthropic per-token prices — and can be overridden in .mergecost.yml.

Worked example

A PR adds one gpt-4o-mini call per post on GET /feed (50 posts per page, 200,000 requests a day, 120 input and 40 output tokens per call):

per request = 50 × (120 × $0.15 + 40 × $0.60) / 1,000,000 = $0.0021
per month   = $0.0021 × 200,000 × 30.44 ≈ $12,785  →  shown as $11,506 – $14,063

Confidence levels

LevelWhen
HighTraffic measured by the production SDK and a directly priced metric (LLM tokens, logs, egress, paid APIs).
MediumTraffic from .mergecost.yml, a database estimate, or production scaling applied.
LowToken usage or model price unknown, or default traffic.

Limits

  • Endpoints your tests never call are not measured. The static scan flags risky calls added inside loops instead, without dollars.
  • If a test replaces an SDK method entirely with a mock, its calls are invisible to measurement.
  • Database cost approximates capacity used. Set database.current_utilization to get “upsize likely” warnings.