> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Response Caching

> Cache model responses to reduce API calls and costs.

> [!NOTE]
>
> For a conceptual overview of response caching, see [Response Caching](https://agno-v2.mintlify.site/models/cache-response.md).

Response caching stores model responses locally, reducing response times and API costs during development and testing.

## 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 cache_model_response.py theme={null}
import time

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(model=OpenAIChat(id="gpt-4o", 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

<Snippet file="create-venv-step.mdx" />

**1. Set your API key**

```bash theme={null}
export OPENAI_API_KEY=xxx
```

**2. Install dependencies**

```bash theme={null}
uv pip install -U openai agno
```

**3. Run Agent**

```bash theme={null}
python cache_model_response.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.