---
title: Purge Cached Content by Environment
---

[Skip to content](#_top)

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

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

Copy Markdown

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

---

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

# Purge Cached Content by Environment

client.cache.purgeEnvironment(stringenvironmentID, CachePurgeEnvironmentParamsparams, RequestOptionsoptions?): [CachePurgeEnvironmentResponse](<https://developers.cloudflare.com/api/typescript/resources/cache#(resource)%20cache%20%3E%20(model)%20cache_purge_environment_response%20%3E%20(schema)>) {id } | null

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

Deletes cached content for one environment of the zone. Content cached for the zone’s other environments, including production, is not affected. Otherwise this works like `POST /zones/{zone_id}/purge_cache`: the next request for purged content is a cache `MISS`, and the request body takes the same fields.

Environments are part of [Version Management](https://developers.cloudflare.com/version-management/). To keep content cached and have Cloudflare revalidate it instead, use `POST /zones/{zone_id}/environments/{environment_id}/invalidate_cache`.

Purging by URL (`files`) does not work for environments that select requests by IP address, country, ASN, or threat score, and fails with error `1136`. Use `tags`, `hosts`, `prefixes`, or `purge_everything` for those environments.

### 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

environmentID: string

maxLength32

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

<details>

<summary>

CachePurgeEnvironmentParams = CachePurgeFlexPurgeByTags| CachePurgeFlexPurgeByHostnames| CachePurgeFlexPurgeByPrefixes| 3 more

</summary>

<details>

<summary>

CachePurgeEnvironmentParamsBase {zone\_id, tags }

</summary>

zone\_id: string

Path param: The zone ID.

maxLength32

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%200%20%3E%20(param)%20zone_id">Link to this property</a>

tags?: Array&lt;string&gt;

Body param: Cache tags. Targets all content whose <code>Cache-Tag</code> response header contains at least one of these tags. See <a href="https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/">Purge cache by cache-tags</a>.

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%200%20%3E%20(param)%20tags">Link to this property</a>

</details>

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment.typescript.base_params">Link to this property</a>

CachePurgeFlexPurgeByTags extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%200">Link to this property</a>

CachePurgeFlexPurgeByHostnames extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%201">Link to this property</a>

CachePurgeFlexPurgeByPrefixes extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%202">Link to this property</a>

CachePurgeEverything extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%203">Link to this property</a>

CachePurgeSingleFile extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%204">Link to this property</a>

CachePurgeSingleFileWithURLAndHeaders extends CachePurgeEnvironmentParamsBase {zone\_id, tags }

<a href="#(resource)%20cache%20%3E%20(method)%20purge_environment%20%3E%20(params)%205">Link to this property</a>

</details>

[Link to this property](<#(resource)%20cache%20%3E%20(method)%20purge_environment.typescript.params>)

##### ReturnsExpand Collapse

<details>

<summary>

CachePurgeEnvironmentResponse {id }

</summary>

id: string

maxLength32

<a href="#(resource)%20cache%20%3E%20(model)%20cache_purge_environment_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_environment_response%20%3E%20(schema)>)

### Purge Cached Content by Environment

TypeScript

HTTPTypeScriptPythonGoTerraform

```
import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const response = await client.cache.purgeEnvironment('023e105f4ecef8ad9ca31a8372d0c353', {
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  tags: ['product-1234', 'homepage'],
});

console.log(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
}
```