DEV Community

CloudGPU
CloudGPU

Posted on

Round each bill before comparing AI-video costs

AI-generated article. All prices are fictional USD inputs, and the code was verified offline. This is not a GPU benchmark.

A video generator can look cheap per second and still be expensive per second you actually keep. Three numbers answer different questions: generated duration, accepted duration, and billable allocation time. Keep all three.

Suppose a fictional session produces 120 seconds, but the edit uses only 60. The GPU is allocated for 4,764 seconds, including preparation. At an assumed $0.69 per hour, minute rounding produces an 80-minute bill: $0.92. Whole-hour rounding produces a two-hour bill: $1.38. Neither number is a current provider quote or a promise about picture quality.

The important detail is where rounding happens. Two independently billed 30-second sessions with a one-minute minimum cost two minutes, even though their combined allocation is one minute. Aggregate the actual bills after rounding each billing event. A provider may instead round an account-wide interval; model its actual contract rather than imposing this example.

The script assumes a minimum of one minute for minute billing and one hour for hour billing. A zero-duration event still incurs that minimum. Change the formula if your contract uses different terms.

Use one CSV row per independently billed event:

event_id,billing,allocation_seconds,unit_price,generated_seconds,accepted_seconds,extra_usd
hypothetical-session-1,minute,4764,0.69,120,60,310
Enter fullscreen mode Exit fullscreen mode

Here unit_price is USD per hour for minute/hour billing, or USD per generated output second for output_second billing. The $310 is a fictional shared production budget, not a measured labour cost. Record it once, not once per generation.

Save the CSV above as example.csv and the following code as accepted_cost.py, then run python3 accepted_cost.py example.csv.

"""Offline USD ledger; one CSV row per billed session/request, not per retry summary."""
import csv,json,sys
from decimal import Decimal, ROUND_CEILING

def money(row):
    kind=row['billing']; t=Decimal(row['allocation_seconds']); p=Decimal(row['unit_price'])
    gen=Decimal(row['generated_seconds']); used=Decimal(row['accepted_seconds'])
    extra=Decimal(row['extra_usd'])
    if min(t,p,gen,used,extra)<0 or used>gen:raise ValueError('invalid negative amount or accepted > generated')
    if kind=='minute': cost=max(Decimal(1),(t/60).to_integral_value(rounding=ROUND_CEILING))*p/60
    elif kind=='hour': cost=max(Decimal(1),(t/3600).to_integral_value(rounding=ROUND_CEILING))*p
    elif kind=='output_second':cost=gen*p
    else:raise ValueError('unknown billing unit')
    return cost+extra,used

def summarize(rows):
    ids=set(); total=Decimal(0); used=Decimal(0)
    for row in rows:
        if row['event_id'] in ids:raise ValueError('duplicate billed event')
        ids.add(row['event_id']); c,a=money(row);total+=c;used+=a
    return dict(total_usd=str(total),accepted_seconds=str(used),usd_per_accepted_second=str(total/used) if used else None)

if __name__=='__main__':
    with open(sys.argv[1],newline='') as f:print(json.dumps(summarize(csv.DictReader(f)),indent=2))
Enter fullscreen mode Exit fullscreen mode

It returns total_usd 310.92, accepted_seconds 60, and usd_per_accepted_second 5.182. It uses Decimal arithmetic, rejects duplicate event IDs, rejects negative values and accepted duration greater than generated duration, and returns null for unit cost if nothing is accepted.

There is a useful limitation: generated_seconds means billable output seconds in this simplified ledger. A failed request may cost money while returning no video. Record that charge in extra_usd or extend the schema with a separate charge field; do not invent output duration. Input references, storage, tax, minimum spend and currency conversion also need explicit treatment when they apply. Multiple currencies must be converted using a recorded rate before aggregation.

For a fair comparison, run the same shot list with a fixed resolution, frame rate, duration and acceptance rubric. Log every attempt, including rejected clips. Ask a reviewer to assess continuity, faces, hands and motion without seeing the provider name. Report the accepted fraction and total elapsed work alongside the bill. Equal output duration alone is not equal quality.

Finally, test the zero case. If all clips are rejected, there is no meaningful cost per accepted second. Showing zero would turn a complete failure into an apparently free result. Keep the cost, show the denominator as zero, and display the rate as unavailable.

Top comments (0)