This domain is 12% of scored content. It’s about running GenAI applications cheaply, quickly and visibly. Questions describe a bill that’s too high, latency that’s too long or a failure nobody can see, and ask for the smallest change that fixes it. The levers are almost always the same: send fewer tokens, use a smaller model, cache, batch, stream, and measure.
Cost: token efficiency
Cost on Bedrock on-demand is input tokens plus output tokens, and output tokens cost more per token. Latency also grows with output length.
| Technique | Effect |
|---|---|
| Token estimation and tracking | Count tokens before sending (tokenizer estimates, the usage field in responses) and record per request, per user and per feature in CloudWatch |
| Prompt compression | Shorter instructions, remove filler and repeated examples, compress or summarise history |
| Context pruning | Retrieve fewer and better chunks (top-k tuning, reranking, metadata filters); drop old turns |
| Response limiting | Set maxTokens, request concise formats, use stop sequences |
| Context window optimisation | Put stable content first so it can be cached; don’t fill the window just because it’s available |
Long contexts are not free; more context can also reduce quality.
Cost: model selection
- Cost-capability trade-off: evaluate several models on your test set and compare price-to-performance (quality score per dollar), not raw quality.
- Tiered usage: route simple queries to a small, cheap model and complex ones to a large model; cascade by escalating when confidence is low. Bedrock intelligent prompt routing automates this within a model family.
- Right-size: distilled models and small models fine-tuned for one task often beat a large general model on cost with equal quality.
- Pricing modes: on-demand (per token), batch inference (discounted, asynchronous), Provisioned Throughput (hourly, committed), and service tiers that trade price for priority or latency on some models. Match mode to traffic: spiky means on-demand, steady and high means provisioned, offline means batch.
- Cost visibility: application inference profiles with cost allocation tags show spend per application or tenant in Cost Explorer; AWS Budgets and Cost Anomaly Detection alert on unusual spend.
Throughput and capacity
- Quotas apply per model and Region in requests per minute and tokens per minute. Exceeding them returns throttling errors (429). Requests for increases go through Service Quotas. For some models, output tokens count against the quota at a multiple (a burn rate), so setting
maxTokensmuch higher than needed consumes quota. - Batching: batch inference for offline workloads; batch embedding calls; group small prompts where models allow it.
- Concurrency control: SQS plus Lambda with a maximum concurrency setting keeps you under quotas and smooths bursts.
- Cross-Region inference raises effective throughput and handles bursts.
- Provisioned Throughput gives dedicated model units when you need guaranteed rate; size by tokens per minute at peak and check utilisation so you don’t pay for idle units.
- SageMaker endpoints: auto scaling policies on invocations per instance, concurrency or custom token metrics; scale-in cool-downs to avoid thrashing; warm capacity for slow-loading models.
- Capacity planning: estimate tokens per request × requests per minute at peak, add headroom, and monitor actual prompt and completion size distributions.
Caching
| Cache | How it works | Saves |
|---|---|---|
| Bedrock prompt caching | Mark a stable prefix (system prompt, documents) with a cache checkpoint; cached tokens are reused within a short TTL (about 5 minutes, refreshed on use) at a lower price, with lower latency | Cost and latency for repeated long prefixes. Put static content first, variable content last |
| Exact-match (deterministic request hashing) | Hash the normalised prompt plus parameters; store the response in DynamoDB, ElastiCache or S3 | Repeated identical requests. Needs temperature 0 or acceptance of one canned answer |
| Semantic cache | Embed the query; if a stored query is within a similarity threshold, return its answer (ElastiCache or MemoryDB vector search, OpenSearch) | Paraphrased repeats such as FAQs. Tune the threshold: too loose returns wrong answers |
| Edge caching | CloudFront or API Gateway caching for public, non-personalised responses | Global read-heavy content |
| Pre-computation | Generate answers for predictable queries ahead of time (batch job) | Latency and cost for known questions |
| Result fingerprinting | Fingerprint documents or inputs so unchanged items aren’t reprocessed (summaries, embeddings) | Re-embedding and re-summarising cost |
Never cache personalised or sensitive responses in a shared cache without keying on the user or tenant.
Latency and performance
- Streaming (
ConverseStream): time to first token drops, so the app feels fast. - Latency-optimised inference options for supported models and smaller models for time-sensitive paths.
- Parallel requests: run independent sub-tasks (several retrievals, several classification calls) in parallel with Step Functions Parallel or Map states or async code.
- Reduce output length and chain depth; fewer sequential model calls means lower latency.
- Retrieval speed: index tuning (HNSW parameters such as
ef_search,m, quantisation to reduce memory), fewer or smaller vectors (lower dimensionality), shard and replica sizing, query preprocessing (rewrite, normalise), hybrid search with custom scoring weights, filtering to shrink the candidate set, and caching frequent queries. - API profiling: log prompt size, completion size and latency per call; find slow steps with X-Ray; communication patterns such as keeping connections warm, VPC endpoints in the same Region and avoiding cross-Region hops.
- Pre-warm SageMaker and provisioned capacity ahead of known peaks.
Inference parameters
| Parameter | Effect | Typical use |
|---|---|---|
| Temperature | Randomness: low is focused and repeatable, high is varied | Low (0–0.3) for extraction, classification, SQL; higher for brainstorming |
| Top-p (nucleus) | Sample from the smallest set of tokens whose probability sums to p | Alternative to temperature; adjust one, not both |
| Top-k | Sample from the k most likely tokens | Cut the tail of unlikely tokens |
| Max tokens | Cap on output length | Controls cost and prevents runaway output |
| Stop sequences | Strings that end generation | Clean delimiting of structured output |
Parameter names and ranges differ per model; use Converse inferenceConfig for the common ones and additionalModelRequestFields for model-specific ones (such as top-k for some models). Validate changes with A/B testing against the same evaluation set before rolling out.
Monitoring and observability
Layers of observability.
| Layer | Sources |
|---|---|
| Operational metrics | CloudWatch AWS/Bedrock metrics: Invocations, InvocationLatency, InputTokenCount, OutputTokenCount, InvocationClientErrors, InvocationServerErrors, InvocationThrottles, plus guardrail intervention metrics. Dimensions include model ID and (with profiles) the application |
| Invocation logging | Model invocation logging (off by default) writes request metadata, prompts and responses to S3 and/or CloudWatch Logs. Use it for forensic analysis, offline evaluation and audit |
| Tracing | X-Ray and OpenTelemetry through ADOT; agent traces; Bedrock Agents trace; AgentCore Observability for agent steps and tool calls |
| Custom metrics | Embedded metric format or PutMetricData for token cost per request, cache hit rate, guardrail blocks, thumbs-up rate, hallucination flags, retrieval hit rate |
| Business impact | Task completion, conversion, ticket deflection, time saved; dashboards in CloudWatch or QuickSight |
What to alarm on. Token usage bursts and cost anomalies (CloudWatch anomaly detection, Cost Anomaly Detection), latency percentiles (p95, p99, time to first token), throttle rate, error rate, guardrail block rate, retrieval empty-result rate, response drift (shifts in length, sentiment, or evaluator scores), and quality scores sampled from production.
Tool and agent monitoring. Track tool call counts, latency, error rates and parameter validation failures per tool; follow multi-agent hand-offs with a trace ID; baseline normal call patterns and alert on deviations (a tool suddenly called 100 times per request signals a loop or abuse).
Vector store operations. Monitor query latency, indexing lag, memory and CPU (OpenSearch metrics, Aurora Performance Insights), index health and shard balance; run automated index optimisation (merge segments, refresh intervals, rebuild after embedding changes) and data quality validation (empty chunks, duplicates, stale documents).
GenAI troubleshooting frameworks. Failures that don’t exist in classic ML: hallucination, inconsistent answers, reasoning errors, prompt drift. Techniques: golden datasets with known answers run on schedule to detect hallucination and regressions; output diffing across runs or versions to measure consistency; reasoning path tracing to find where multi-step logic went wrong; specialised pipelines that sample production traffic, score it with an LLM judge and chart trends.
Common traps
- Provisioned Throughput for unpredictable traffic.
- Caching with high temperature and expecting identical output.
- Semantic cache threshold set too loose.
- Raising
maxTokens“just in case” and burning quota and money. - Placing variable content at the start of a prompt, breaking prompt caching.
- Turning on invocation logging and forgetting the storage cost and sensitivity of what’s stored.
- Measuring only averages; p95 and time to first token matter for users.
Exam checklist
- Token levers: compression, pruning, max tokens, caching, smaller model.
- On-demand vs Provisioned vs batch; cross-Region inference for bursts; SQS plus Lambda concurrency limits.
- Prompt caching vs exact-match vs semantic caching, and what each is safe for.
- Streaming, parallelism, pre-computation, smaller models for latency.
- Temperature, top-p, top-k, max tokens, stop sequences.
- Metrics in
AWS/Bedrock; invocation logging to S3 and CloudWatch Logs; X-Ray; custom quality metrics. - Application inference profiles plus cost allocation tags for per-team cost.
- Golden datasets, output diffing and reasoning traces for GenAI-specific troubleshooting.