#!/usr/bin/env python3 """Deploy Grade: LLM API cost-per-task calculator (Oct 2026, Mistral and Gemini re-read Nov 4). Reproducible: `python3 compute.py` rewrites prices.csv and cost-per-task.csv next to this file. All prices are USD per 1M tokens, copied by hand from the official pages listed in SOURCES. OpenAI and xAI pricing pages accessed Wed Oct 21, 2026, 9:16 AM PT (sources/2026-10-21/). Anthropic pricing accessed Mon Oct 19, 2026, 11:26 PM PT. Mistral pricing, batch, and caching pages and the Gemini pricing page re-read Wed Nov 4, 2026, 3:01–3:05 PM PT (sources/2026-11-04/reread-2026-11-04.md). Updated Nov 13, 2026: Claude Fable 5.2 and Gemini 4 Carbon rows added from captures taken Fri Nov 13, 2026, 5:57–5:58 AM PT (per-row "accessed"); Gemini source URL is now aistudio.google.com/docs/pricing (the old ai.google.dev URL redirects there); the "flagship" role is dropped only from Claude Fable 5.1, Claude Opus 5.5, Gemini 4 Argon and Mistral Large 4 (Large 4 is GA since Nov 5, 2026; model card re-read Nov 13, 6:54 AM PT); GPT-6 Astra and Grok 4.7 keep it. Tier labels are Deploy Grade's grouping. Existing prices and costs are unchanged. Every token count in TASKS is a Deploy Grade ASSUMPTION, not a measurement. Every cost output is a Deploy Grade calculation from list prices. """ import csv, math, os HERE = os.path.dirname(os.path.abspath(__file__)) # Access time of the pricing page each vendor's prices came from (true logged fetch times, PT). ACCESSED_BY_VENDOR = { "OpenAI": "2026-10-21 09:16:16 PT (sources/2026-10-21/openai_pricing.md)", "Anthropic": "2026-10-19 23:26:34 PT (sources/anthropic_pricing.html; .md 23:27:10)", "Google": "2026-11-04 15:01:49 PT (sources/2026-11-04/reread-2026-11-04.md)", "xAI": "2026-10-21 09:16:13 PT (sources/2026-10-21/xai_pricing.md)", "Mistral": "2026-11-04 15:01:24 PT (sources/2026-11-04/reread-2026-11-04.md)", } ACCESSED = ACCESSED_BY_VENDOR["Anthropic"] # default; per-row value comes from the vendor map SOURCES = { "openai": "https://developers.openai.com/api/docs/pricing", "anthropic": "https://platform.claude.com/docs/en/about-claude/pricing", "google": "https://aistudio.google.com/docs/pricing", "xai": "https://docs.x.ai/developers/pricing", "mistral": "https://docs.mistral.ai/inference/pricing", } # Each model: # std / batch: dict(inp, cached, write, out) USD per 1M tokens. # cached = price of a cache hit (read). write = cache-write price (None = no write # price listed; first request is billed at the normal input price). # batch = None means no batch discount is documented for the model. # long: (threshold_tokens, rule, std_long dict, batch_long dict or None) or None. # rule "gt" = more than threshold; "ge" = threshold or more. Whole request repriced. # cache_min: documented minimum cacheable prefix in tokens (None = not disclosed). # cache_block: Mistral caches in 64-token blocks. # batch_cache_stacks: True only where the vendor documents cached prices in batch. def P(inp, cached, write, out): return dict(inp=inp, cached=cached, write=write, out=out) MODELS = [ # ---------------- OpenAI ---------------- dict(vendor="OpenAI", name="GPT-6 Astra", id="gpt-6-astra", role="flagship", std=P(10.00, 1.00, 12.50, 50.00), batch=P(5.00, 0.50, 6.25, 25.00), long=(272_000, "gt", P(20.00, 2.00, 25.00, 75.00), P(10.00, 1.00, 12.50, 37.50)), cache_min=1024, batch_cache_stacks=True, src=SOURCES["openai"], note="Short context <=272K input tokens; long context >272K billed for the full request."), dict(vendor="OpenAI", name="GPT-6.1 Sol", id="gpt-6.1-sol", role="mid", std=P(2.00, 0.10, 2.50, 10.00), batch=P(1.00, 0.05, 1.25, 5.00), long=(272_000, "gt", P(4.00, 0.20, 5.00, 15.00), P(2.00, 0.10, 2.50, 7.50)), cache_min=1024, batch_cache_stacks=True, src=SOURCES["openai"], note="Cached input is 5% of input; cache writes 1.25x input."), dict(vendor="OpenAI", name="GPT-6 Luna", id="gpt-6-luna", role="small", std=P(0.10, 0.01, 0.125, 0.50), batch=P(0.05, 0.005, 0.0625, 0.25), long=(272_000, "gt", P(0.20, 0.02, 0.25, 0.75), P(0.10, 0.01, 0.125, 0.375)), cache_min=1024, batch_cache_stacks=True, src=SOURCES["openai"], note="Cached input is 10% of input."), # ---------------- Anthropic ---------------- dict(vendor="Anthropic", name="Claude Fable 5.2", id="claude-fable-5-2", role="added Nov 13, 2026", std=P(8.00, 0.20, 10.00, 40.00), batch=P(4.00, 0.10, 5.00, 20.00), long=None, cache_min=None, batch_cache_stacks=True, accessed="2026-11-13 05:57–05:58 PT (research capture bc-drift-verify-2026-11-13/anthropic_api.txt of https://platform.claude.com/docs/en/about-claude/pricing)", src=SOURCES["anthropic"], note="Pricing page lists $8 input, $10 5-minute cache write, $0.20 cache hit, $40 output; batch $4 / $20. Batch cache prices $0.10 (hit) and $5.00 (write) are a Deploy Grade calculation at 50% of the list $0.20 and $10.00; the pricing page lists batch input and output only, with no batch cache prices, and says: \"These multipliers stack with other pricing modifiers, including the Batch API discount and data residency.\" Minimum cacheable length not in the capture."), dict(vendor="Anthropic", name="Claude Fable 5.1", id="claude-fable-5-1", role="—", std=P(10.00, 0.25, 12.50, 50.00), batch=P(5.00, 0.125, 6.25, 25.00), long=None, cache_min=512, batch_cache_stacks=True, src=SOURCES["anthropic"], note="5-minute cache write 1.25x; cache hit 0.025x. Batch cache prices = 50% x listed cache prices (pricing page: multipliers stack with Batch)."), dict(vendor="Anthropic", name="Claude Opus 5.5", id="claude-opus-5-5", role="— (Anthropic's suggested default)", std=P(4.00, 0.20, 5.00, 20.00), batch=P(2.00, 0.10, 2.50, 10.00), long=None, cache_min=512, batch_cache_stacks=True, src=SOURCES["anthropic"], note="Cache hit 0.05x base input."), dict(vendor="Anthropic", name="Claude Sonnet 5.5", id="claude-sonnet-5-5", role="mid", std=P(2.00, 0.10, 2.50, 10.00), batch=P(1.00, 0.05, 1.25, 5.00), long=None, cache_min=512, batch_cache_stacks=True, src=SOURCES["anthropic"], note="Cache hit 0.05x base input."), dict(vendor="Anthropic", name="Claude Haiku 5.5", id="claude-haiku-5-5", role="small", std=P(0.10, 0.01, 0.125, 0.50), batch=P(0.05, 0.005, 0.0625, 0.25), long=(100_000, "gt", P(0.50, 0.05, 0.625, 2.50), P(0.25, 0.025, 0.3125, 1.25)), cache_min=512, batch_cache_stacks=True, src=SOURCES["anthropic"], note="Prompts over 100,000 tokens (incl. cache reads/writes) pay the higher rates for the whole request."), # ---------------- Google ---------------- dict(vendor="Google", name="Gemini 4 Carbon (intro price, through Nov 30)", id="gemini-4-carbon", role="added Nov 13, 2026", std=P(2.00, 0.10, None, 10.00), batch=P(1.00, 0.05, None, 5.00), long=None, cache_min=None, batch_cache_stacks=True, accessed="2026-11-13 05:57–05:58 PT (research capture bc-drift-verify-2026-11-13/google_aistudio.txt of https://aistudio.google.com/docs/pricing)", src=SOURCES["google"], note="Implicit caching only (explicit caching is not supported). Minimum cacheable length not in the capture."), dict(vendor="Google", name="Gemini 4 Carbon (from Dec 1, 2026)", id="gemini-4-carbon", role="added Nov 13, 2026 (scheduled price)", std=P(4.00, 0.20, None, 20.00), batch=P(2.00, 0.10, None, 10.00), long=None, cache_min=None, batch_cache_stacks=True, accessed="2026-11-13 05:57–05:58 PT (research capture bc-drift-verify-2026-11-13/google_aistudio.txt of https://aistudio.google.com/docs/pricing)", src=SOURCES["google"], note="Price the page says starts December 1, 2026."), dict(vendor="Google", name="Gemini 4 Argon (intro price, through Nov 30)", id="gemini-4-argon", role="—", std=P(2.00, 0.10, None, 10.00), batch=P(1.00, 0.05, None, 5.00), long=None, cache_min=4096, batch_cache_stacks=True, src=SOURCES["google"], note="Implicit caching only. No long-context tier listed on the pricing page."), dict(vendor="Google", name="Gemini 4 Argon (from Dec 1, 2026)", id="gemini-4-argon", role="— (scheduled price)", std=P(4.00, 0.20, None, 20.00), batch=P(2.00, 0.10, None, 10.00), long=None, cache_min=4096, batch_cache_stacks=True, src=SOURCES["google"], note="Price the page says starts December 1, 2026."), dict(vendor="Google", name="Gemini 3.8 Flash (intro price, through Dec 31)", id="gemini-3.8-flash", role="mid", std=P(0.75, 0.075, None, 3.75), batch=P(0.375, 0.0375, None, 1.875), long=None, cache_min=4096, batch_cache_stacks=True, src=SOURCES["google"], note="All rates double on Jan 1, 2027: standard $1.50/$7.50, cached $0.15; batch $0.75/$3.75, batch cached $0.075. Context-cache storage $0.50 per 1M tokens per hour through Dec 31, 2026; $1.00 from Jan 1, 2027."), dict(vendor="Google", name="Gemini 3.5 Flash-Lite", id="gemini-3.5-flash-lite", role="small", std=P(0.30, 0.03, None, 2.50), batch=P(0.15, 0.015, None, 1.25), long=None, cache_min=None, batch_cache_stacks=True, src=SOURCES["google"], note="Batch context caching price is $0.015 (Batch tab). The $0.02 context caching price is the Flex tab, not batch. Minimum cacheable tokens not listed on the caching page."), # ---------------- xAI ---------------- dict(vendor="xAI", name="Grok 4.7", id="grok-4.7", role="flagship", std=P(2.00, 0.50, None, 6.00), batch=P(1.60, 0.40, None, 4.80), long=(200_000, "ge", P(4.00, 1.00, None, 12.00), P(3.20, 0.80, None, 9.60)), cache_min=None, batch_cache_stacks=True, src=SOURCES["xai"], note="Batch = 20% off all token types incl. cached (Deploy Grade calculation from the 20% rule; grok-4.7 added to xAI's 20%-off list, read 2026-10-21)."), dict(vendor="xAI", name="Grok 4.3", id="grok-4.3", role="lower-priced general model", std=P(1.25, 0.20, None, 2.50), batch=P(1.00, 0.16, None, 2.00), long=(200_000, "ge", P(2.50, 0.40, None, 5.00), P(2.00, 0.32, None, 4.00)), cache_min=None, batch_cache_stacks=True, src=SOURCES["xai"], note="Batch = 20% off all token types incl. cached (Deploy Grade calculation from the 20% rule)."), # ---------------- Mistral ---------------- dict(vendor="Mistral", name="Mistral Large 4", id="mistral-large-4", role="—", std=P(0.70, 0.07, None, 2.10), batch=P(0.35, 0.035, None, 1.05), long=None, cache_min=64, cache_block=64, batch_cache_stacks=True, src=SOURCES["mistral"], note="Pricing page lists $0.7 input, $0.07 cached input, $2.1 output per 1M tokens (read 2026-11-04). Its Batch tab lists $0.35 input, $0.035 cached input, $1.05 output (read 2026-11-14 17:27 PT)."), dict(vendor="Mistral", name="Mistral Small 4", id="mistral-small-2603", role="small", std=P(0.15, 0.015, None, 0.60), batch=P(0.075, 0.0075, None, 0.30), long=None, cache_min=64, cache_block=64, batch_cache_stacks=True, src=SOURCES["mistral"], note="Cached input $0.015 is listed on the pricing page (read 2026-11-04). Its Batch tab lists $0.075 input, $0.0075 cached input, $0.30 output (read 2026-11-14 17:27 PT)."), ] # ---------------- Task assumptions (ALL are Deploy Grade assumptions) ---------------- WORDS_PER_PAGE = 500 # assumption TOKENS_PER_WORD = 1.33 # assumption (English prose); vendor tokenizers differ DOC10 = round(10 * WORDS_PER_PAGE * TOKENS_PER_WORD) # 6,650 DOC200 = round(200 * WORDS_PER_PAGE * TOKENS_PER_WORD) # 133,000 TASKS = [ dict(key="support_reply", label="Support reply", prefix=5000, variable=600, out=300, desc="5,000-token reusable prefix (instructions + policy excerpts), 600 tokens of thread + new customer message, 300-token reply (~225 words)."), dict(key="rag_answer", label="RAG answer", prefix=1500, variable=3100, out=500, desc="1,500-token reusable prefix (instructions + tool schema), 6 retrieved chunks x 500 tokens + 100-token question = 3,100 variable tokens, 500-token answer."), dict(key="doc_summary_10p", label="10-page document summary", prefix=0, variable=DOC10 + 200, out=600, desc=f"10 pages x {WORDS_PER_PAGE} words x {TOKENS_PER_WORD} tokens/word = {DOC10:,} tokens + 200-token instruction = {DOC10+200:,} input; 600-token summary. No reusable prefix (each document is new)."), dict(key="support_reply_reasoning", label="Sensitivity: support reply + 2,000 thinking tokens", prefix=5000, variable=600, out=2300, desc="Same as support reply, plus 2,000 reasoning/thinking tokens billed as output (300 visible + 2,000 hidden = 2,300 output)."), dict(key="doc_summary_200p", label="Sensitivity: 200-page document summary", prefix=0, variable=DOC200 + 200, out=1000, desc=f"200 pages x {WORDS_PER_PAGE} x {TOKENS_PER_WORD} = {DOC200:,} tokens + 200 instruction = {DOC200+200:,} input; 1,000-token summary."), ] def price_for(m, mode, input_tokens): """Return the applicable price dict (standard or batch), applying long-context tiers.""" base = m["std"] if mode == "std" else m["batch"] if base is None: return None, False lc = m.get("long") if lc: thr, rule, std_long, batch_long = lc over = input_tokens > thr if rule == "gt" else input_tokens >= thr if over: return (std_long if mode == "std" else batch_long), True return base, False def cost_uncached(p, inp, out): return (inp * p["inp"] + out * p["out"]) / 1e6 def cacheable_tokens(m, prefix): if prefix <= 0: return 0, "no reusable prefix" cmin = m.get("cache_min") if cmin is not None and prefix < cmin: return 0, f"prefix {prefix:,} below documented minimum {cmin:,}" blk = m.get("cache_block") if blk: c = (prefix // blk) * blk return c, f"{c:,} tokens cached ({blk}-token blocks)" note = "" if cmin is not None else " (minimum cacheable length not disclosed; assumed eligible)" return prefix, f"{prefix:,} tokens cached{note}" def cost_cached_per_1000(p, inp, out, cached, n=1000): """1 cold request (cache write, or normal input where no write price is listed) + (n-1) warm hits.""" rest = inp - cached write_price = p["write"] if p.get("write") is not None else p["inp"] cold = (cached * write_price + rest * p["inp"] + out * p["out"]) / 1e6 warm = (cached * p["cached"] + rest * p["inp"] + out * p["out"]) / 1e6 return cold + (n - 1) * warm def r6(x): return None if x is None else round(x, 6) def r4(x): return None if x is None else round(x, 4) def main(): # prices.csv with open(os.path.join(HERE, "prices.csv"), "w", newline="") as f: w = csv.writer(f) w.writerow(["vendor","model_name","model_id","role","mode","context_band","currency","unit", "input","cached_input","cache_write","output","source_url","accessed_pt","notes"]) for m in MODELS: bands = [("std","standard", m["std"]), ("batch","batch", m["batch"])] for mode, label, p in bands: band = "all" if m.get("long"): thr, rule, _, _ = m["long"] band = f"{'<=' if rule=='gt' else '<'}{thr:,} input tokens" if p is None: w.writerow([m["vendor"],m["name"],m["id"],m["role"],label,"all","USD","per 1M tokens", "no batch discount","","","",m["src"],m.get("accessed", ACCESSED_BY_VENDOR[m["vendor"]]),m["note"]]) continue w.writerow([m["vendor"],m["name"],m["id"],m["role"],label,band,"USD","per 1M tokens", p["inp"], "" if p["cached"] is None else p["cached"], "not listed" if p["write"] is None else p["write"], p["out"], m["src"],m.get("accessed", ACCESSED_BY_VENDOR[m["vendor"]]),m["note"]]) if m.get("long"): thr, rule, sl, bl = m["long"] lp = sl if mode == "std" else bl if lp: w.writerow([m["vendor"],m["name"],m["id"],m["role"],label, f"{'>' if rule=='gt' else '>='}{thr:,} input tokens","USD","per 1M tokens", lp["inp"], lp["cached"], "not listed" if lp["write"] is None else lp["write"], lp["out"], m["src"],m.get("accessed", ACCESSED_BY_VENDOR[m["vendor"]]),"Long-context rate applies to the whole request."]) # cost-per-task.csv rows = [] for t in TASKS: inp = t["prefix"] + t["variable"] for m in MODELS: ps, long_std = price_for(m, "std", inp) pb, long_b = price_for(m, "batch", inp) std = cost_uncached(ps, inp, t["out"]) bat = cost_uncached(pb, inp, t["out"]) if pb else None cached, cnote = cacheable_tokens(m, t["prefix"]) if cached and ps.get("cached") is not None: c1000 = cost_cached_per_1000(ps, inp, t["out"], cached) else: c1000 = None if cached and pb and m.get("batch_cache_stacks") and pb.get("cached") is not None: bc1000 = cost_cached_per_1000(pb, inp, t["out"], cached) elif cached and pb is None and ps.get("cached") is not None: bc1000 = None else: bc1000 = None rows.append(dict( task=t["key"], task_label=t["label"], vendor=m["vendor"], model_name=m["name"], model_id=m["id"], role=m["role"], input_tokens=inp, cacheable_prefix=t["prefix"], cached_tokens=cached, output_tokens=t["out"], long_context_rate_applied="yes" if long_std else "no", std_per_task=r6(std), std_per_1000=r4(std*1000), batch_per_task=r6(bat) if bat is not None else "no batch discount", batch_per_1000=r4(bat*1000) if bat is not None else "no batch discount", cached_per_task=r6(c1000/1000) if c1000 is not None else "n/a", cached_per_1000=r4(c1000) if c1000 is not None else "n/a", batch_cached_per_1000=r4(bc1000) if bc1000 is not None else "not computed", cache_note=cnote, task_assumptions=t["desc"], accessed_pt=m.get("accessed", ACCESSED_BY_VENDOR[m["vendor"]]), source_url=m["src"])) cols = list(rows[0].keys()) with open(os.path.join(HERE, "cost-per-task.csv"), "w", newline="") as f: w = csv.DictWriter(f, fieldnames=cols); w.writeheader(); w.writerows(rows) # console summary for t in TASKS: sub = [r for r in rows if r["task"] == t["key"]] sub.sort(key=lambda r: r["std_per_1000"]) print(f"\n== {t['label']} ==") for r in sub: print(f" {r['model_name']:<48} std/1k ${r['std_per_1000']:<10} batch/1k {r['batch_per_1000']!s:<18} cached/1k {r['cached_per_1000']!s:<10} bc/1k {r['batch_cached_per_1000']!s:<12} long={r['long_context_rate_applied']}") if __name__ == "__main__": main()