Cost Accounting and Optimization Practices for AI-Generated PPTs and Web Pages
This article explores the cost structure behind generating presentations and web pages using Large Language Models (LLMs). It breaks down the generation pipeline into key stages, explains fundamental billing concepts like input/output tokens and multipliers, provides a reusable Python cost estimation function, and recommends a tiered model routing strategy to optimize resource consumption without compromising output quality.
1. Background: Where Does the Cost of Generated Content Come From?
Using Large Language Models (LLMs) to generate presentations or web pages usually looks like just entering a prompt and waiting a few seconds. However, behind the scenes, it involves a series of model calls. Most platforms charge based on the length of input and output text, or convert them into a unified billing unit. Even if the interface claims it is free, costs still exist as task volume increases; they are just temporarily offset by free quotas.
Developers need to answer three questions: How many resources does a single task consume? Which stages consume the most resources? How can consumption be reduced while maintaining acceptable results?
2. Task Breakdown: What Stages Are Involved in a Generation?
Take “generating a product introduction presentation” as an example. The complete process usually includes the following five stages:
- Requirement Understanding: Parse user intent, determine the number of pages, style, and target audience.
- Outline Planning: Output the chapter structure and core points for each page.
- Content Filling: Generate titles, body text, and chart descriptions page by page.
- Layout and Code Generation: Map the content to a slide structure, or HTML and CSS for a web page.
- Validation and Correction: Check for text overflow, broken links, and formatting errors, and rewrite local content if necessary.
The consumption characteristics of each stage vary greatly. Outline planning requires understanding the global structure, making it suitable for more capable models, but the output is short. Content filling involves many calls with small individual inputs, making it suitable for cheaper models in batch processing. Layout and code generation have the longest output, making it one of the most resource-intensive stages. For the validation stage, if programmatic rules can handle it, model calls are not necessary every time.
3. Basic Concepts of Billing
3.1 Input and Output Tokens
Most models charge by token, which is the basic unit of text processing for the model. The number of tokens for the same text may vary depending on the tokenization method, so estimation should be based on actual bills or the counting method provided by the platform.
Input tokens include prompts, system instructions, and the historical context carried in each call. Output tokens are the content generated by the model. Many platforms price outputs higher than inputs, so long outputs are often more expensive than long inputs.
3.2 Cost Formula for a Single Call
The cost of a single call can be expressed by the following formula:
cost = (input_tokens / 1000 * input_price + output_tokens / 1000 * output_price) * billing_multiplier
The unit price and multiplier are determined by platform rules. The multiplier allows different tiers of models to be compared under a unified metering system.
3.3 Free Quotas and Billing Multipliers
Common promotional mechanisms on platforms generally fall into three categories:
- Setting billing multipliers by model tier: The same number of tokens results in different consumption after conversion for different tiers.
- Granting free quotas for low-consumption tasks: Short or lightweight tasks might not consume quotas.
- Issuing trial quotas for new users: Used for testing, usually with an expiration date and usage limits.
These are operational rules, and their values and conditions may change at any time. Developers should refer to platform announcements and bills, and should not write rules from a specific point in time into long-term plans.
4. Cost Estimation Method
Estimation involves three steps: calculate the average tokens for each type of task, multiply by the number of calls, and then apply the unit price and multiplier. The code below provides a reusable estimation function. The prices are example values and not actual quotes from any platform.
from dataclasses import dataclass@dataclassclass ModelTier:name: strinput_price_per_k: float # Price per 1k input tokens (example value)output_price_per_k: float # Price per 1k output tokens (example value)multiplier: float = 1.0 # Billing multiplier, subject to platform announcementsdef estimate_cost(tier: ModelTier, input_tokens: int, output_tokens: int) -> float:base = (input_tokens / 1000) * tier.input_price_per_kbase += (output_tokens / 1000) * tier.output_price_per_kreturn base * tier.multiplierdef estimate_task(tier: ModelTier, calls: list[tuple[int, int]]) -> float:"""calls is a list of (input_tokens, output_tokens), returns the estimated cost of the entire task."""return sum(estimate_cost(tier, i, o) for i, o in calls)if __name__ == "__main__":tier_small = ModelTier("Small Model", input_price_per_k=0.5,output_price_per_k=2.0, multiplier=0.5)# 12 slides, one call per slide, 1200 input tokens and 400 output tokens per callcalls = [(1200, 400)] * 12print(round(estimate_task(tier_small, calls), 2)) # Output 8.4 (example value)
The estimation result is only for reference. Actual consumption will be affected by the number of retries, context length, and output fluctuations. Therefore, it is recommended to calibrate the average values with a few real tasks before official use.
5. Model Tiering and Routing
Different stages have different requirements for model capabilities. Using a single tier uniformly is usually both expensive and inefficient. Layering by stage is recommended:
| Stage | Task Characteristics | Recommended Tier |
|---|---|---|
| Outline Planning | Requires global structure, few calls | Higher capability tier |
| Content Filling | Many calls, short single input | Lower cost tier |
| Layout & Code Generation | Long output, strict format requirements | Medium tier, combined with programmatic validation |
| Validation & Correction | Mainly rule-based judgments | Programmatic rules / Lowest cost tier |
