Use prompt caching with open-weight models on Amazon Bedrock
In one sentence
Amazon Bedrock now supports explicit and implicit prompt caching for open-weight models to help reduce input costs and response latency.
Key points
- Open-weight models on Amazon Bedrock now support explicit prompt caching alongside implicit caching.
- Implicit caching automatically reuses stable prompt prefixes, making it ideal for conversations and agent loops.
- Explicit caching lets developers mark reusable prefixes with breakpoints to avoid paying cache write rates for changing content.
- The post demonstrates both caching modes via the Chat Completions API using a product manual assistant and an OpenCode coding agent.
In depth
An AI-written overview of the original article, not the article itself.
According to the AWS Machine Learning Blog, open-weight models on Amazon Bedrock now support explicit prompt caching alongside implicit caching through the Chat Completions API. Prompt caching reuses the computed state of long contexts such as system prompts, reference documents, or conversation history across requests, helping reduce input costs and response latency.
Implicit vs. explicit caching
The post explains that implicit caching works automatically on a best-effort basis without request changes, making it suitable for conversations and agent loops with naturally stable prefixes. However, it may write changing user questions to the cache, which can add costs on models with higher cache write rates.
Explicit caching gives developers control by setting prompt_cache_options to explicit and adding prompt_cache_breakpoint markers. Content up to each breakpoint is cached and reused, while content after the last breakpoint is billed at standard input rates, supporting layered prefixes and avoiding unnecessary cache writes.
API examples and coding agent
The article demonstrates using the OpenAI Python SDK with the Amazon Bedrock Chat Completions endpoint, authenticated via short-term API keys from aws-bedrock-token-generator. In a sample caching a 4,000-token product manual, developers can inspect cache reads and writes through usage.prompt_tokens_details in each response.
The post also applies implicit caching to OpenCode, an open-source coding agent, over the same endpoint. Across a three-turn coding session, Amazon Bedrock automatically caches the system prompt, tool definitions, and prior turns without extra configuration, processing only the new tail of each request.
Best practices for prompt caching
The post recommends placing static content first and dynamic elements such as timestamps or request IDs at the end in both modes, while ensuring prefixes meet the minimum token count on the model card.
Developers should also verify cache hits using response fields and runtime metrics, maintain steady traffic to reset the cache time to live, and only cache content that later requests will reuse.
This summary was generated by AI from the original article and may contain errors; the original is authoritative. Copyright belongs to the original author.