LLM API Cost Control and Choosing Between Chat and Agent Modes
This article explains how LLM API billing actually works and why the real cost driver is context size per request, not the number of conversation turns. It breaks down the three preconditions for keeping costs predictable, four context engineering techniques (layered memory summaries, retrieval-based injection, prompt streamlining, and session rotation with budget guardrails), and the practical differences between Chat and Agent modes, including when to use each. It also covers key points for building a lightweight custom chat front end, how to combine multiple models for review without doubling token usage, and a final implementation checklist for running stable, low-budget LLM workflows.
1. Start With the Right Question: It Is Not About “Abandoning Free Users”
Most debates about whether a major model provider is “dropping free users” come from conflating two entirely different resources: the free interactive quota offered to end users, and the usage-based quota for programmatic API calls. The former is limited by concurrency, rate limits, and feature scope. The latter is metered in tokens, with pricing strongly tied to context length and output length. Once you see this distinction, an emotional argument turns into an engineering problem you can calculate and optimize.
From an engineering perspective, the cost of a single call can be approximated as:
cost per request ≈ input tokens × input price + output tokens × output pricewhere input tokens = system prompt + conversation history + current question + tool results
The conclusion is straightforward: cost is not determined by the number of conversation turns, but by the actual context size carried in each turn. If long context becomes the norm, cost grows roughly linearly. Conversely, if the context is effectively compressed, the unit cost can stay extremely low even after a long cumulative interaction.
2. Three Preconditions for Cost Control
2.1 Context Is the Main Cost Variable
In long conversations, historical messages are repeatedly carried into every request, which means they are billed repeatedly. If a single session carries context on the order of tens of thousands of characters, the cost of one round trip is significantly higher than with short context. Splitting the same content into several short sessions often reduces total cost by an order of magnitude. So there is no universal answer to “how long can I chat after topping up ten dollars” — it depends entirely on how much history you carry each time.
2.2 Output Length Sets the Ceiling
Input can be compressed; output is hard to compress. Tasks that require long-form generation are inherently more expensive. In practice, separate “generation” from “refinement”: set the tone with a small sample first, then produce in batches, instead of asking the model to brainstorm, write, and proofread all in a single request.
2.3 Free Quotas and Billed Quotas Are Two Separate Systems
Consumer-facing interactive products usually offer a certain amount of free usage, but with constraints on feature scope, context length, concurrency, and rate. Programmatic calls are billed by usage. The two are not substitutes; they are fit-for-purpose options for different workloads. Reading “the free quota is being tightened” as “users are being abandoned” is a misreading of the resource model.
3. Pushing Cost Extremely Low: Four Context Engineering Techniques
3.1 Summary Compression and Layered Memory
Do not keep verbatim history. Maintain three layers instead: long-term points (goals, constraints, style), mid-term summaries (conclusions already reached), and short-term raw text (the most recent few turns). Each request injects only the layers that are necessary. A sample structure:
{"long_term": ["Goal: complete the first draft of the product description", "Style: concise, few adjectives"],"mid_summary": "Three-part structure confirmed: background / capabilities / implementation","recent_turns": 3}
3.2 Retrieval-Based Injection Instead of Carrying Everything
Put source material in general-purpose object storage, retrieve the fragments relevant to the question, and inject only those, rather than attaching all the material every time. This decouples context size from the total volume of material and ties it only to the relevance of the current question.
3.3 Concise, Structured Prompts
The system prompt should be short and explicit. Replace long descriptions with field-based constraints. Turn “what not to do” into verifiable positive requirements, which reduces the extra turns caused by repeated correction.
3.4 Session Splitting and Budget Guardrails
Set a context limit and a cumulative budget threshold for each session; when a limit is exceeded, summarize automatically and start a new session. In engineering terms, this can be controlled with pseudocode like the following:
if estimated_tokens(history) > CONTEXT_LIMIT:summary = summarize(history)history = [system_prompt, summary, latest_user_msg]if session_cost > BUDGET:rotate_session()
4. Chat vs. Agent: Two Modes That Should Not Be Mixed
The goal of Chat mode is to “say it clearly”: interaction is low-latency, traceable, and lightweight in context. The goal of Agent mode is to “get the job done”: it has tool calling, multi-step planning, self-verification, and deliverable output, which brings additional reasoning and tool overhead.
Using an Agent for pure conversation produces familiar symptoms: stiff expression, slower responses, and heavy background reasoning and self-negation triggered as soon as the context grows a little, sometimes even generating files or plans that were never requested, wasting quota. The rule of thumb can be reduced to one line:
- When you need “text quality,” use Chat.
- When you need “task closure and deliverables,” use Agent.
For writing tasks, the recommended path is: first settle the tone, structure, and template in Chat, then turn the template into prompts and validation rules, and finally hand it to an automated workflow for batch execution. Example:
Stage 1 (Chat): define the audience, tone, and structure; produce 3 opening versions and pick oneStage 2 (固化 ->固化): write the chosen structure into a template and a checklistStage 3 (Agent): generate in batches against the template, validate automatically, archive the output
5. Engineering Notes for Building a Lightweight Interaction Layer
If you want a more controllable interactive experience, you can build a minimal usable chat front end. The core is only four things: keep keys in a local or private environment, send only the necessary context in the request body, support summarization and export in the UI, and allow sessions to be switched and archived at any time. On security, one point must be stressed: keys must never be written into front-end code or public repositories; they should be injected via environment variables or a key management service, and logs should be redacted.
For capability composition, general cloud service categories can fill the engineering gaps: object storage for source material and outputs, a message queue for smoothing traffic spikes, a container platform for hosting the stateless front end, and logging plus monitoring and alerting to observe call volume and failure rates. This avoids locking into a single solution and makes it easier to swap model sources later.
6. Multi-Model Collaboration: Let Contexts “Review Each Other” Rather Than “Burn Each Other”
Alternating between models from different sources within the same session lets them offer differentiated perspectives on the same piece of content, which suits solution review and copy comparison. Two cautions apply. First, every switch re-injects the context, so pair it with summarization to avoid doubling cost. Second, fix the review dimensions (accuracy, structure, tone, actionability); otherwise you easily end up with a large volume of mutually incompatible opinions. The recommended approach is “one model as the primary writer plus multiple models scoring by dimension,” and then write the conclusions back as new long-term points.
7. Implementation Checklist
- Do the math first: estimate real cost with “input + output tokens × unit price,” then set the budget.
- Then compress: prioritize the three essentials — summarization, retrieval injection, and prompt streamlining.
- Then choose the mode: writing and Q&A go to Chat; delivery and automation go to Agent.
- Add guardrails: context limits, budget thresholds, session rotation, and log redaction.
- Build up reusable assets: turn effective templates and checklists into reusable material.
In summary, “whether free users are being abandoned” is not the core issue. The real dividing line is whether you have a handle on two things: context and mode. Manage context as a budget and match mode as a tool, and you can still get stable, predictable interaction and output on a low budget.
