Anthropic::CacheControl
Inherits JSON::Serializable < Struct < Value < Object
Cache control configuration for prompt caching
Prompt caching reduces costs by up to 90% and latency by up to 85% for prompts with large amounts of repeated content.
# Default 5-minute ephemeral cache
cache = Anthropic::CacheControl.ephemeral
# Extended 1-hour cache (requires beta header)
cache = Anthropic::CacheControl.one_hour
# Use in content
content = Anthropic::TextContent.new(
text: "Large context...",
cache_control: CacheControl.ephemeral
)
Pricing:
- Cache writes (5-min): 1.25x base input token price
- Cache writes (1-hour): 2x base input token price
- Cache reads: 0.1x base input token price
Constructors
ephemeral
Create ephemeral cache control (5-minute TTL, default)
Standard caching with 5-minute duration. Cache writes cost 1.25x base price.
new(pull : JSON::PullParser)
Sourcenew(*, __pull_for_json_serializable pull : JSON::PullParser)
Sourceone_hour
Create extended cache control (1-hour TTL)
Extended caching for longer context retention. Cache writes cost 2x base price.
Requires the beta header: extended-cache-ttl-2025-04-11
# Use via beta.messages.create with the beta header
client.beta.messages.create(
betas: [Anthropic::EXTENDED_CACHE_TTL_BETA],
model: ...,
messages: [...]
)
Instance methods
ttl
Sourcetype
Source