# `client.KeyAvailabilityAsync()`

Availability

Returns public information on an API Key: whether it can be used right now (`available`), the search contexts the key is licensed for (`contexts`) and the context that best matches the caller's IP address (`context`).

The endpoint accepts API Keys (beginning `ak_`) and sub-licensed keys (beginning `sl_`), and needs no Management Key.

A key that exists but cannot be used, because it has no lookups left or has breached a limit, returns `200` with `"available": false`. An unknown or malformed key returns an error.

Supply a valid Management Key and the endpoint returns the key's private details instead, as `GET /keys/{key}/details` does. A Management Key that does not own the key is rejected.

## Endpoint

`GET /keys/{key}`

See the [API reference](/docs/api/key-availability.md) for this endpoint.

## Signature

```csharp
Task<ApiKeyResponse> KeyAvailabilityAsync(string key, CancellationToken cancellationToken = default)
```

## Arguments

| Name                | Type                | Required | Description          |
| ------------------- | ------------------- | -------- | -------------------- |
| `key`               | `string`            | yes      | API Key              |
| `cancellationToken` | `CancellationToken` | no       | Cancels the request. |

## Query Parameters

*None.*

## Response

`ApiKeyResponse`. Fields are properties in PascalCase, such as `response.Result`; fields this SDK version does not know are kept in `AdditionalProperties`. See [responses](/docs/sdks/dotnet/responses.md).

## Errors

An HTTP error throws `ApiException` with the `StatusCode`, the API error `Code` and the raw `Body`. A success response whose body cannot be read throws `UnserializableResponseException`. Network failures and cancellation throw `HttpClient`'s own `HttpRequestException` and `OperationCanceledException`. See [error handling](/docs/sdks/dotnet/errors.md).

## Example

key-availability.cscsharp

```csharp
using IdealPostcodes;

using var client = new IdealPostcodesClient("ak_test");

var response = await client.KeyAvailabilityAsync("ak_test");

Console.WriteLine($"Available: {response.Result.Available}");
Console.WriteLine($"Context: {response.Result.Context}");
```
