Organizations adopting Amazon Bedrock at scale struggle to attribute model-invocation costs to specific teams, detect LLM-native anomalies like tool-call loops, and investigate spend spikes fast enough to act. This article introduces a serverless, CDK-deployable platform that provides real-time per-team cost attribution, budget enforcement, six anomaly detectors, and an autonomous Claude-powered agent that root-causes a spike and proposes reversible remediation
The problem
When multiple teams share an Amazon Bedrock account, three things break down:
- Attribution - Bedrock logs a shared IAM role ARN, so you can't tell which team spent how much without post-hoc guesswork.
- Anomaly detection - Traditional cost tools report daily/weekly. LLM-native issues (tool-call loops, prompt bloat, model switching) spike in minutes.
- Investigation speed - A platform engineer sees a cost alert but must manually cross-reference dashboards, budgets, and logs. At scale, that expertise doesn't fan out to every team.
The solution - BedrockFuse
BedrockFuse is a serverless platform deployed with AWS CDK that solves all three:
Architecture
Your apps -> LiteLLM Gateway (ECS Fargate) -> Amazon Bedrock
|
v
CloudWatch Model-Invocation Logs
|
v
Ingestor Lambda -> DynamoDB (usage events)
|
+--------------+--------------+
v v v
Attribution Budget Engine 6 Anomaly Detectors
(team/app/env) (warn/crit/ (tool-call loop,
hard-stop) prompt bloat, etc.)
|
v
Dashboard + Autonomous Spend Agent
Key components
| Layer | Services | What it does |
|---|
| Inference Gateway | Amazon ECS Fargate, ALB, LiteLLM | OpenAI-compatible proxy; logs every call without code changes |
| Ingestion | CloudWatch Logs, AWS Lambda | Normalizes invocation logs into priced, attributed usage events |
| Storage | Amazon DynamoDB (PAY_PER_REQUEST) | Usage events with GSIs for by-user, by-team, by-model queries |
| Governance | Lambda (60s), SNS, EventBridge | Six anomaly detectors + budget eval every minute; alerts on breach |
| Dashboard | CloudFront, S3, Cognito, API Gateway | React SPA with spend-by-team, budgets, and incident wall |
| Spend Agent | Amazon Bedrock (Claude), Lambda | Autonomous tool-use loop: investigates spike, proposes remediation |
The six LLM-native anomaly detectors
Traditional cost tools miss these because they don't understand LLM usage patterns:
- Spend spike vs. baseline - Sudden cost jump relative to a team's trailing average.
- Tool-call loop - A model calling tools 20+ times in a single request (runaway agent loops).
- Prompt bloat - Input token count growing abnormally, indicating unbounded context stuffing.
- Output-length spike - Model generating unusually long responses (token-cost multiplier).
- Model switching - Traffic shifting from a cheap model to an expensive one without an operational reason.
- Cache-miss surge - Prompt-cache hit rate dropping, indicating new/changing prompts at scale.
The autonomous Spend Agent
The Spend Agent is Claude on Amazon Bedrock running in a tool-use loop. When asked "why did the search team's spend spike?", it:
- Calls
get_spend_summary -> sees the 3x cost increase.
- Calls
get_top_users -> identifies role/team-search-agent as the outlier.
- Calls
list_incidents -> finds the tool_call_loop anomaly flagged by the monitor.
- Calls
get_user_detail -> discovers 22 tool calls per request (vs. the normal 3).
- Calls
propose_enforcement -> recommends a budget hard-stop (dry-run only, never enforced without operator approval).
All reasoning is visible in a trace. Enforcement stays off by default - the agent only proposes; a human decides.
Deploying it yourself
The entire platform deploys with three CDK stacks:
npx cdk deploy BedrockFusePlatform BedrockFuseApp BedrockFuseGateway --require-approval never
Prerequisites: Node.js 20+, Python 3.12+, an AWS account with Amazon Bedrock Claude models enabled.
Cost: All serverless/pay-per-request except the gateway (one Fargate task + NAT gateway, ~$2/hr when running). Clean up with npx cdk destroy --all --force.
Source: Available as a hands-on AWS Workshop Studio workshop - Real-Time Spend Governance for Amazon Bedrock with an Autonomous Spend Agent
Key design decisions
- No code changes required - The LiteLLM gateway is a drop-in proxy; apps call it instead of Bedrock directly and get governed for free.
- Attribution by convention - Glob-pattern rules match IAM ARNs and session tags to teams/apps/environments, solving the shared-role problem.
- Enforcement is advisory - The agent proposes but never blocks. Teams opt in to hard-stop enforcement per budget rule.
- LLM-native, not generic - The detectors understand tokens, tool calls, prompt sizes, and model tiers - signals that exist only in the LLM context.
What's next
- Per-model cost forecasting with time-series anomaly scoring
- Slack/Teams integration for alert routing
- Multi-region gateway federation
- Prompt-level cost tagging (attributing cost to individual features/endpoints, not just teams)
Conclusion
If your organization runs multiple teams on Amazon Bedrock and you need per-team visibility, real-time anomaly detection, and a reasoning agent that investigates spikes on your behalf - this pattern gives you a deployable reference architecture built entirely on AWS serverless services.