Skip to content

Commit 696a4fd

Browse files
committed
feat(economy): verified OpenAI rates — the ledger's first real est_saved_usd (dogfood cycle 5)
gpt-4.1 (2.0, 8.0) and gpt-4.1-mini (0.4, 1.6) per MTok, live-verified 2026-06-12 (OpenAI pricing page + two independent trackers), recorded in MODEL-ECONOMY.md §1 as the canonical refresh source. Prefix pricing is now longest-first so versioned ids price by most-specific match. On the repo's real telemetry: 8/8 calls priced, est 0.0126 vs naive 0.3122 USD — est_saved_usd 0.2996 (96%), measured not claimed. 272 tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 2121cbb commit 696a4fd

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

docs/product/MODEL-ECONOMY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
| Claude Sonnet 4.6 | $3 / $15 | Anthropic's explicit "default for most coding" |
1515
| Claude Opus 4.8 | $5 / $25 | per-TURN cost is "several times" Sonnet (deeper-thinking turns consume more tokens — multiplier unpublished, measure locally) |
1616
| Claude Fable 5 | $10 / $50 | tokenizer emits ~30–35% MORE tokens for the same content → effective per-content cost exceeds the 2× sticker vs Opus. Reserve strictly. |
17+
| gpt-4.1 | $2 / $8 | live-verified 2026-06-12 |
18+
| gpt-4.1-mini | $0.40 / $1.60 | live-verified 2026-06-12 |
1719
| Codex GPT-5.5 | 125/12.5/750 credits per MTok | ~5–45 credits per typical task |
1820
| Codex GPT-5.4 | 62.5/6.25/375 credits | Sonnet-analog on the Codex side |
1921
| Codex GPT-5.4-Mini | 18.75/1.875/113 credits | ~6.7× cheaper input than 5.5 — Codex's own haiku-class |

prd_taskmaster/economy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"claude-sonnet-4-6": (3.0, 15.0),
2424
"claude-opus-4-8": (5.0, 25.0),
2525
"claude-fable-5": (10.0, 50.0),
26+
"gpt-4.1": (2.0, 8.0),
27+
"gpt-4.1-mini": (0.4, 1.6),
2628
}
2729

2830
NAIVE_BASELINE_MODEL = "claude-fable-5"
@@ -125,7 +127,7 @@ def _price_key_for_model(model):
125127
return None
126128
if model in PRICES_PER_MTOK:
127129
return model
128-
for price_key in PRICES_PER_MTOK:
130+
for price_key in sorted(PRICES_PER_MTOK, key=len, reverse=True):
129131
if model.startswith(price_key + "-"):
130132
return price_key
131133
return None

tests/core/test_economy_report.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""T7: economy-report — telemetry summary per (op_class, model)."""
22

33
import json
4+
from pathlib import Path
45

56
import pytest
67

7-
from prd_taskmaster.economy import append_telemetry, summarize_telemetry
8+
from prd_taskmaster.economy import PRICES_PER_MTOK, append_telemetry, summarize_telemetry
9+
10+
REPO_ROOT = Path(__file__).resolve().parents[2]
811

912

1013
def _rows():
@@ -44,6 +47,13 @@ def test_summarize_skips_malformed_lines(tmp_path):
4447
assert rep["total_calls"] == 1 and rep["skipped_lines"] == 1
4548

4649

50+
def test_model_economy_docs_include_verified_openai_price_rows():
51+
content = (REPO_ROOT / "docs" / "product" / "MODEL-ECONOMY.md").read_text()
52+
53+
assert "| gpt-4.1 | $2 / $8 | live-verified 2026-06-12 |" in content
54+
assert "| gpt-4.1-mini | $0.40 / $1.60 | live-verified 2026-06-12 |" in content
55+
56+
4757
def test_summarize_costs_priced_unpriced_unknown_and_corrupt(tmp_path):
4858
rows = [
4959
{
@@ -105,6 +115,50 @@ def test_summarize_costs_priced_unpriced_unknown_and_corrupt(tmp_path):
105115
assert costs["priced_coverage"] == pytest.approx(0.5)
106116

107117

118+
def test_verified_openai_price_math_from_prd(tmp_path):
119+
f = tmp_path / "telemetry.jsonl"
120+
f.write_text(json.dumps({
121+
"op_class": "structured_gen",
122+
"model": "gpt-4.1-mini",
123+
"exit": 0,
124+
"wall_ms": 100,
125+
"tokens_in": 384,
126+
"tokens_out": 1240,
127+
"escalated": False,
128+
}) + "\n")
129+
130+
rep = summarize_telemetry(f)
131+
132+
assert PRICES_PER_MTOK["gpt-4.1"] == (2.0, 8.0)
133+
assert PRICES_PER_MTOK["gpt-4.1-mini"] == (0.4, 1.6)
134+
costs = rep["costs"]
135+
assert costs["est_cost_usd"] == pytest.approx(0.0021376)
136+
assert costs["naive_cost_usd"] == pytest.approx(0.06584)
137+
assert costs["est_saved_usd"] == pytest.approx(0.0637024)
138+
assert costs["priced_calls"] == 1
139+
assert costs["unpriced_calls"] == 0
140+
assert costs["priced_coverage"] == pytest.approx(1.0)
141+
142+
143+
def test_versioned_openai_model_id_prices_by_most_specific_prefix(tmp_path):
144+
f = tmp_path / "telemetry.jsonl"
145+
f.write_text(json.dumps({
146+
"op_class": "structured_gen",
147+
"model": "gpt-4.1-mini-2025-04-14",
148+
"exit": 0,
149+
"wall_ms": 100,
150+
"tokens_in": 384,
151+
"tokens_out": 1240,
152+
"escalated": False,
153+
}) + "\n")
154+
155+
costs = summarize_telemetry(f)["costs"]
156+
157+
assert costs["est_cost_usd"] == pytest.approx(0.0021376)
158+
assert costs["priced_calls"] == 1
159+
assert costs["unpriced_calls"] == 0
160+
161+
108162
def test_append_telemetry_returns_row_reference(tmp_path):
109163
f = tmp_path / "telemetry.jsonl"
110164
first = {

0 commit comments

Comments
 (0)