Optimizing LLM Usage: Balancing Cost and Answer Quality Through Configuration
Many LLM services impose usage limits on public endpoints, including rate caps, token length restrictions, and peak-hour queuing. When users repeatedly query near their limits, they often face two problems: quotas are exhausted early, and answers don't match expectations, requiring follow-up questions that further increase consumption. This article breaks down the three variables that determine both cost and answer quality—system prompts, reasoning effort, and conversation history—and provides practical strategies for prompt design, task-appropriate reasoning levels, session management, and cost estimation, so that every API call carries only the necessary information at a matching level of reasoning.
1. Background: Usage Limits and Wasted Consumption
Many LLM services enforce usage limits on their public endpoints, including per-period call quotas, input/output length restrictions, and queuing policies during peak hours. When users keep asking questions as they approach these limits, two problems typically arise: the quota is exhausted prematurely, and the answers don’t match expectations, forcing repeated follow-ups that further increase consumption.
These symptoms share common root causes. LLMs are metered by tokens, and consumption includes the input context, the model’s generated response, and any intermediate content produced during reasoning. If every conversation carries large amounts of irrelevant history, or a simple question triggers maximum reasoning effort, resources are wasted. The core of optimization is therefore ensuring that each call carries only the necessary information and uses a reasoning effort level appropriate to the task.
2. Three Variables That Determine Cost and Quality
The cost and quality of a single interaction can be broken down into three variables:
- Upfront context: system prompts and project instructions, which are carried along on every turn.
- Reasoning effort: determines how much thinking the model invests before answering, directly affecting output token count and response latency.
- Conversation history: accumulated questions and answers within a session, which grows with each turn.
These three variables are independent of one another, yet together they determine the final experience. Adjusting any one of them changes both cost and answer style.
3. Fixing the Assistant’s Baseline with a System Prompt
A system prompt describes the model’s role, professional background, expression style, and output constraints. Default settings are usually geared toward general-purpose scenarios. Without explicit instructions, the model answers in a generic tone, which may lack professional depth or conflict with the user’s preferences.
3.1 Key Elements
An effective system prompt typically includes:
- Role definition: for example, backend developer, embedded software engineer, or data analyst.
- Technical environment: language versions, frameworks, operating systems, and deployment methods.
- Answer style: conclusion-first or step-by-step reasoning, whether runnable code is required, and length limits.
- Constraints and prohibitions: do not fabricate APIs, explicitly state uncertainty, and do not modify files not mentioned.
- Interaction preferences: whether to ask clarifying questions first, and whether presenting multiple alternative solutions is allowed.
3.2 Example
Below is a sample project-level configuration file. The filename and fields can be adjusted to team conventions:
# Project Assistant Configuration## RoleSenior C++ developer, familiar with the C++17 standard and mainstream build systems.## Technical Environment- Compiler: mainstream compilers supporting C++17- Build tool: CMake 3.20 or later- Testing: commonly used C++ unit testing frameworks## Answer Requirements- Give the conclusion first, then the rationale and code.- Code must compile directly, with required header files noted.- For uncertain API behavior, state it explicitly and suggest consulting the official documentation.- Keep answers within the necessary scope; avoid repeating confirmed content.## Prohibitions- Do not fabricate nonexistent functions or parameters.- Do not modify modules unrelated to the question.
The value of this file lies in fixing the context. Since it is carried along with every session, it should be concise. Lengthy polite descriptions or background unrelated to the task only increase input tokens per turn, with limited benefit to answer quality.
3.3 Maintenance Principles
Prompts should be maintained like code. Recommended principles:
- Every rule should be observable and verifiable; avoid vague statements like “try to do well.”
- Rules must not contradict each other—for example, requiring both brevity and exhaustive step-by-step explanations.
- Update the prompt when the project changes; revise version information promptly after tech stack upgrades.
- Place the project-level configuration in the project root or a unified directory, shared by all sessions under the same project.
4. Choosing Reasoning Effort by Task
Higher reasoning effort means the model thinks more thoroughly before answering, which suits tasks requiring multi-step derivation. But for most everyday questions, extra reasoning brings no obvious benefit—it only lengthens response time and increases output tokens.
| Task Type | Recommended Reasoning Effort | Rationale |
|---|---|---|
| Algorithm design, complex debugging, mathematical proofs | High | Relies on multi-step derivation and thorough checking |
| Code review, architecture trade-offs | Medium to high | Requires weighing multiple constraints simultaneously |
| Translation, polishing, summarization, format conversion | Low or off | Task boundaries are clear; reasoning gains are limited |
| General knowledge Q&A, fact lookup | Low or off | A direct answer suffices |
If answer quality declines for a certain task type, raise the reasoning effort step by step rather than starting at the maximum level.
5. Session and Context Management
5.1 Split Sessions by Topic
Multiple sessions can be opened for the same project. Each session should handle a single topic—for example, “API refactoring,” “performance troubleshooting,” and “documentation writing” should each be independent. Mixing unrelated topics in one session causes the history to keep growing, which increases cost and interferes with the model’s judgment of the current question.
5.2 Compressing Long Sessions
When a session exceeds a certain number of turns, ask the model to first output the current conclusions, confirmed facts, and unresolved issues, then start a new session with that summary. Replacing the full text with a summary preserves key information while significantly shortening the context.
5.3 Sharing Information Across Sessions
Some tools support shared memory within the same project. If implementing this yourself, use a “project notes” file to record long-term decisions, terminology, and conventions, and reference it at the start of each new session. Two points require attention: avoid writing sensitive information, and regularly clean up outdated content to prevent the model from answering based on stale conclusions.
6. Cost Estimation
Before deciding whether to enable high reasoning effort, you can estimate the cost of a single call with a simple formula:
Cost = input tokens × input unit price + output tokens × output unit price
If reasoning is billed separately, add the reasoning token portion as well. Unit prices should follow the pricing published by the service provider. Since different models tokenize differently, token counts can only be estimated, and results are for reference only.
Sample code:
def estimate_cost(input_tokens: int, output_tokens: int,input_price: float, output_price: float,reasoning_tokens: int = 0,reasoning_price: float = 0.0) -> float:"""Estimate the cost of one call based on unit prices;prices and cost use the same currency unit."""return (input_tokens * input_price+ output_tokens * output_price+ reasoning_tokens * reasoning_price)
Accumulating the estimated cost per turn lets you observe how session cost grows with the number of turns, helping you decide when to compress history or start a new session.
7. Common Issues and Troubleshooting
7.1 Costs Higher Than Expected
- Check whether the session has accumulated a large history and whether a new session should be started.
- Check whether large blocks of logs are being pasted repeatedly.
