
I Set Up Per-Team LLM Cost Tracking for Amazon Bedrock in 30 Minutes — Here's How
Multiple teams sharing a single AWS account for Amazon Bedrock? Your monthly bill shows one number. You have no idea who's spending what. Sound familiar?
I ran a proof-of-concept that solves this with a single open-source binary, zero application code changes, and a built-in analytics dashboard. Here's exactly how I did it.
The Problem No One Talks About
Generative AI adoption is spreading fast inside organizations. The payments team is using Claude Opus for complex financial analysis. The fraud team is running transaction classification on Claude Haiku. The product team is generating onboarding copy with Nova Lite.
They all hit the same Bedrock account. The AWS bill says "$X on Bedrock this month." That's it.
No one can answer:
- Which team burned through the most tokens?
- Who's using the expensive models when a cheaper one would do?
- Can we set budgets before someone accidentally runs a recursive agent loop for 8 hours?
Cloud cost allocation tags help at the billing level, but they don't give you real-time visibility or enforcement. You need something in the request path.
The Fix: An AI Gateway in Front of Bedrock
AgentGateway is an open-source proxy (Linux Foundation project, written in Rust) that sits between your applications and LLM providers. It exposes an OpenAI-compatible endpoint, so your apps swap one URL and everything else stays the same.
What it gives you:
- Per-team authentication via virtual API keys
- Per-request token counting (input + output)
- USD cost calculation using a pricing catalog
- Built-in analytics dashboard — group by user, model, team
- Rate limiting and budget controls
No Prometheus. No Grafana. No external observability stack. Just the binary.
The Architecture
Team A (Finance) ─────┐ │ ┌───────────────────┐ ┌──────────────┐Team B (Risk) ─────┼─────▶│ AgentGateway │─────▶│ Amazon │ │ │ │ │ Bedrock │Team C (Product) ─────┘ │ Auth │ Track │ $ │ │ │ └────────┬──────────┘ └──────────────┘ │ ▼ ┌───────────────────┐ │ Analytics Dashboard│ │ (tokens/cost/team) │ └───────────────────┘Each team gets a virtual API key. The gateway authenticates, forwards to Bedrock, counts tokens, prices the request, and logs everything to a local SQLite database. The dashboard reads from that database.
Step-by-Step Setup
Install
One command on macOS or Linux:
curl -sL https://agentgateway.dev/install | bashConfigure
Create
config.yaml :config: adminAddr: "0.0.0.0:15000" database: url: "sqlite://./data.db?mode=rwc" modelCatalog: - file: ./base-costs.json
llm: port: 4000 policies: apiKey: mode: strict keys: - key: sk-your-payments-team-key metadata: user: payments-team group: finance - key: sk-your-fraud-team-key metadata: user: fraud-team group: risk - key: sk-your-onboarding-team-key metadata: user: onboarding-team group: product models: - name: "us.anthropic.claude-opus-4-5-20251101-v1:0" provider: bedrock params: awsRegion: us-west-2 - name: "us.anthropic.claude-sonnet-4-6" provider: bedrock params: awsRegion: us-west-2 - name: "us.anthropic.claude-haiku-4-5-20251001-v1:0" provider: bedrock params: awsRegion: us-west-2 - name: "us.amazon.nova-pro-v1:0" provider: bedrock params: awsRegion: us-west-2 - name: "us.amazon.nova-2-lite-v1:0" provider: bedrock params: awsRegion: us-west-2The
metadata.user and metadata.group fields are what the dashboard uses to group costs. Name them whatever maps to your org.Set Up the Pricing Catalog
Create
base-costs.json :{ "providers": { "aws.bedrock": { "models": { "us.anthropic.claude-opus-4-5-20251101-v1:0": { "rates": { "input": "15.0", "output": "75.0" } }, "us.anthropic.claude-sonnet-4-6": { "rates": { "input": "3.0", "output": "15.0" } }, "us.anthropic.claude-haiku-4-5-20251001-v1:0": { "rates": { "input": "0.8", "output": "4.0" } }, "us.amazon.nova-pro-v1:0": { "rates": { "input": "0.8", "output": "3.2" } }, "us.amazon.nova-2-lite-v1:0": { "rates": { "input": "0.06", "output": "0.24" } } } } }}Rates are in USD per 1,000,000 tokens. The provider key must be
aws.bedrock — I'll explain why in the gotchas section.Start
agentgateway -f config.yamlThat's it. Dashboard at
localhost:15000/ui . LLM endpoint at localhost:4000 .Send Requests
Teams just add their key to the Authorization header:
curl http://localhost:4000/v1/chat/completions \ -H "Authorization: Bearer sk-your-payments-team-key" \ -H "Content-Type: application/json" \ -d '{ "model": "us.anthropic.claude-sonnet-4-6", "messages": [{"role": "user", "content": "Analyze payment processing patterns..."}], "max_tokens": 500 }'The access logs immediately show cost:
gen_ai.provider.name=aws.bedrockgen_ai.request.model=us.anthropic.claude-sonnet-4-6gen_ai.usage.input_tokens=42gen_ai.usage.output_tokens=156agw.ai.usage.cost.total=0.002466
What I Saw in the Dashboard
I generated 105 requests across the three teams using five models with varying prompt sizes:
Team | Strategy | Result |
|---|---|---|
Payments (Finance) | Heavy Opus + Sonnet, large prompts | Highest cost |
Fraud (Risk) | Balanced model mix, medium prompts | Medium cost |
Onboarding (Product) | Mostly Nova Lite + Haiku, small prompts | Lowest cost |
Grouping by User immediately showed the cost disparity. Grouping by Model revealed that Claude Opus drove the majority of spend despite being used in only 15 requests out of 105. Grouping by Group rolled it up to the department level.
This is exactly the data you need for chargeback conversations.
Three Gotchas That Cost Me Time
1. Use Inference Profile IDs, Not Model IDs
Newer Bedrock models (Nova 2, Claude Sonnet 4, etc.) require inference profile IDs for on-demand invocation. If you pass the raw model ID, you get:
"Invocation of model ID amazon.nova-2-lite-v1:0 with on-demand throughput isn't supported."The fix: prefix with
us. (the cross-region inference profile):❌ amazon.nova-2-lite-v1:0✅ us.amazon.nova-2-lite-v1:0List available profiles with:
aws bedrock list-inference-profiles --region us-west-22. The Provider Key Is aws.bedrock , Not bedrock
I initially created my cost catalog with
"bedrock" as the provider key. Tokens showed up in the dashboard, but costs stayed at zero.The fix: check the access logs for
gen_ai.provider.name . AgentGateway uses aws.bedrock internally. Your catalog must match exactly.3. Database Format Matters
The SQLite URL format in the docs is
sqlite://./data.db?mode=rwc . I initially used sqlite:data.db which worked for basic operations but had issues. Stick with the documented format, and always delete data.db when changing your key metadata — old requests without attribution will pollute the dashboard.
Beyond the POC: What About Production?
This POC uses the open-source AgentGateway binary. It works great for validation, but for production multi-team deployments you'd want:
- SSO integration — teams authenticate with corporate identity, no virtual keys
- Per-team and per-user hard budget limits
- Automatic cost attribution from identity claims
- Managed operations and enterprise support
AWS Native Cost Attribution (complementary to any gateway):
- Tag your per-team IAM roles → costs appear in Cost Explorer automatically
- Create Application Inference Profiles per team → billing-level attribution
- Both work alongside the gateway for FinOps reconciliation
The best practice is to combine both: gateway for real-time governance and developer experience, AWS native for billing reconciliation.
The 30-Second Pitch
If you have multiple teams or applications calling Bedrock from one account and you need cost visibility:
- Install AgentGateway (one binary, one command)
- Define virtual keys per team in the config
- Create a model pricing catalog
- Point your apps at the gateway endpoint
- Open the dashboard
No infrastructure to deploy. No application code changes. No observability stack to maintain. Just per-team, per-model, per-request cost tracking with a built-in UI.
Resources
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article