Monitoring Token Usage, Quality and Behavioral Drift
This lesson covers generative AI key performance indicators, anomaly detection and cost monitoring, which tell you whether answers are good, costs are controlled and behaviour is changing.
Learning outcomes
After completing this lesson, you will be able to:
- Track generative AI key performance indicators.
- Detect bursts and drift with CloudWatch anomaly detection.
- Run scheduled benchmarks and cost anomaly detection.
GenAI key performance indicators
Token usage per model, application, feature and tenant, and tokens per request, track cost and capacity. Prompt effectiveness measures whether prompts achieve their purpose: task success rate, format validity rate, user ratings and escalations per prompt version. Hallucination rate is estimated from contextual grounding check failures, LLM-judge faithfulness scores on sampled responses and golden dataset runs. Response quality combines judge scores, user feedback and task outcomes. These are published as custom CloudWatch metrics with dimensions for model, prompt version and feature.
# Embedded metric format: one log line becomes metrics without a PutMetricData call
print(json.dumps({
"_aws": {"Timestamp": int(time.time() * 1000), "CloudWatchMetrics": [{
"Namespace": "Assistant/GenAI", "Dimensions": [["Feature", "PromptVersion"]],
"Metrics": [{"Name": "FaithfulnessScore"}, {"Name": "FormatValid"}, {"Name": "OutputTokens"}]}]},
"Feature": "claims-qa", "PromptVersion": "7",
"FaithfulnessScore": 0.91, "FormatValid": 1, "OutputTokens": 212
}))Which KPI family?
Anomaly detection for bursts and drift
CloudWatch anomaly detection learns the normal pattern of a metric, including daily and weekly seasonality, and alarms when values leave the expected band. It suits token burst patterns (a sudden spike in tokens from one tenant, possibly misuse or a runaway agent) and metrics whose normal level changes over the day. Response drift is detected by tracking distributions of response length, refusal rate, sentiment, language and judge scores over time, and by comparing embeddings of current responses to a golden set with those from a reference period; a drop in similarity or quality after a model or prompt update triggers investigation.
Detecting the unusual
Benchmarks and cost anomaly detection
Performance benchmarks run on a schedule, for example a nightly golden dataset run with latency measurements, to detect regressions from provider-side model updates or configuration drift. AWS Cost Anomaly Detection uses machine learning on cost and usage data to alert on unusual spend by service, account or cost allocation tag, catching cost problems that token metrics might not attribute to a cause. AWS Cost Explorer analyses spend trends, including by tagged application inference profile. The following table summarises GenAI monitoring signals.
| Signal | Source | Detects |
|---|---|---|
| Tokens per tenant or feature | Token metrics; custom metrics | Cost growth; misuse; runaway agents |
| Format validity and task success | Application validation metrics | Prompt effectiveness problems |
| Grounding failures and faithfulness | Guardrail metrics; judge scores | Hallucination rate |
| Response length, refusal rate, similarity to baseline | Custom metrics | Response drift |
| Nightly golden-set scores and latency | Scheduled benchmark | Regressions |
| Spend by service or tag | Cost Anomaly Detection; Cost Explorer | Unexpected cost |
The following diagram contrasts flat operational metrics with a falling quality benchmark for an assistant whose answers became vaguer.

Silent quality decline
Users report that an assistant's answers have become vaguer over two weeks. Latency and error metrics are normal.
Operational metrics cannot detect this. A nightly golden dataset benchmark with LLM-judge scores, plus custom metrics for faithfulness on sampled traffic and response length, would have shown the decline; anomaly detection alarms on these metrics catch the next one early, and invocation logs show which prompt version or model was involved.
Which alarm type catches unusual token bursts on a seasonal metric?
Show answer
A CloudWatch anomaly detection alarm.
Exam Tips
Remember for the exam
- Monitor tokens, prompt effectiveness, hallucination rate and quality as custom metrics.
- Anomaly detection alarms catch token bursts and seasonal metrics.
- Detect drift with output statistics and golden-set comparisons.
- Unexpected spend: Cost Anomaly Detection.