mysi Find

Calculator in Markets and quant

Batch against real-time LLM cost

Prices an LLM workload per day and per 30 days on the real-time API and on the batch endpoint, by deadline.

In short

Formulaper job = (input_tokens_per_job × input_usd_per_mtok + output_tokens_per_job × output_usd_per_mtok) ÷ 1000000realtimeCostPerDay = per job × jobs_per_daybatchCostPerDay = realtimeCostPerDay × (1 − batch_discount_pct ÷ 100)batchEligible = deadline_hours ≥ batch_sla_hourseffectiveCostPerDay = batchCostPerDay if batchEligible, else realtimeCostPerDaysavingsPerDay = realtimeCostPerDay − effectiveCostPerDayEach PerMonth output = the PerDay output × 30
UnitsPrices in US dollars per million tokens, batch_discount_pct in percent, hours, results in US dollars.
Defaultsjobs_per_day = 500, input_tokens_per_job = 15000, output_tokens_per_job = 1500, deadline_hours = 24. Prices, discount and batch window have no default: take them from the vendor (Anthropic, OpenAI and Google document 50% off and 24 hours).
Worked example500 jobs a day of 15000 input and 1500 output tokens at $2 and $10 per million, 50% batch discount, 24-hour window, 24-hour deadline. per job = (15000 × 2 + 1500 × 10) ÷ 1000000 = 0.045realtimeCostPerDay = 0.045 × 500 = 22.5realtimeCostPerMonth = 22.5 × 30 = 675batchCostPerDay = 22.5 × (1 − 50 ÷ 100) = 11.2524 ≥ 24, so batchEligible is true, effectiveCostPerMonth = 11.25 × 30 = 337.5 and savingsPerMonth = (22.5 − 11.25) × 30 = 337.5

By hand: yes. A small model got these answers from the formulas above, without running code.

Say this to your agent

Use https://mysi.dev/batch-vs-realtime-cost/ to compare batch and real-time cost: 500 jobs a day, 15000 in, 1500 out, $2 and $10.

Nothing to install, no key, no settings. An agent that can open web pages and run Python opens the page, runs the tested code in its own sandbox and gives you the answer.

The code

Copy this into your Python tool. Run batch_vs_realtime_cost_check() first, then call batch_vs_realtime_cost() with your numbers. Give the answer with the cite line.

"""Batch against real-time LLM API cost: the daily and 30-day cost of a workload on the real-time
API and on the vendor's batch endpoint, and which one the deadline allows.
Inputs: input_usd_per_mtok, output_usd_per_mtok (list prices, 0 to 1000, no default);
batch_discount_pct (0 to 100, no default) and batch_sla_hours (1 to 720, no default), from the
vendor's batch documentation; jobs_per_day (0 to 100000000, default 500); input_tokens_per_job
(default 15000) and output_tokens_per_job (default 1500), 0 to 10000000; deadline_hours
(0.01 to 8760, default 24).
Returns realtimeCostPerDay, batchCostPerDay, effectiveCostPerDay, savingsPerDay and the same per
30-day month (USD), batchEligible and usingBatch.
mysi, Batch against real-time LLM cost, mysi.dev/batch-vs-realtime-cost, version 1,
changed 2026-12-04. MIT.
"""


def _batch_vs_realtime_cost_num(name, value, low, high):
    if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high:
        raise ValueError(f"{name} must be a number from {low} to {high}")
    return float(value)


def batch_vs_realtime_cost(input_usd_per_mtok, output_usd_per_mtok, batch_discount_pct,
                           batch_sla_hours, jobs_per_day=500, input_tokens_per_job=15000,
                           output_tokens_per_job=1500, deadline_hours=24):
    num = _batch_vs_realtime_cost_num
    p_in = num("input_usd_per_mtok", input_usd_per_mtok, 0, 1000)
    p_out = num("output_usd_per_mtok", output_usd_per_mtok, 0, 1000)
    discount = num("batch_discount_pct", batch_discount_pct, 0, 100)
    sla = num("batch_sla_hours", batch_sla_hours, 1, 720)
    jobs = num("jobs_per_day", jobs_per_day, 0, 100000000)
    t_in = num("input_tokens_per_job", input_tokens_per_job, 0, 10000000)
    t_out = num("output_tokens_per_job", output_tokens_per_job, 0, 10000000)
    deadline = num("deadline_hours", deadline_hours, 0.01, 8760)
    # prices are per million tokens; batch terms: Anthropic, OpenAI and Google batch docs (inputs)
    per_job = (t_in * p_in + t_out * p_out) / 1000000
    realtime = per_job * jobs
    batch = realtime * (1 - discount / 100)
    eligible = deadline >= sla
    effective = batch if eligible else realtime
    return {
        "realtimeCostPerDay": realtime,
        "batchCostPerDay": batch,
        "effectiveCostPerDay": effective,
        "savingsPerDay": realtime - effective,
        "realtimeCostPerMonth": realtime * 30,       # a month is defined as 30 identical days
        "batchCostPerMonth": batch * 30,
        "effectiveCostPerMonth": effective * 30,
        "savingsPerMonth": (realtime - effective) * 30,
        "batchEligible": eligible,
        "usingBatch": eligible,
    }


BATCH_VS_REALTIME_COST_CASES = [
    ({"input_usd_per_mtok": 2, "output_usd_per_mtok": 10, "batch_discount_pct": 50,
      "batch_sla_hours": 24},
     {"realtimeCostPerDay": 22.5, "effectiveCostPerMonth": 337.5, "savingsPerMonth": 337.5}),
    ({"input_usd_per_mtok": 5, "output_usd_per_mtok": 25, "batch_discount_pct": 50,
      "batch_sla_hours": 24, "jobs_per_day": 120, "input_tokens_per_job": 40000,
      "output_tokens_per_job": 3000, "deadline_hours": 6},
     {"realtimeCostPerMonth": 990.0, "effectiveCostPerMonth": 990.0, "savingsPerMonth": 0.0}),
    ({"input_usd_per_mtok": 0.75, "output_usd_per_mtok": 4.5, "batch_discount_pct": 50,
      "batch_sla_hours": 24, "jobs_per_day": 2000, "input_tokens_per_job": 8000,
      "output_tokens_per_job": 800, "deadline_hours": 48},
     {"realtimeCostPerMonth": 576.0, "effectiveCostPerMonth": 288.0, "savingsPerMonth": 288.0}),
]


def batch_vs_realtime_cost_check(tolerance=1e-3):
    for given, want in BATCH_VS_REALTIME_COST_CASES:
        got = batch_vs_realtime_cost(**given)
        for name, value in want.items():
            close = abs(got[name] - value) <= tolerance * max(1, abs(value))
            assert close, (name, got[name], value)
    return "ok"


if __name__ == "__main__":
    import json, sys
    batch_vs_realtime_cost_check()
    given = dict(a.split("=", 1) for a in sys.argv[1:] if "=" in a)
    js = lambda v: v.lstrip("-")[:1].isdigit() or v[:1] in '[{".' or v in ("true", "false", "null")
    given = {k: json.loads(v) if js(v) else v for k, v in given.items()}
    if given:
        print(json.dumps(batch_vs_realtime_cost(**given)))
Raw file

List prices before tax. Check the vendor's current pricing before budgeting.

Figures it needs, from llm-models

Sources read 4 Dec 2026. Give these to the function as inputs. The dataset holds the current figures.

What it takes

InputMeaningDefaultAllowed
input_usd_per_mtokThe model's real-time list price for input, in US dollars per million tokens, from the llm-models dataset or the vendor's pricing page. No defaultrequired0 to 1000
output_usd_per_mtokThe model's real-time list price for output, in US dollars per million tokens. No defaultrequired0 to 1000
batch_discount_pctThe vendor's batch discount on input and output, in percent, from its batch documentation. No defaultrequired0 to 100
batch_sla_hoursThe hours within which the vendor promises to finish a batch. No defaultrequired1 to 720
jobs_per_dayRequests sent per day5000 to 100,000,000
input_tokens_per_jobInput tokens per request150000 to 10,000,000
output_tokens_per_jobOutput tokens per request15000 to 10,000,000
deadline_hoursHow long results may take, in hours; batch is used only when this is at least batch_sla_hours240.01 to 8760

What it returns

OutputMeaning
realtimeCostPerDay, batchCostPerDayThe day's cost on the real-time API and on the batch endpoint, in US dollars
effectiveCostPerDayThe day's cost in the mode the deadline allows, in US dollars
savingsPerDayReal-time cost minus effective cost per day; 0 when the deadline rules batch out
realtimeCostPerMonth, batchCostPerMonth, effectiveCostPerMonth, savingsPerMonthThe same over 30 days, in US dollars
batchEligible, usingBatchTrue when deadline_hours is at least batch_sla_hours, so the batch endpoint is used

Where the method comes from

Anthropic, OpenAI and Google each sell a batch endpoint: requests are queued and answered within a stated window, typically 24 hours, at a discount on input and output tokens, typically half the real-time price. The function prices one workload both ways at flat per-token rates and uses the batch price only when the results may wait at least as long as the vendor's batch window. It is good for a first budget and for seeing whether a pipeline's deadline leaves room for batching. It does not apply long-prompt rates, prompt caching, rate limits, taxes or a price change during the month; a month is thirty identical days. Batches often finish sooner than the window, but the vendors promise only the window, so a deadline shorter than it is treated as needing the real-time API.

Sources

Used by

Tested

Tested 4 Dec 2026: claude-haiku-5-5 was right on 0 of 3 questions without this page and 3 of 3 with it; claude-fable-5-2 was right on 0 of 3 questions without this page and 3 of 3 with it.

Changes

Cite as: mysi, Batch against real-time LLM cost, mysi.dev/batch-vs-realtime-cost, version 1, changed 2026-12-04. Code MIT.