LLM API Prices Stabilize as Competition Shifts to Cost per Task

    Most new large language models keep API prices close to their predecessors, so price per million tokens no longer shows which option is cheaper. This article explains what drives the cost of a single task, how to estimate it with a worked example, which inference engine optimizations affect it, and how to control agent spending with step limits, budgets, and loop detection.

    Recent large language model releases have come quickly, but the API prices of most new-generation models match those of the previous generation. Comparing price per million tokens alone no longer shows which option costs less. More developers and companies are now tracking a different metric: how much it actually costs to complete one business task.

    Why Price per Token Does Not Reflect Real Cost

    Token price is only one variable in the cost formula. The same task can consume very different total token counts depending on the model and architecture. Three main factors drive this:

    1. Total token consumption: Poor context management, or a model with weak instruction-following, forces developers to rewrite prompts and add context repeatedly. Input tokens rise as a result.
    2. Retry and error-handling overhead: When a model generates JSON or code, formatting errors and factual errors still occur. Each call made after a failed validation is billed and adds to the task cost.
    3. Multi-step reasoning loss: Agents need to plan, call tools, and reflect. Without explicit termination conditions, an agent may repeat similar actions, and its costs keep growing.

    Therefore, the cost-effectiveness of a model should be judged by its total cost per task in a specific business scenario.

    How to Calculate the Cost per Task

    The cost per task can be estimated with the following formula:

    Cost per task = average cost per call × number of calls including retries + tool call cost + infrastructure amortization

    Here, average cost per call = input tokens × input price + output tokens × output price. Number of calls including retries = required calls per task × (1 + retry rate).

    The example below uses assumed figures. The input price is 2 yuan per million tokens, and the output price is 8 yuan per million tokens. These numbers are for illustration only and are not the actual pricing of any vendor. A task needs an average of 3 calls. Each call uses 4,000 input tokens and 800 output tokens. The retry rate is 20%, and the tool call cost is 0.002 yuan.

    • Cost per call = 4,000 × 2 / 1,000,000 + 800 × 8 / 1,000,000 = 0.0144 yuan
    • Number of calls including retries = 3 × 1.2 = 3.6
    • Cost per task = 0.0144 × 3.6 + 0.002 ≈ 0.054 yuan

    This structure points to several ways to reduce cost: cut the input tokens in each call, reduce the number of calls, lower the retry rate, and assign simple steps to models with lower unit prices.

    When tallying costs, use the actual usage fields returned in API responses, not estimates. Before and after an optimization, compare total cost and task success rate on the same fixed set of test tasks. If costs fall but the success rate falls too, the optimization should not count as a success.

    Which Inference Engine Optimizations Exist, and When Do They Apply

    KV Cache: When generating each new token, the model must read the attention keys (K) and values (V) of all previous tokens. KV Cache stores these results in GPU memory, so the K and V projections of earlier tokens do not need to be recomputed at every step. The cost is that memory usage grows with sequence length, batch size, number of layers, and number of attention heads. Long-context requests can fill GPU memory quickly.

    PagedAttention: This method splits the KV Cache into fixed-size blocks and allocates them on demand. It reduces the memory fragmentation and waste caused by reserved space, so a single GPU can serve more concurrent requests. The throughput gain depends on batch size, average sequence length, and GPU model. With few requests or short sequences, the benefit is limited.

    Continuous batching and operator fusion: Continuous batching does not wait for an entire batch to finish before starting the next one. Instead, it adds new requests after each generation step, which raises GPU utilization. Operator fusion merges several small computations, which reduces the number of reads and writes to GPU memory.

    These optimizations mainly lower the unit compute cost for the service provider. Whether the savings reach the user’s cost per task depends on the provider’s pricing and scheduling policies.

    How to Control Agent Costs

    The code below is an illustrative implementation. The model call is a placeholder function. In practice, replace it with the real API call and tool execution.

    1. import hashlib
    2. class AgentCostController:
    3. def __init__(self, max_steps=5, max_cost=0.10, cost_per_call=0.02):
    4. self.max_steps = max_steps # Maximum number of call steps
    5. self.max_cost = max_cost # Budget per task (yuan)
    6. self.cost_per_call = cost_per_call # Estimated cost per call (yuan)
    7. self.steps = 0
    8. self.total_cost = 0.0
    9. self.seen_actions = set()
    10. def run(self, task):
    11. print(f"Starting task: {task}")
    12. while True:
    13. if self.steps >= self.max_steps:
    14. return "Terminated: maximum steps reached"
    15. if self.total_cost + self.cost_per_call > self.max_cost:
    16. return "Terminated: budget limit reached"
    17. action, finished, answer = self._call_model(task)
    18. self.steps += 1
    19. self.total_cost += self.cost_per_call
    20. # Completion is determined only by an explicit end marker in the model output
    21. if finished:
    22. print(f"Task completed in {self.steps} steps, total cost about {self.total_cost:.3f} yuan")
    23. return f"Completed: {answer}"
    24. # Loop detection: terminate when the same action appears again
    25. key = hashlib.sha256(action.encode("utf-8")).hexdigest()
    26. if key in self.seen_actions:
    27. return "Terminated: repeated action detected"
    28. self.seen_actions.add(key)
    29. def _call_model(self, task):
    30. # Placeholder implementation: replace with the model API call and tool execution in real use
    31. return "search(test)", True, "placeholder result"
    32. if __name__ == "__main__":
    33. controller = AgentCostController(max_steps=5, max_cost=0.10)
    34. print(controller.run("Look up the price of a product"))

    This code controls three things at once: the number of steps, the budget, and loops. When you use it, keep the following in mind:

    • The completion check must come from an explicit end marker in the model output or a definite result returned by a tool. Do not rely on ambiguous text.