# Response Caching (/models/providers/native/anthropic/usage/cache-response)



Response caching allows you to cache model responses, which can significantly improve response times and reduce API costs during development and testing.

<Note>
  For a detailed overview of response caching, see [Response Caching](/models/cache-response).
</Note>

<Note>
  This is different from Anthropic's prompt caching feature. Response caching caches the entire model response, while [prompt caching](/models/providers/native/anthropic/usage/prompt-caching) caches the system prompt to reduce processing time.
</Note>

## Basic Usage [#basic-usage]

Enable caching by setting `cache_response=True` when initializing the model. The first call will hit the API and cache the response, while subsequent identical calls will return the cached result.

```python title="cache_model_response.py"
import time

from agno.agent import Agent
from agno.models.anthropic import Claude

agent = Agent(model=Claude(id="claude-sonnet-4-5", cache_response=True))

# Run the same query twice to demonstrate caching
for i in range(1, 3):
    print(f"\n{'=' * 60}")
    print(
        f"Run {i}: {'Cache Miss (First Request)' if i == 1 else 'Cache Hit (Cached Response)'}"
    )
    print(f"{'=' * 60}\n")

    response = agent.run(
        "Write me a short story about a cat that can talk and solve problems."
    )
    print(response.content)
    print(f"\n Elapsed time: {response.metrics.duration:.3f}s")

    # Small delay between iterations for clarity
    if i == 1:
        time.sleep(0.5)
```

## Usage [#usage]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

  <Step title="Set your API key">
    ```bash
    export ANTHROPIC_API_KEY=xxx
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash
    uv pip install -U anthropic agno
    ```
  </Step>

  <Step title="Run Agent">
    ```bash
    python cache_model_response.py
    ```
  </Step>
</Steps>
