---
title: Purge Cached Content
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/python)

[Cache](https://developers.cloudflare.com/api/python/resources/cache)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Purge Cached Content

cache.purge(CachePurgeParams\*\*kwargs) -> [CachePurgeResponse](<https://developers.cloudflare.com/api/python/resources/cache#(resource)%20cache%20%3E%20(model)%20cache_purge_response%20%3E%20(schema)>)

POST/zones/{zone\_id}/purge\_cache

Deletes cached content in every Cloudflare data center and cache tier, including Cache Reserve. The next request for purged content is a cache `MISS`: Cloudflare fetches the full response from your origin and caches it again. Cloudflare does not serve purged content from cache again, even if your origin is unavailable.

To keep content cached and have Cloudflare revalidate it with your origin instead, use `POST /zones/{zone_id}/invalidate_cache`.

### Choose what to purge

Send one of these fields in the request body:

- `files`: specific URLs. If your cache key includes request headers, send each URL with the header values it was cached with.
- `tags`: all content whose `Cache-Tag` response header contains one of the tags.
- `hosts`: all content cached for the hostnames.
- `prefixes`: all content whose URL starts with one of the prefixes.
- `purge_everything`: all cached content in the zone.

### Check the result

A `200` response with `success: true` means Cloudflare accepted the request. It does not confirm that any content was cached or removed. To check, request a purged URL and confirm that the `CF-Cache-Status` response header is `MISS`.

### Availability and limits

Rate limits and the number of items you can send in one request depend on your plan. See [Purge cache: availability and limits](https://developers.cloudflare.com/cache/how-to/purge-cache/#availability-and-limits).

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`Cache Purge`

##### ParametersExpand Collapse

zone\_id: str

maxLength32

[Link to this property](<#(resource)%20cache%20%3E%20(method)%20purge%20%3E%20(params)%200%20%3E%20(param)%20zone_id%20%3E%20(schema)>)

tags: Optional\[Sequence\[str]]

Cache tags. Targets all content whose `Cache-Tag` response header contains at least one of these tags. See [Purge cache by cache-tags](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/).

[Link to this property](<#(resource)%20cache%20%3E%20(method)%20purge%20%3E%20(params)%200%20%3E%20(param)%20tags%20%3E%20(schema)>)

##### ReturnsExpand Collapse

<details>

<summary>

class CachePurgeResponse: …

</summary>

id: str

maxLength32

<a href="#(resource)%20cache%20%3E%20(model)%20cache_purge_response%20%3E%20(schema)%20%3E%20(property)%20id">Link to this property</a>

</details>

[Link to this property](<#(resource)%20cache%20%3E%20(model)%20cache_purge_response%20%3E%20(schema)>)

### Purge Cached Content

Python

HTTPTypeScriptPythonGoTerraform

```
import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
response = client.cache.purge(
    zone_id="023e105f4ecef8ad9ca31a8372d0c353",
    tags=["product-1234", "homepage"],
)
print(response.id)
```

200 example

4XX example

4XX example

```
{
  "errors": [],
  "messages": [],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353"
  },
  "success": true
}
```

```
{
  "errors": [
    {
      "code": 1092,
      "message": "Request cannot contain \"purge_everything\" and any of \"files\", \"tags\", \"hosts\" or \"prefixes\""
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
```

```
{
  "errors": [
    {
      "code": 1134,
      "message": "Unable to purge, rate limit reached. Please wait and consider throttling your request speed"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
```

##### Returns Examples

200 example

4XX example

4XX example

```
{
  "errors": [],
  "messages": [],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353"
  },
  "success": true
}
```

```
{
  "errors": [
    {
      "code": 1092,
      "message": "Request cannot contain \"purge_everything\" and any of \"files\", \"tags\", \"hosts\" or \"prefixes\""
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
```

```
{
  "errors": [
    {
      "code": 1134,
      "message": "Unable to purge, rate limit reached. Please wait and consider throttling your request speed"
    }
  ],
  "messages": [],
  "result": null,
  "success": false
}
```