Skip to main content
The --prompt-caching flag enables prompt caching to reduce costs when using repeated or long system prompts.

Quick Start

praisonai "Analyze this document..." --prompt-caching --llm anthropic/claude-sonnet-4-20250514

Usage

Basic Prompt Caching

praisonai "Analyze this document..." --prompt-caching --llm anthropic/claude-sonnet-4-20250514
Expected Output:
๐Ÿ’พ Prompt Caching enabled

โ•ญโ”€ Agent Info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  ๐Ÿ‘ค Agent: DirectAgent                                                       โ”‚
โ”‚  Role: Assistant                                                             โ”‚
โ”‚  Model: anthropic/claude-sonnet-4-20250514                                          โ”‚
โ”‚  Prompt Caching: Enabled                                                     โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€ Cache Status โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  ๐Ÿ“Š Cache hit: System prompt (1,024 tokens saved)                           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Combine with Metrics

# See cost savings with metrics
praisonai "Process data..." --prompt-caching --metrics --llm anthropic/claude-sonnet-4-20250514

Supported Providers

ProviderSupportNotes
OpenAIAutoAutomatic caching for repeated prompts
AnthropicManualExplicit caching with --prompt-caching
BedrockManualExplicit caching support
DeepseekManualExplicit caching support

How It Works

  1. Enable: The --prompt-caching flag activates caching
  2. Hash: System prompt is hashed for cache lookup
  3. Check: Provider checks if prompt is cached
  4. Reuse: Cached prompts skip re-processing
  5. Save: Reduced token costs for cached portions

Cost Savings

Prompt caching can significantly reduce costs for:
ScenarioSavings
Long system promptsUp to 90%
Repeated instructionsUp to 80%
Document analysisUp to 70%
Multi-turn conversationsUp to 50%

Examples

Long System Prompt

# Agent with extensive instructions benefits from caching
praisonai "Answer questions about the codebase" \
  --prompt-caching --llm anthropic/claude-sonnet-4-20250514

Document Analysis

# Repeated analysis of same document
praisonai "Find security issues in this code..." \
  --prompt-caching --llm anthropic/claude-sonnet-4-20250514

Multi-Query Session

# Multiple queries with same context
praisonai "Query 1..." --prompt-caching --llm anthropic/claude-sonnet-4-20250514
praisonai "Query 2..." --prompt-caching --llm anthropic/claude-sonnet-4-20250514
praisonai "Query 3..." --prompt-caching --llm anthropic/claude-sonnet-4-20250514

Programmatic Usage

from praisonaiagents import Agent

agent = Agent(
    instructions="You are an AI assistant..." * 50,  # Long system prompt
    llm="anthropic/claude-sonnet-4-20250514",
    prompt_caching=True
)

# First call caches the prompt
result1 = agent.start("Question 1")

# Subsequent calls use cached prompt
result2 = agent.start("Question 2")  # Reduced cost
result3 = agent.start("Question 3")  # Reduced cost

Best Practices

Use prompt caching when you have long system prompts or make repeated calls with the same context.
Caching is most effective for stable prompts. Frequently changing prompts wonโ€™t benefit from caching.
DoDonโ€™t
Use for long system promptsUse for short prompts
Use for repeated queriesUse for one-off queries
Combine with --metrics to track savingsIgnore cost monitoring
Use stable instructionsChange prompts frequently

Cache Behavior

ProviderCache DurationCache Scope
OpenAIAutomaticPer-request
Anthropic5 minutesPer-session
BedrockConfigurablePer-session
Deepseek5 minutesPer-session