opensite-ai/opensite-skills / amazon-bedrock
amazon-bedrock
FlaggedBuilds generative AI applications on Amazon Bedrock. Covers model invocation (Converse API, InvokeModel), RAG with Knowledge Bases, Bedrock Agents, Guardrails, and AgentCore (including the Harness managed agent loop). Applies when invoking models, setting up Knowledge Bases, creating agents, applying guardrails, deploying to AgentCore, migrating/porting/converting a Bedrock Agent (including inline agents) to an AgentCore Harness, troubleshooting Bedrock errors (ThrottlingException, AccessDeniedException), or choosing Bedrock models (Claude, Llama, Nova, Titan). Also for prompt caching, quota and throttling diagnosis, cost tracking, migrating between Claude model generations, chunking strategies, and Bedrock model selection. Covers AgentCore Payments (x402, microtransactions, Payment Manager, Connector, Instrument, Coinbase CDP, Stripe Privy, paid endpoints, agent payments). NOT for custom model training, Rekognition, or Comprehend. For SageMaker model discovery, customization, or endpoints, use aws-ai-ml.
references/cost-tracking.md
View on GitHub# Bedrock Cost Attribution and Tracking
Track, allocate, and manage Bedrock inference costs across teams, products, and models. Bedrock charges per input/output token with model-specific rates.
## Table of Contents
- [Cost Attribution Approaches](#cost-attribution-approaches)
- [Application Inference Profiles](#application-inference-profiles)
- [IAM Principal-Based Attribution](#iam-principal-based-attribution)
- [CloudWatch Usage Monitoring](#cloudwatch-usage-monitoring)
- [Budget Alerts](#budget-alerts)
## Cost Attribution Approaches
| Approach | Best For | Setup Effort |
|----------|----------|-------------|
| Application inference profiles + cost allocation tags | Per-product or per-team cost tracking in Cost Explorer | Medium — create profiles, tag, activate in Billing |
| IAM principal-based (CUR 2.0) | Per-developer or per-role attribution | Low — automatic in CUR 2.0, no Bedrock config needed |
| Model invocation logging + custom analytics | Fine-grained per-request analysis (token counts, latency, model) | High — enable logging, build queries |
For most teams, **application inference profiles with cost allocation tags** is the recommended approach. It provides clean cost breakdowns in Cost Explorer without custom analytics.
## Application Inference Profiles
### Setup Workflow
#### 1. Create an Application Inference Profile
```bash
aws bedrock create-inference-profile \
--inference-profile-name "<TEAM_OR_PRODUCT_NAME>" \
--model-source "copyFrom=arn:aws:bedrock:<REGION>::foundation-model/<MODEL_ID>" \
--region <REGION> --profile <PROFILE>
```
Note the returned `inferenceProfileArn`.
#### 2. Tag the Profile
```bash
aws bedrock tag-resource \
--resource-arn <INFERENCE_PROFILE_ARN> \
--tags key=CostCenter,value=<COST_CENTER> key=Project,value=<PROJECT> \
--region <REGION> --profile <PROFILE>
```
#### 3. Activate Cost Allocation Tags
In the AWS Billing console (or via API), activate the tags as cost allocation tags. Tags take ~24 hours to appear in Cost Explorer after activation.
#### 4. Use the Profile for Inference
Replace the base model ID with the inference profile ARN in application code:
```python
response = bedrock_runtime.converse(
modelId="<INFERENCE_PROFILE_ARN>",
messages=[...],
inferenceConfig={"maxTokens": 1024}
)
```
#### 5. Verify in Cost Explorer
After 24–48 hours, filter Cost Explorer by the tag keys. Bedrock costs appear under `Amazon Bedrock` service, grouped by tag values.
## IAM Principal-Based Attribution
CUR 2.0 automatically records the IAM caller identity for every Bedrock API call. No Bedrock-specific setup required.
To use: tag IAM roles/users with keys like `department`, `costCenter`, or `project`, then filter CUR 2.0 data by those tags. Works for per-developer tracking when each developer assumes a distinct IAM role.
Limitation: only tracks who made the call, not which product or feature triggered it. Use inference profiles for product-level attribution.
## CloudWatch Usage Monitoring
Key metrics for cost monitoring (namespace `AWS/Bedrock`, dimension `ModelId`):
| Metric | Cost Signal |
|--------|------------|
| `InputTokenCount` | Input token spend (charged per token) |
| `OutputTokenCount` | Output token spend (higher per-token rate) |
| `Invocations` | Request volume |
| `CacheReadInputTokens` | Tokens served from cache (billed at a reduced rate; see pricing page) |
| `CacheWriteInputTokens` | Cache write tokens (may be billed above the standard input rate; see pricing page) |
Exact cache read and write rates are model-dependent — consult the [Amazon Bedrock pricing page](https://aws.amazon.com/bedrock/pricing/) for the specific figures for your model.
### Cost Analysis Script
```bash
python3 scripts/analyze-bedrock-costs.py --days <DAYS> --region <REGION> --profile <PROFILE>
```
The script queries Cost Explorer for Bedrock spend grouped by usage type (model + token direction) over the specified period.
## Budget Alerts
Set up AWS Budgets to alert when Bedrock spend approaches a threshold:
```bash
aws budgets create-budget --account-id <ACCOUNT_ID> \
--budget '{"BudgetName":"bedrock-monthly","BudgetLimit":{"Amount":"<AMOUNT>","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST","CostFilters":{"Service":["Amazon Bedrock"]}}' \
--notifications-with-subscribers '[{"Notification":{"NotificationType":"ACTUAL","ComparisonOperator":"GREATER_THAN","Threshold":80},"Subscribers":[{"SubscriptionType":"EMAIL","Address":"<EMAIL>"}]}]' \
--profile <PROFILE>
```
This alerts at 80% of the monthly budget. Adjust threshold and notification targets as needed.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |