> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get secured API key remaining validity

> Retrieve the remaining validity of a secured API key in seconds.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Retrieve remaining validity for secured API key" href="/doc/libraries/sdk/methods/search/get-remaining-validity" />

**Required ACL:** `Any secured API key`

This method takes a secured API key as a parameter and returns the amount of seconds left until the API key's `validUntil` field expires.
If the key is no longer valid, the method returns a negative number indicating the amount of seconds passed since the key expired.

If the API key has no `validUntil` restriction, this method raises an exception or an error depending on your client.

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  var remainingValidity = client.GetSecuredApiKeyRemainingValidity("YourSecuredAPIkey");
  ```

  ```go Go theme={"system"}
  validity, err := client.GetSecuredAPIKeyRemainingValidity("YourSecuredAPIkey")
  ```

  ```java Java theme={"system"}
  Duration remainingValidity = searchClient.getSecuredApiKeyRemainingValidity("YourSecuredAPIkey");
  ```

  ```js JavaScript theme={"system"}
  const remainingValidity = client.getSecuredApiKeyRemainingValidity('YourSecuredAPIkey');
  ```

  ```kotlin Kotlin theme={"system"}
  val remainingValidity = APIKey("YourSecuredAPIkey").getSecuredApiKeyRemainingValidity()
  ```

  ```php PHP theme={"system"}
  $remainingValidity = SearchClient::getSecuredApiKeyRemainingValidity('YourSecuredAPIkey');
  ```

  ```python Python theme={"system"}
  remaining_validity = SearchClient.get_secured_api_key_remaining_validity('YourSecuredAPIkey')
  ```

  ```ruby Ruby theme={"system"}
  remaining_validity = Algolia::Search::Client.get_secured_api_key_remaining_validity('YourSecuredAPIkey')
  ```

  ```scala Scala theme={"system"}
  val remainingValidity = client.getSecuredApiKeyRemainingValidity("YourSecuredAPIkey")
  ```

  ```swift Swift theme={"system"}
  let remainingValidity = client.getSecuredApiKeyRemainingValidity("YourSecuredAPIkey")
  ```
</CodeGroup>

## Parameters

<ParamField body="apiKey" type="string" required>
  Secured API key to check.
</ParamField>

## Response

<ResponseField name="remaining" type="integer">
  The number of seconds left until the API key expires.
  If the key is no longer valid, the method returns a negative number indicating the amount of seconds passed since the key expired.

  If the API key has no `validUntil` restriction,
  this method raises an exception or an error depending on the API client.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
15
```
