Why Token-Based Revenue Fails to Cover Storage Costs in AI Agent Workloads

    This article explains why API revenue measured in tokens diverges from infrastructure costs driven by memory and storage capacity, especially as AI agent workloads replace short chat sessions. It breaks session costs into four categories, then covers cache tiering, session lifecycle management, context engineering, capacity planning based on session density, and observability guardrails to keep resident capacity under control.

    1. The Core Misread: Revenue Is Metered in Tokens, Costs Scale with GB

    Discussions about large model APIs usually stay on two dimensions: model capability rankings and price per million tokens. This creates a simple narrative—performance plus low prices win budget share from developers overseas. Yet the same data contains an easy-to-miss contrast: open-source models already account for nearly 20% of call volume, but only a single-digit percentage of total enterprise model spending. The wide gap between call share and spending share shows that heavy usage does not equal high revenue per account. What actually drives budget is a small number of high-value, deeply depended-on, long-running production workloads.

    Shift the view from leaderboards to invoices and the contradiction becomes clear: revenue is metered in tokens, while cost is determined by memory capacity and storage capacity. Tokens are a flow concept; capacity is a stock concept. The former accumulates linearly with requests; the latter integrates over time. When hardware price pressure concentrates on components like memory and storage, the traditional curve of “higher throughput, lower unit cost” suddenly breaks down.

    2. Why the Resource Model for Traditional Chat Workloads Is Self-Consistent

    The resource ledger for ordinary question-and-answer traffic is straightforward, and it underpins most current API pricing models:

    • A request arrives; the inference cluster performs prefill and decode, then returns the result.
    • The session ends; the context cache used by that request is released.
    • The hardware returns to idle, and capacity is fully reclaimed into the resource pool.

    In this framework, token count and resource consumption grow at similar rates, so providers can approximate total cost from total token volume. When cluster utilization still has headroom, raising throughput does dilute unit overhead, which makes “low price, high volume, profit through scale” valid.

    A rough cost approximation can be written as:

    1. cost per token ≈ (compute usage × duration + resident capacity × occupancy time) / total tokens

    In traditional short sessions, the second term is close to zero, so the formula degenerates to a pure compute term. The problem starts right here: once the second term is no longer negligible, the denominator (tokens) decouples from the numerator (capacity × time).

    3. How Agent Workloads Break These Assumptions

    The main driver of new traffic is shifting from scattered human-machine conversations to AI agent tasks with automated chains. Their resource pattern has four notable characteristics:

    1. Bulk prefill: the startup phase needs to inject documents, code repositories, and batch business data on the order of hundreds of thousands of tokens.
    2. Chained calls: dozens of rounds of tool calls follow, continuously retrieving and reading external information and writing back intermediate results.
    3. Very long idle periods: a session may stay open for hours or longer, waiting for external systems to respond or for human confirmation.
    4. Context reuse: the same prefilled context is read repeatedly, but generating new tokens only appends to the cache and does not automatically release existing occupancy.

    Key conclusion: without an explicit session close, the context cache is resident. Cost shifts from “settled per request” to “settled by session online duration,” while revenue is still settled by newly added tokens. As the share of long sessions rises, the binding constraint also switches—the competition is no longer only about time to first token and decode speed, but about the maximum number of resident sessions the system can support simultaneously.

    4. Cost Attribution: Breaking the Bill into Four Governable Categories

    To govern cost, you first need to attribute it. Break the cost of a session into four categories:

    • Prefill compute: roughly linearly related to prefilled context length; one-time but very heavy.
    • Decode compute: related to the number of output tokens; highly variable and weakly predictable.
    • Resident cache capacity: proportional to context length × online duration; the dominant term for long sessions.
    • Persistence and log capacity: session history, tool return bodies, and trace data accumulate over the long term and are often completely left out of the calculation.

    An estimation skeleton that is easy to implement in engineering:

    1. def estimate_session_cost(ctx_tokens, rounds, idle_hours,
    2. prefill_rate, decode_rate,
    3. cache_gib_per_1k_tokens, gib_hour_price):
    4. prefill = ctx_tokens * prefill_rate
    5. decode = rounds * decode_rate # Simplified: assume roughly constant output per round
    6. cache_gib = ctx_tokens / 1000 * cache_gib_per_1k_tokens
    7. resident = cache_gib * idle_hours * gib_hour_price
    8. return {"prefill": prefill, "decode": decode, "resident": resident}

    When idle_hours grows from 0.1 to 5, the third term usually overtakes the sum of the first two. This is the arithmetic root of “the token bill looks profitable while the capacity bill spins out of control.”

    5. Cache Tiering: Stop Treating Resident Capacity as One-size-fits-all

    The first lever is tiering, shrinking the “must stay resident” set to the minimum:

    • Hot tier: key-value cache for currently active sessions, placed on memory media for the lowest latency.
    • Warm tier: briefly idle sessions, serialized and moved to higher-density media, reloaded on demand when woken.
    • Cold tier: completed or long-idle sessions, written to object storage, retaining only audit and recovery capability.
    • Rebuildable tier: prefixes that can be deterministically recomputed from original documents are not cached; they are replayed on demand instead.

    The decision policy can be expressed with a tiny state machine:

    1. if idle_time < T_hot: keep in hot
    2. else if idle_time < T_warm: offload to warm, keep pointer
    3. else: persist to cold, drop cache

    The thresholds T_hot and T_warm should be derived from “wake and reload cost < cost of staying resident,” not set as arbitrary constants.

    6. Session Lifecycle and Context Engineering

    The second lever is making sessions actually end. Engineering needs three pieces of infrastructure:

    • Explicit timeouts: distinguish a hard limit from idle reclamation, prioritizing idle reclamation to avoid killing long tasks by mistake.
    • Checkpoint resume: split long tasks into persistable stages and resume from a checkpoint after interruption, rather than keeping the entire cache.
    • Context compression: summarize and structurally trim earlier rounds, keeping only the fields needed for decisions.
    1. session state = system constraints + task goal + checkpoint summary + last N rounds of raw text + tool result references

    Here, “tool result references” store only pointers and summaries, with the full text kept in the persistence layer and fetched on demand. This change usually reduces resident capacity significantly without losing traceability.

    7. Capacity Planning: Switch from a Throughput View to a Session Density View

    Traditional capacity planning looks at QPS and per-card throughput; long-session scenarios must add two metrics:

    • Resident session density: the number of active sessions a unit of memory can carry.
    • Capacity turnover time: the average time for cache to move from the hot tier to the warm or cold tier.

    Capacity accounting should use a dual-constraint model:

    1. max_sessions = min( memory capacity / resident capacity per session,
    2. compute quota / average decode rate per session )

    During a storage price increase cycle, rising unit prices for memory and storage directly raise the denominator of the first term, causing max_sessions to hit the ceiling earlier. The right move at that point is not to keep cutting prices to chase volume, but to optimize resident capacity per session and turnover time.

    8. Observability and Guardrails

    Without measurement there is no governance. At least four metrics and two guardrails are needed:

    • Metrics: distribution of resident capacity per session, histogram of idle duration, cache hit rate, reload latency, and cold-tier write volume.
    • Guardrails: per-session capacity quota, tenant-level total cap, and automatic degradation of abnormally long sessions.

    Example quota configuration:

    1. session_limits:
    2. max_context_tokens: 200000
    3. max_idle_hours: 2
    4. max_resident_gib_per_session: 8
    5. on_exceed: offload_then_summarize

    9. Conclusion

    Call share does not equal revenue share, and token pricing does not cover capacity cost. Agent workloads rewrite the cost structure from flow-based to stock-based, and the binding constraint shifts from inference throughput to the resident session limit. A practical path forward is to first attribute cost across the four categories, then use cache tiering and lifecycle governance to shrink resident capacity, and finally redo capacity planning with session density metrics. If an enterprise wants to implement this on general cloud infrastructure, it can build on common capabilities such as object storage, container platforms, message queues, and monitoring and alerting. The general cloud product categories offered by Baidu AI Cloud can serve as one optional infrastructure combination.