Purge cache
post
https://api.imagekit.io
/v1/files/purge
Purge cache API

Response structure and status code

In case of error, you will get an error code along with the error message. On success, you will receive a 200 status code with the request ID returned in the JSON-encoded response body.
requestId can be used to fetch the status of submitted purge request.

Purge Cache for Multiple Files

You can purge the cache for multiple files within a directory by appending a wildcard at the end of the URL, only if ANY ONE of the following conditions are met:
    1.
    The path consists of at least two levels of nesting: The path of the directory, excluding your imagekitId and URL pattern, contains at least two levels of nesting, starting from the root as shown below:
    https://ik.imagekit.io/IMAGEKIT_ID/PATTERN/LEVEL_1/LEVEL_2*
    https://ik.imagekit.io/IMAGEKIT_ID/PATTERN/LEVEL_1* For example, the path /images/upload* is valid, but /images* is not.\
    2.
    The path length is at least 15 characters: The path of the directory, excluding your imagekitId and URL pattern, is at least 15 characters in length, as shown below:
    https://ik.imagekit.io/IMAGEKIT_ID/PATTERN/FIFTEEN_CHARACTERS* However, if the first condition is met, i.e. the path consists of at least two levels of nesting, then it need not be 15 characters long.\
    3.
    The path is a complete file path: The path specified is a complete path pointing to a file, with the file extension present at the end of the path, as shown below:
    https://ik.imagekit.io/IMAGEKIT_ID/PATTERN/FILE.EXT* For example, the path /sample.jpg* is valid, despite not being 15 characters long, or having two levels of nesting.
Note that the wildcard can only be appended at the end of a URL. Wildcards within the path are not supported. i.e. /folder/*/sample.jpg is an invalid path.
The following paths are unconditionally not supported when using a wildcard. Please reach out to us at [email protected] if you need to purge the following patterns.
    media/catalog/*
    s/files/*

Limitations

Purge API has the following limitations:
    An account can issue a maximum of 1000 purge requests in a month. Please reach out to us at [email protected] if you need to increase this limit.
    Note that the wildcard can only be appended at the end of a URL. Wildcards within the path are not supported. i.e. /folder/*/sample.jpg is an invalid path. Please reach out to us at [email protected] if you need to purge all images on a specific pattern not supported through the API.

Examples

Here are some example requests to understand the API usage.
cURL
Node.js
Python
PHP
Java
Ruby
1
curl -X POST "https://api.imagekit.io/v1/files/purge" \
2
-H "content-type: application/json" \
3
-u your_private_key: -d'
4
{
5
"url": "https://ik.imagekit.io/your_imagekit_id/default-image.jpg"
6
}
7
'
Copied!
1
var ImageKit = require("imagekit");
2
3
var imagekit = new ImageKit({
4
publicKey : "your_public_api_key",
5
privateKey : "your_private_api_key",
6
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
7
});
8
9
imagekit.purgeCache("https://ik.imagekit.io/your_imagekit_id/default-image.jpg", function(error, result) {
10
if(error) console.log(error);
11
else console.log(result);
12
});
Copied!
1
from imagekitio import ImageKit
2
3
imagekit = ImageKit(
4
public_key='your_public_api_key',
5
private_key='your_private_api_key',
6
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
7
)
8
9
purge_cache = imagekit.purge_cache(file_url="https://ik.imagekit.io/your_imagekit_id/default-image.jpg")
10
11
print("Purge cache-", purge_cache)
Copied!
1
use ImageKit\ImageKit;
2
3
$public_key = "your_public_api_key";
4
$your_private_key = "your_private_api_key";
5
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
6
7
$imageKit = new ImageKit(
8
$public_key,
9
$your_private_key,
10
$url_end_point
11
);
12
13
$purgeCache = $imageKit->purgeCacheApi(array(
14
"url" => "https://ik.imagekit.io/your_imagekit_id/default-image.jpg"
15
));
16
17
echo("File details : " . json_encode($purgeCache));
Copied!
1
ResultCache result=ImageKit.getInstance().purgeCache("https://ik.imagekit.io/your_imagekit_id/default-image.jpg");
Copied!
1
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")
2
purge_cache = imagekitio.purge_file_cache("https://ik.imagekit.io/your_imagekit_id/default-image.jpg")
Copied!
Last modified 3d ago