I want to enable bedrock prompt caching
# ask-ai
c
I want to enable bedrock prompt caching
t
Thanks for reaching out, Shivansh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you enable prompt caching in AWS Bedrock when using LiveKit, you can easily set up the
cache_system
and
cache_tools
parameters in your LLM configuration. These settings are great because they help reduce token usage by caching system messages and tool definitions, making things more efficient for you. Here’s a simple example to guide you:
Copy code
from livekit.plugins.aws import LLM

llm_instance = LLM(
    model="anthropic.claude-3-5-sonnet-20240620-v1:0",
    cache_system=True,
    cache_tools=True
)
When you set
cache_system=True
, system messages get tagged with a
cachePoint
in the API request to AWS Bedrock. Likewise,
cache_tools=True
adds a
cachePoint
to the last tool in your tool list. If you want to keep an eye on how caching is working, just check the
prompt_cached_tokens
field in the response metadata—that shows you how many tokens were pulled from the cache. Just a quick heads-up: caching works only with certain models, so be sure your chosen model supports this feature. If you have any questions or need a hand setting this up, feel free to ask—I’m here to help! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | tools/main/README.md | Amazon Bedrock LLM plugin guide | LiveKit Docs