concept

Latency, throughput and cost

Known hypothetical total USD and USD per accepted task; no billing API or measured costs.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
task_cost(completed, attempts, input_rate, output_rate, node_minutes, node_hour_rate, extras_micro)

Working Example

Example Snippetartificial-intelligence
from fractions import Fraction
def task_cost(completed, attempts, input_rate, output_rate,              node_minutes, node_hour_rate, extras_micro):    # All rates in hypothetical integer USD; extras in microdollars.    if any(type(x) is not int or x < 0 for x in           (completed, input_rate, output_rate, node_minutes, node_hour_rate, extras_micro)):        raise ValueError("invalid costs or counts")    if any(type(i) is not int or type(o) is not int or min(i, o) < 0           for i, o in attempts):        raise ValueError("invalid usage")    total = Fraction(sum(i * input_rate + o * output_rate for i, o in attempts)                     + extras_micro, 1_000_000) + Fraction(node_minutes * node_hour_rate, 60)    return total, total / completed if completed else None
# Same 100 completed tasks; usage includes retry and failed attempts.print(task_cost(100, [(100_000, 20_000)], 2, 5, 0, 0, 300_000))print(task_cost(100, [], 0, 0, 60, 1, 300_000))print(task_cost(100, [], 0, 0, 60, 2, 300_000))print(task_cost(0, [(1000, 0)], 2, 5, 0, 0, 0))