Why Long Prompts Increase LLM Costs, and How Runtime Policy Bounds What Enters Them
Most hosted LLM APIs are stateless, so a multi-turn application resends the system prompt, conversation history, retrieved documents and tool outputs on every call. Input tokens are billed per request, and longer contexts add latency and compute load, so the cost of each turn grows with session length. Runtime policy enforcement in the execution path adds control over what enters a prompt and records what was allowed, redacted or blocked.
- Inventory every source that feeds a prompt: system prompt, history, retrieved documents, tool outputs and memory stores.
- Measure input tokens per source and per turn, so growth is attributable to a component rather than to the session as a whole.
- Treat retrieved content and tool outputs as untrusted input, and confirm they are scoped to what the requesting user may access.
- Remove secrets from system prompts and keep user and system prompts distinct.
- Decide which interactions need deterministic rules (allow, redact, block, rate limit, escalate) enforced outside the model's reasoning.
- Confirm you can reconstruct, for any call, what content was sent and what decision was applied, and who owns each limit.
How cost scales with prompt length and turns
A model does not read text directly. A tokenizer splits input into tokens, and providers meter usage in tokens. Many providers price input tokens, output tokens and cached input tokens at different rates, so the size of the input is a direct billing variable.
The second factor is statelessness. A hosted chat API does not remember the previous request. To give the model continuity, the application sends the full context again with each call: the system prompt, the earlier turns, any retrieved passages and any tool results. The model sees a conversation only because the client rebuilds it every time.
This is why cost per turn compounds. If each turn adds a similar number of tokens, the input for turn n is roughly proportional to n, and the cumulative input across a session grows roughly with the square of the number of turns. The user experiences a steady conversation. The billing meter sees a context that gets larger on every request.
Length also affects serving behavior. Self-attention work grows with sequence length, and the key-value cache that holds intermediate state grows with the number of tokens in context. Longer prompts generally mean more processing before the first output token, which shows up as latency and as compute load on the provider. Context window limits set the ceiling, but cost and latency rise well before the ceiling is reached.
Per-token price is also an incomplete predictor of spend. Different models use different numbers of tokens to finish the same task, so end-to-end cost can diverge from the listed rate.
Where context growth comes from
Platform teams often assume the user's message is the main input. In copilots, agents and coding assistants it is usually a small part. Context is assembled at runtime from several sources, and each one grows on its own schedule.
- System prompts: Long instruction sets, policies and formatting rules, resent unchanged on every call.
- Conversation history: Each turn adds the user message and the model reply, and all of it is carried forward.
- Retrieved documents: RAG pipelines insert passages chosen per query from external documents and web pages, often more than the answer needs.
- Tool outputs: API responses, file contents and query results are appended to context, and an agent loop can add several per task.
- Memory stores: Summaries and long-term memory are reloaded into the context window at the start of later interactions.
Common mitigation patterns and their trade-offs
Four patterns are in common use, and each trades something for a smaller or cheaper prompt.
Truncation drops the oldest turns or caps total tokens. It is simple and predictable, but it can discard facts the user stated earlier, or the instructions that shaped the session, and the application may not notice what was lost.
Summarization replaces older turns with a condensed version. It keeps continuity in fewer tokens, but it adds a model call, loses detail, and can introduce errors. A summary is also a new stored artifact. If the original history held sensitive data, the summary may carry it forward in a form that is harder to review.
Retrieval scoping limits what is inserted from external sources, through tighter queries, fewer passages and access filters. It reduces irrelevant context, but its quality depends on retrieval precision, and it only controls content when the scoping rules reflect what a given user is allowed to see.
Prompt caching stores frequently used prompt segments so repeated prefixes cost less to process. It is a documented mechanism offered by several providers and for locally run open-weight models. It changes how repeated content is processed and priced, not what is in the prompt. Everything still goes to the model, including anything that should not have been there.
These patterns are context engineering. They shrink or reshape context, but none of them decides whether specific content should enter a call, and none produces a record of that decision.
Prompt content is a risk surface as well as a cost surface
Because context is built at runtime from external data, it is also an input channel. Retrieved documents and web pages can contain indirect prompt injection, meaning instructions placed in content the model later reads. Tool outputs can carry the same risk, and a poisoned or impersonated tool can propagate it. Agents that load prompts dynamically or connect to MCP servers and external agents widen the path further.
The exposure also runs outward. Sensitive data in history, retrieved records or tool results is sent to the model on every call, and again to any downstream tool the model invokes. System prompts are a related case. Prompt extraction attacks try to reveal the system prompt or other hidden context, and system prompt leakage exposes any secrets placed in it. Keep credentials and secrets out of system prompts, and distinguish system prompts from user prompts in your design.
The practical consequence is that unreviewed context grows in two ways at once: more tokens billed, and more material that can leak or be manipulated. A team that only watches the token counter sees one of the two.
Runtime policy enforcement over prompt and context content
NIST guidance on agent security points to a different layer of control. Individual tool invocations, API calls and resource accesses should be verified at runtime based on current state and risk. Policy should be kept architecturally separate from model reasoning, and access decisions should be deterministic, so that a prompt cannot argue its way past a rule.
Applied to prompt content, that means evaluating each interaction before it reaches the model or tool, and returning one of a small set of outcomes. Allow the call as constructed. Redact identifiers or secrets from history, retrieved text or tool output. Block a call whose context includes content outside the user's scope or exceeds a defined size. Rate limit by user, application or team, using token-bucket or similar algorithms as NIST SP 800-228 describes for APIs. Escalate a consequential tool call for human approval.
Prompt size policy enforcement is one application of this model. A ceiling on context size becomes a rule applied in the path, with a recorded outcome, rather than a convention in each application's code. Whether limits are counted in requests or tokens is an engineering choice.
Trussed enforces policy in the execution path across models, agents, tools, MCP servers, AI sites and coding assistants. Enforcement happens at runtime, not through review after the fact, and its scope is individual interactions and tool calls. Each decision generates audit-ready evidence of what was sent and what was allowed, redacted or blocked. That evidence maps to HIPAA, NAIC, NYDFS, EU AI Act and NIST requirements, which matters to a regulated enterprise that has to show an auditor what its AI was permitted to do.
This does not replace truncation, summarization or retrieval scoping. Those shape context. Runtime policy governs what is allowed to enter the call and leaves a record.
What is resent on every model call
System prompt
Instructions repeated on each request.
Conversation history
Every prior turn, since the API holds no state.
Retrieved documents
Content assembled at runtime from external data.
Tool outputs
Results returned by tools and APIs, appended to context.
Policy decision
Allow, redact, block, rate limit or escalate before the call proceeds.
See what policy in the execution path looks like
Review how enforcement applies to individual interactions and tool calls, and how each decision becomes audit-ready evidence.
Explore Agent and Tool-Call Enforcement