专为 AWS Bedrock 上托管的模型设计的中间件。了解更多关于中间件的信息。Documentation Index
Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
| 中间件 | 描述 |
|---|---|
| 提示词缓存 | 通过缓存重复的提示词前缀来降低成本 |
提示词缓存
通过在 Amazon Bedrock 上缓存频繁重用的提示词前缀来降低推理延迟和输入 Token 成本。 This middleware automatically places cache checkpoints after the system prompt, tool definitions, and the most recent message so that the model can skip recomputation of previously seen content on subsequent requests. 提示词缓存适用于以下场景:- 具有长且一致的系统提示词的多轮对话
- 具有在多次调用中保持不变的大量工具定义的智能体
- 基于文档的问答,用户针对相同的上传上下文提出多个问题
- 具有重复静态内容的批处理工作负载
- Anthropic Claude
- Amazon Nova
了解更多关于 AWS Bedrock prompt caching strategies and limitations. Cached content must exceed 1,024 tokens for a cache checkpoint to take effect, sometimes more depending on model. See supported models, regions, and limits.
BedrockPromptCachingMiddleware
ChatBedrockConverse
ChatBedrock
配置选项
配置选项
Cache type. For
ChatBedrock, only 'ephemeral' is currently supported. For ChatBedrockConverse, this value is ignored as the Converse API always uses "default" cache type.Time to live for cached content. Valid values:
'5m' or '1h'. 请注意 Amazon Nova models only support '5m'.Minimum number of messages before caching starts.
Behavior when using unsupported models. Options:
'ignore', 'warn', or 'raise'.完整示例
完整示例
The middleware caches content up 提供自然语言接口d including the latest message in each request. On subsequent requests within the TTL window (5 minutes or 1 hour), previously seen content is retrieved from cache rather than reprocessed, reducing costs and latency.How it works:
- First request: System prompt, tools, and the user message are sent to the API and cached
- Second request: The cached content is retrieved from cache. Only the new message needs to be processed
- This pattern continues for each turn, with each request reusing the cached conversation history
Prompt caching reduces API costs by caching tokens, but does not provide conversation memory. To persist conversation history across invocations, use a checkpointer like
MemorySaver.特定模型行为
中间件自动处理不同 API 和模型系列之间的差异:| Feature | ChatBedrockConverse (Anthropic) | ChatBedrockConverse (Nova) | ChatBedrock (Anthropic) |
|---|---|---|---|
| 系统提示词缓存 | ✅ | ✅ | ✅ |
| 工具定义缓存 | ✅ | ❌ | ✅ |
| 消息缓存 | ✅ | ✅ (excludes tool result messages) | ✅ |
扩展 TTL(1h) | ✅ | ❌ | ✅ |
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

