Skip to content

opensite-ai/opensite-skills / amazon-bedrock

amazon-bedrock

Flagged

Builds 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.

FileKindSize
.aws-skill-metadataother18 B
SKILL.mdskill md34.1 KB
assets/kb_shim.py.tmplother3.4 KB
assets/lambda_shim.py.tmplother8.0 KB
assets/tool_schema.json.tmplother389 B
references/agentcore-credentials-and-security.mdmarkdown6.5 KB
references/agentcore-gateway.mdmarkdown7.0 KB
references/agentcore-harness.mdmarkdown22.0 KB
references/agentcore-memory-observability.mdmarkdown5.6 KB
references/agentcore-payments-setup-script.mdmarkdown12.3 KB
references/agentcore-payments-wiring.mdmarkdown12.1 KB
references/agentcore-payments.mdmarkdown19.5 KB
references/agentcore-registry-evaluations.mdmarkdown6.8 KB
references/agentcore-runtime-container-build.mdmarkdown10.4 KB
references/agentcore-runtime.mdmarkdown7.6 KB
references/agents-and-action-groups.mdmarkdown16.5 KB
references/bedrock-agents-to-agentcore-harness/cli.mdmarkdown2.0 KB
references/bedrock-agents-to-agentcore-harness/deploy.mdmarkdown12.0 KB
references/bedrock-agents-to-agentcore-harness/discovery.mdmarkdown3.9 KB
references/bedrock-agents-to-agentcore-harness/eligibility.mdmarkdown3.3 KB
references/bedrock-agents-to-agentcore-harness/mapping.mdmarkdown8.9 KB
references/cost-tracking.mdmarkdown4.5 KB
references/guardrails.mdmarkdown14.7 KB
references/knowledge-bases-decision-guide.mdmarkdown2.8 KB
references/knowledge-bases-retrieval.mdmarkdown8.3 KB
references/knowledge-bases-setup.mdmarkdown17.9 KB
references/managed-knowledge-bases-retrieval.mdmarkdown8.1 KB
references/managed-knowledge-bases-setup.mdmarkdown12.7 KB
references/migrate-bedrock-agents-to-agentcore-harness.mdmarkdown11.5 KB
references/model-invocation.mdmarkdown11.0 KB
references/model-migration.mdmarkdown4.3 KB
references/model-selection-guide.mdmarkdown7.4 KB
references/prompt-caching.mdmarkdown5.5 KB
references/prompt-engineering-by-model.mdmarkdown7.9 KB
references/quota-health.mdmarkdown4.3 KB
references/sdk-converse-api-python.mdmarkdown6.3 KB
references/sdk-converse-api-typescript.mdmarkdown6.5 KB
scripts/fetch_bedrock_agent.pyscript14.1 KB

references/prompt-caching.md

View on GitHub
# Prompt Caching on Amazon Bedrock

Prompt caching stores frequently used input content so subsequent requests can reuse it, reducing latency by up to 85% and costs by up to 90%. Cache reads do not count toward Bedrock token quotas.

## Table of Contents
- [Two Approaches](#two-approaches)
- [Setup Workflow](#setup-workflow)
- [Key Concepts](#key-concepts)
- [Minimum Token Thresholds](#minimum-token-thresholds)
- [Why Isn't My Cache Working?](#why-isnt-my-cache-working)
- [Debug Workflow](#debug-workflow)
- [Break-Even Analysis](#break-even-analysis)
- [Preventing Cache Fragmentation](#preventing-cache-fragmentation)

## Two Approaches

**Simplified** (Claude models only): A single `cachePoint` marker; Bedrock checks ~20 preceding blocks automatically. First request shows `cacheWriteInputTokens > 0`; subsequent identical requests show `cacheReadInputTokens > 0`.

**Explicit** (all supported models): Place multiple `cachePoint` markers at specific positions. Supports mixed TTL (1h + 5min) for different content sections.

## Setup Workflow

### 1. Choose Strategy

Ask the developer which approach fits. Simplified is recommended for Claude-only workloads. Explicit is required for Nova models or mixed-TTL scenarios.

### 2. Fetch Implementation Guidance

Before giving implementation advice, fetch the latest from the aws-samples repo:
- Fetch `https://raw.githubusercontent.com/aws-samples/amazon-bedrock-samples/main/introduction-to-bedrock/prompt-caching/README.md`
- Key directories: `converse_api/` (recommended), `invoke_model_api/` (provider-specific)

### 3. Configure TTL

| TTL | Supported Models | Use Case |
|-----|-----------------|----------|
| 5 min (default) | All supported models | Dynamic content, short conversations |
| 1 hour | Claude Sonnet 4.6, Opus 4.6, Sonnet 4.5, Opus 4.5, Haiku 4.5 | System prompts, reference docs |

When mixing TTLs, longer durations MUST precede shorter ones.

### 4. Validate

```bash
python3 scripts/validate-prompt-caching.py --model-id <MODEL_ID> --region <REGION> --profile <PROFILE>
```

Confirm cache write on first request and cache read on second.

## Key Concepts

The `cachePoint` is a standalone content block placed **after** the content to cache: `{"cachePoint": {"type": "default"}}`. For 1-hour TTL, add `"ttl": "1h"`.

Cache metrics in the Converse API `usage` object:
- `cacheWriteInputTokens > 0`: Cache populated (first request or expired)
- `cacheReadInputTokens > 0`: Cache hit (subsequent requests within TTL)
- Both zero: Below threshold or unsupported model

For InvokeModel (Anthropic format): `cache_creation_input_tokens` and `cache_read_input_tokens`.

**Good candidates:** System prompts, few-shot examples, reference docs, tool definitions, long code files.
**Poor candidates:** Per-request user messages, dynamic context, content below the token threshold.

## Minimum Token Thresholds

Content before a cache point must meet the model's minimum. Below threshold = silently ignored.

> **Note:** This table goes stale as new models launch. Before relying on it, fetch the latest supported models from the [Amazon Bedrock model cards](https://docs.aws.amazon.com/bedrock/latest/userguide/model-cards.html) and confirm the per-model threshold on that model's card.

| Model | Minimum Tokens |
|-------|---------------|
| Claude Sonnet 4.6 | 2,048 |
| Claude Opus 4.6 / Opus 4.5 / Haiku 4.5 | 4,096 |
| Claude Sonnet 4.5 / Opus 4.1 / Opus 4 / Sonnet 4 / 3.7 Sonnet / 3.5 Sonnet v2 | 1,024 |
| Claude 3.5 Haiku | 2,048 |
| Amazon Nova Pro | 1,024 |
| Amazon Nova Lite / Micro | 1,536 |

## Why Isn't My Cache Working?

Caching fails silently. Checklist:

1. **Model not supported?** Silently ignored for unsupported models.
2. **Below minimum threshold?** Cache point ignored if content is too short.
3. **Content not identical?** Cache keys use exact byte-for-byte prefix match. Invalidators: timestamps in system prompts, whitespace differences, reordered JSON keys, session tokens before the cache point.
4. **TTL expired?** Default is 5 minutes. After expiry, next request is a cache write.
5. **Cache point misplaced?** Must be a separate content block placed **after** the content to cache.

## Debug Workflow

Run 6 automated diagnostic tests when cache issues are reported:

```bash
python3 scripts/debug-prompt-cache.py --model-id <MODEL_ID> --region <REGION> --profile <PROFILE>
```

**Tests:** (1) Model support, (2) Token threshold, (3) Cache write/read cycle, (4) Prefix sensitivity, (5) TTL behavior, (6) Break-even analysis.

**If tests fail:** Focus on the matching section above. Prefix sensitivity failures indicate cache fragmentation (see below). Break-even failures mean caching is not cost-effective at the developer's request volume.

**After diagnosis:** Recommend simplified vs explicit caching for their model, 5-min vs 1-hour TTL for their request pattern, and whether caching is cost-effective.

## Break-Even Analysis

Cache writes cost **25% more** than standard input tokens. Cache reads cost **90% less**.

| Requests per TTL Window | Savings |
|------------------------|---------|
| 1 (write only) | **-25% (costs MORE)** |
| 2 | 32% |
| 5 | 67% |
| 10 | 78% |

You need at least **2 requests within the TTL window** to break even. For single-use content, do NOT enable caching.

## Preventing Cache Fragmentation

Cache fragmentation = "static" content varies between requests. Fixes:

- Move timestamps and session IDs AFTER the cache point
- Separate static content from dynamic user context
- Use sorted JSON keys, consistent whitespace, fixed-format strings
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 119kUpdated Claude CodeCodexVerifiedInstall
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: 118kUpdated Claude CodeCodexVerifiedInstall