Claude/Code/Bedrock/How To/Enable Prompt Caching
How To Enable Prompt Caching for Anthropic Models in AWS Bedrock
Goal
Preconditions
Procedure
1. Configure Claude Code for Bedrock with caching enabled
- Set the Bedrock backend:bash
export CLAUDE_CODE_USE_BEDROCK=1 - Ensure prompt caching isn't disabled:bash
unset DISABLE_PROMPT_CACHING - (Alternative) Persist it for every session under the
envkey in~/.claude/settings.json— Claude/Code/Settings:json{ "env": { "CLAUDE_CODE_USE_BEDROCK": "true" } }
- Set the Bedrock backend:
2. Verify prompt caching via AWS CLI
- Create a
payload.json:json{ "prompt": "Human: Test for caching.\n\nAssistant:", "cache_control": {"type":"default"}, "max_tokens": 10 } - Invoke the model and specify an output file (required positional
outfile): - Inspect the response for caching metrics:bash
jq '.CacheReadInputTokens, .CacheWriteInputTokens' response.jsonPresence of numeric values confirms prompt caching is operational.
- Create a
3. Enable caching in the Bedrock console
- Open the Amazon Bedrock console.
- In Playground, select an Anthropic Claude model.
- Toggle Prompt caching to On (default for supported models).
Troubleshooting
- Invalid base64 error → Use
fileb://instead offile://for the--bodyparameter in your AWS CLI command. - Missing cache fields → Verify your account's prompt caching entitlement; contact AWS Support if unavailable.
cache_controlnot recognized → Upgrade AWS CLI/SDK to the latest version that supports cache control.- Console toggle absent → Confirm your region and console version support prompt caching.
- Invalid base64 error → Use
References