
Reducing GenAI Costs on AWS Without Sacrificing Answer Quality
Reduce GenAI costs on AWS with Amazon Bedrock caching, smart model routing and serverless design. Learn to measure cost per accepted answer while preserving quality, accuracy and document permissions.
A document Q&A application can become expensive before it becomes particularly busy. Every question may send the same instructions, repeat large portions of a document and invoke a capable model for a task that needs only a short factual answer. If users retry slow requests or ask for corrections, the cost of a completed interaction rises further.
Lowering that bill starts with understanding which work is repeated and which work actually contributes to a useful answer. Caching, model routing and serverless design can each help, but they affect different parts of the system. The practical goal is to reduce the cost of an acceptable answer while preserving the quality thresholds the application promises to users.
This article follows a proposed internal document assistant built around Amazon Bedrock. Employees ask questions about approved policies and operating procedures and the application retrieves authorized source material before generating an answer. The examples describe a measurement approach rather than savings achieved in a deployed project.
Define answer quality before changing the architecture
For a document assistant, quality means more than producing fluent text. The answer needs to reflect the source, cover the requested detail, cite the right document and acknowledge when the available evidence is insufficient. It must also respect document permissions and avoid presenting an outdated policy as current.
Build an evaluation set that represents those demands. Include straightforward lookups, questions requiring several passages, conflicting document versions, ambiguous wording and questions the sources cannot answer. Record the expected evidence and acceptance criteria so reviewers can assess correctness without relying entirely on a model’s opinion.
Set thresholds before testing cheaper designs. For example, require no unauthorized document exposure, accurate citations and a defined minimum pass rate for each question category. Evaluate harder categories separately because a large volume of easy questions can hide a regression in the cases users most need help with.
Measure the cost of a completed answer
Token charges are only one part of the request path. Include retrieval, embeddings, cache reads and writes, orchestration, application compute, storage and relevant network charges. Attribute retries and fallback calls to the original interaction so they do not disappear into separate counters.
Track cost per accepted answer alongside latency and answer-quality scores. For an evaluation run, divide its total measured serving cost by the number of answers that pass the acceptance criteria. Failed attempts remain in the numerator, making it harder for a cheap but unreliable design to appear successful.
Use this metric with the overall acceptance rate, rather than by itself. A design that declines most difficult questions might have a low cost per accepted answer but fail the application’s purpose. Report both the cost of serving traffic and how often the system delivers an acceptable result.
Remove unnecessary context before adding a cache
Inspect what the application sends to the model. Long conversation histories, duplicate retrieved passages, repeated formatting instructions and irrelevant document sections can increase input size without helping the answer. Remove duplication and retrieve evidence that directly supports the current question.
Do not cut context solely to meet a token target. A policy exception may appear in a different section from the main rule and removing it could make a shorter answer wrong. Test retrieval changes against questions that require qualifications, dates and cross-references before accepting the cost reduction.
Apply the same discipline to generated output. Ask for the detail the user needs and use output limits appropriate to the task. Detect answers that stop early so a shorter response is not counted as a successful saving when it omits required information.
Use prompt caching for stable content
Prompt caching reuses processing of eligible input content while the model still generates a new answer. In the document assistant, a stable instruction prefix or repeatedly used document context may be a candidate. The changing question and any changing evidence need careful placement so they do not unnecessarily invalidate the reusable prefix.
The Amazon Bedrock prompt caching documentation explains that availability, cache controls, token minimums and retention periods vary by model and API. Keep reusable content stable, follow the requirements for the selected model and inspect returned cache-usage fields. An eligible request does not guarantee a cache hit.
Measure cache writes as well as reads. Depending on the model, writing cached input can cost more than ordinary input, so content that is rarely reused may offer little benefit. Test real request spacing, document changes and traffic bursts rather than assuming a continuously warm cache.
A simple break-even check compares the cost of repeatedly processing a prefix normally with the cost of writing it once and reading it on later hits. Include cache misses and expiry in that calculation. Do not pad a short prompt merely to reach a caching threshold unless measurement shows a net benefit and the added content serves the task.
Treat response caching as a separate quality decision
A response cache stores an answer that the application may return without another generation call. That can avoid more work than prompt caching, but it introduces freshness and access-control responsibilities. A correct answer from yesterday may be wrong after a policy changes.
For a narrow FAQ workload, consider an exact-match cache keyed by the normalized question, authorized document scope, source version and relevant answer configuration. Include tenant or user permission boundaries where required. Recheck access before serving the answer and invalidate entries when the underlying evidence or permissions change.
Semantic caching needs more caution because similar wording does not establish equivalent meaning. “Can contractors access this system?” and “Can employees access this system?” may be close in an embedding space while requiring different answers. Test near-match questions with changed dates, roles, negation and exceptions before allowing similarity to determine reuse.
Begin with stable, repeatable questions and keep sensitive or rapidly changing answers out of the response cache. Choose expiry according to the data’s freshness needs, with explicit invalidation where stale answers would be harmful. A high cache-hit rate has little value if it increases the number of confidently outdated responses.
Route requests according to demonstrated capability
Some questions require a direct lookup from one passage, while others need comparison across documents or careful treatment of exceptions. Test whether a lower-cost model can handle the first category without reducing its acceptance rate. Use a more capable model where the evidence shows it improves results enough to justify the additional cost.
Amazon Bedrock intelligent prompt routing provides routing between supported models within a model family using response-quality criteria. Check the currently supported models and Regions before choosing this managed approach. Its routing criteria still need validation against the application’s evaluation set.
A custom router is another option when the workload needs explicit categories or different model combinations. Start with rules based on observable task requirements, such as a lookup versus a multi-document comparison. Account for classification calls, routing mistakes and any fallback generation in the total cost.
Avoid escalating only because a model says it is uncertain. Use signals the application can verify, such as missing citations, invalid structured output or failure to satisfy a required response format. A polished answer can still be wrong, so sample apparently successful answers for independent review.
Budget for fallbacks and retries
A cheaper first call followed by an expensive second call can cost more than going directly to the stronger model. Estimate the expected serving cost as the first-call cost plus routing overhead and the fallback rate multiplied by fallback cost. Compare that with the direct route using the same acceptance criteria.
Keep retries bounded and distinguish temporary service failures from poor answers. Repeating the same question with the same evidence may not repair a factual mistake. Use a defined escalation path and track whether the second attempt resolves the problem or merely adds another charge.
Coordinate request timeouts across the client and backend. If the interface times out while generation continues, a user retry can create duplicate work. Use application request identifiers and retain job status so clients can reconnect to an existing task rather than silently starting it again.
Choose serverless patterns around the request’s shape
AWS Lambda can suit short application steps and workloads with variable demand, but its economics depend on duration, memory and invocation volume. The AWS Lambda pricing page describes request and duration charges. For a conventional function that remains active while waiting for a model response, include that waiting time in the compute estimate.
Separate interactive questions from background work. An employee asking for one policy answer needs a responsive path, while document ingestion and bulk summaries can often use queued jobs. A queue can help control concurrency and absorb bursts, but queue operations, orchestration and workers still have costs.
For longer background tasks, let the submitting request return a job identifier and allow the client to check progress or receive a completion notification. This avoids holding the submission handler open for the entire job. It does not eliminate worker execution time or model charges and it adds state management that should be justified by the workload.
Measure Lambda memory settings with representative retrieval and parsing work. More memory may reduce processing time, but it also changes the charge per unit of duration. Include logs, network paths and supporting services when comparing the final architecture with a continuously running alternative.
Test each change before combining them
Run the same evaluation questions through each candidate design and record the model, prompt version, document version and configuration. Change one major variable at a time so the team can identify whether caching, retrieval, routing or compute settings caused a regression.
| Change | Potential cost benefit | Quality risk to test |
|---|---|---|
| Smaller retrieved context | Fewer input tokens | Missing exceptions or supporting evidence |
| Prompt caching | Lower repeated input-processing cost | Incorrect request construction or changed context |
| Exact response caching | Fewer generation calls | Stale answers or access-scope mistakes |
| Semantic response caching | More opportunities for reuse | Similar questions with different meanings |
| Lower-cost model route | Lower inference cost on suitable tasks | Weak reasoning or incomplete answers |
| Queued background work | Better control of bursts and concurrency | Delayed, duplicated or incomplete jobs |
Test both warm and cold caches, easy and difficult questions and normal and peak traffic. Record tail latency rather than relying only on the average. Include fallback frequency and answer truncation so an apparently cheaper configuration cannot hide extra work or incomplete output.
Repeat a subset of questions to capture model variability and have reviewers inspect cases that automated scoring marks inconsistently. After release, use a limited rollout and monitor acceptance signals, corrections and escalation rates. Keep a rollback path for changes that reduce the bill while harming the user experience.
Make acceptable answers the unit of progress
Caching is most useful when the application repeats eligible work, routing works when task difficulty matches model capability and serverless design helps when execution patterns fit its billing model. None of these choices replaces measurement and none guarantees savings for every workload.
The strongest cost reduction is one the team can explain with evidence: less repeated processing, fewer avoidable calls and a lower serving cost while the agreed quality thresholds still pass. Track those outcomes together and the architecture can become cheaper without making users pay for the saving through wrong answers, stale information or repeated attempts.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article