---
type: api
title: Clear the API key cache
description: Evict a subset of all entries from the API key cache.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-security-clear-api-key-cache
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-security-clear-api-key-cache
products:
  - Elasticsearch
---

# Clear the API key cache

Availability: Generally available since 7.10

## Paths

- `POST` `/_security/api_key/{ids}/_clear_cache`

#### Path parameters

- `ids` (union string | string[]) — required
  Comma-separated list of API key IDs to evict from the API key cache.
To evict all API keys, use `*`.
Does not support other wildcard patterns.

## Description

Evict a subset of all entries from the API key cache.
The cache is also automatically cleared on state changes of the security index.

## Required authorization

- Cluster privileges: `manage_security`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Response

`application/json`

- `_nodes` (object)
  - `failures` (object[])
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` (object) — recursive
      Same fields as `failures` in `_nodes`
    - `root_cause` (object[]) — recursive
      Same fields as `failures` in `_nodes`
    - `suppressed` (object[]) — recursive
      Same fields as `failures` in `_nodes`
  - `total` (number)
    Total number of nodes selected by the request.
  - `successful` (number)
    Number of nodes that responded successfully to the request.
  - `failed` (number)
    Number of nodes that rejected the request or failed to respond. If this value is not 0, a reason for the rejection or failure is included in the response.
- `cluster_name` (string)
- `nodes` (map string to object)
  Map values (object)
  - `name` (string)
## Code examples

#### Console

```console
POST /_security/api_key/yVGMr3QByxdh1MSaicYx/_clear_cache
```

#### JavaScript

```javascript
const response = await client.security.clearApiKeyCache({
  ids: "yVGMr3QByxdh1MSaicYx",
});
```

#### Python

```python
resp = client.security.clear_api_key_cache(
    ids="yVGMr3QByxdh1MSaicYx",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_security/api_key/yVGMr3QByxdh1MSaicYx/_clear_cache" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().clearApiKeyCache(c -> c
    .ids("yVGMr3QByxdh1MSaicYx")
);
```

#### C#

```c#
var response = await client.Security.ClearApiKeyCacheAsync(ids: new[] { "yVGMr3QByxdh1MSaicYx" });
```

#### PHP

```php
$resp = $client->security()->clearApiKeyCache([
    "ids" => "yVGMr3QByxdh1MSaicYx",
]);
```

#### Ruby

```ruby
response = client.security.clear_api_key_cache(
  ids: "yVGMr3QByxdh1MSaicYx"
)
```

