LLM API Pricing and Hosted Agents: A Practical Guide to Cost and Runtime Design
This guide explains how LLM API billing works beyond per-token price, covering cached versus uncached input, standard versus high-speed tiers, and output token costs. It then examines hosted agents and the runtime harness required for 24/7 long-running tasks, including context growth, checkpoint recovery, least-privilege credentials, and budget guardrails. Readers will find practical request structuring, a cost estimation formula, and a stability and governance checklist.
1. Why the Billing Model Matters More Than the Unit Price
When teams evaluate an LLM API, the first question is usually “how much per million tokens?” In real workloads, however, the bill is driven less by unit price than by call structure: whether prompts are reusable, whether context is retransmitted repeatedly, whether output length is controlled, and whether a low-latency channel is needed. The same model capability can cost several times more or less depending on how the requests are engineered.
Understanding the billing dimensions is therefore really about understanding how to organize your requests. The three common billing dimensions below provide the thread for that discussion.
2. The Three-Layer Structure of API Billing
2.1 Cached Input vs. Uncached Input
Most mainstream LLM APIs split the input side into two tiers: cached input and uncached input, with a price gap typically ranging from a few times to roughly ten times. For example, in one class of service, cached input is about CNY 1.3 per million tokens, uncached input about CNY 13, and output about CNY 68.
The engineering signal in these numbers is clear: output costs far more than input, and the cost of repeated input can be substantially reduced through caching.
Practical implications:
- Keep system prompts, tool definitions, and fixed knowledge-base fragments at the front and stable to improve cache hit rates;
- Place volatile content (live user input, timestamps, random IDs) at the end of the prompt so it does not pollute the prefix;
- In multi-turn conversations, message history naturally has prefix-reuse characteristics, so the prefix must remain byte-for-byte identical.
An illustrative structure:
[Stable prefix] System instructions + tool schema + domain knowledge[Semi-stable section] Conversation summary (appended per turn, earlier text unchanged)[Volatile tail] Current user input + timestamp + request ID
2.2 The Premium Logic of the High-Speed Tier
The same model capability is often offered through two channels, a standard tier and a high-speed tier, with the high-speed tier costing about twice as much. This is not a “stronger model” but trading budget for first-token latency and throughput stability.
Selection guidance:
- Prefer the high-speed tier for interactive scenarios (IDE completion, first response in customer support, voice conversation);
- Use the standard tier for offline batch work (document summarization, data extraction, offline evaluation);
- Abstract a unified model gateway layer in the architecture and route dynamically by scenario, avoiding hard-coding the channel choice into business code.
2.3 Output Tokens as the Cost Lever
The output unit price is usually more than five times the uncached input price, which means making the model say less is the most direct way to cut costs. Actionable practices include constraining structured output (JSON Schema), setting a reasonable maximum output length, splitting long-form generation into multiple controllable tasks, and caching generated results for reuse.
3. From API to Hosted Agents: A Shift in the Runtime Paradigm
The source material also mentions a class of hosted agent services: the “harness” that supports long-running agents is provided as cloud infrastructure, enabling 24/7 long-horizon tasks and multi-agent collaboration.
The technical point here is that the difficulty of agents has shifted from “is the model smart enough” to “is the runtime reliable”.
3.1 What a Harness Is
A harness is the runtime layer wrapped around the model that keeps it working continuously. It typically handles:
- Loop control: iterative scheduling of plan, execute, observe, and re-plan;
- Tool invocation: function registration, parameter validation, permission boundaries, timeouts, and retries;
- State management: context compression, memory reads and writes, checkpoint persistence;
- Concurrency orchestration: task distribution and result aggregation across agents;
- Observability: trace tracking, token metering, and failure attribution.
3.2 Core Challenges of Long-Horizon Tasks
Running 24/7 is not a matter of “increasing the timeout.” It requires solving four engineering problems:
- Context growth: accumulated turns invalidate the prefix, lower the cache hit rate, and push costs up non-linearly, so summarization and segmentation strategies are needed;
- Idempotency and recovery: a task that fails midway must resume from a checkpoint to avoid duplicate charges and duplicate side effects;
- Least privilege: long-lived credentials carry high risk, so short-lived tokens plus on-demand authorization are preferable;
- Cost guardrails: set budget caps, per-task token quotas, and circuit-breaker thresholds.
A simplified long-horizon task loop:
while not done and budget.remaining() > 0:plan = llm.plan(context.summary(), tools=registry.schemas())result = executor.run(plan, timeout=30, retries=2, idem_key=plan.id)context.append(result)if context.tokens() > LIMIT:context.compress() # Summarize while preserving the stable prefixcheckpoint.save(context) # Support resume from checkpoint
4. Cost Estimation: Translating Unit Prices into Business Terms
Teams should maintain a “call structure table” rather than memorizing unit prices. Core fields include average input tokens, cache hit rate, average output tokens, daily call volume, and the share of high-speed channel usage.
A rough estimation formula:
Daily cost ≈ calls × [ input tokens × (hit rate × cached price + (1 - hit rate) × uncached price)+ output tokens × output price ] × channel factor
In practice, raising the cache hit rate from 20% to 70% can cut input-side spending by more than half, while trimming 30% of redundant wording on the output side often improves the overall bill more than switching to a cheaper model.
5. Stability and Governance Checklist
- Model gateway: unified authentication, routing, rate limiting, fallback, and canary rollout;
- Caching strategy: normalize prefixes and avoid meaningless spaces or timestamps that break reuse;
- Observability: tag and meter tokens by business dimension to locate high-consumption callers;
- Multi-agent collaboration: define a primary-subordinate or peer topology, set arbitration and conflict-resolution rules, and prevent endless mutual invocation;
- Security boundaries: tool allowlists, output content moderation, and redaction of sensitive data before it enters the model;
- Evaluation loop: an offline evaluation set plus online sampling to prevent quality loss in the name of cost reduction.
6. Conclusion
Optimizing LLM API cost is not about finding a cheaper number but about rethinking how requests and runtimes are structured: make input reusable, make output more restrained, select channels on demand, and give long-horizon tasks checkpoints and budget guardrails. When a team internalizes the billing model as an architectural constraint, a hosted agent runtime can genuinely support stable 24/7 operations, and multi-agent collaboration can move from demo to production.
