# Ideal Postcodes .NET SDK

[`IdealPostcodes`](https://www.nuget.org/packages/IdealPostcodes) calls the Ideal Postcodes UK address API from C#, with a typed `…Async` method for each operation. It runs on .NET 8 or later, and on .NET Framework 4.6.2 or later through `netstandard2.0`.

Use the `ak_test` key for limited testing. It is capped at 5 requests per day. A new account comes with a free test balance for fuller testing.

```bash
dotnet add package IdealPostcodes
```

Program.cscsharp

```csharp
using IdealPostcodes;

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

var response = await client.FindAddressAsync(new FindAddressParams { Query = "9 Malyons Road" });

foreach (var hit in response.Result.Hits)
{
    Console.WriteLine(hit.Suggestion);
}
```

Each API operation is one method on the client, named from its operation ID, such as `PostcodesAsync()` or `FindAddressAsync()`. Every method returns a class built from the API response, with PascalCase properties.

## Address data

UK addresses come from Royal Mail's Postcode Address File (PAF) and Ordnance Survey AddressBase, depending on the datasets on your key. Each address carries a `Dataset` property naming its source, such as `paf` or `abp`. Its `Native` record holds the raw fields from that source.

## Features

* **Typed requests and responses.** Query parameters and request bodies are classes, with required fields as constructor arguments. Every dataset's native record has its own class, from `PafAddress` to `UspsAddress`.
* **Generated from the OpenAPI spec.** Methods, parameters and response classes come from the contract the API reference is built from.
* **Every current API operation.** Address search, [postcode lookup](/docs/sdks/dotnet/postcode-lookup.md), [UPRN lookup](/docs/sdks/dotnet/uprn-lookup.md), [autocomplete](/docs/sdks/dotnet/autocomplete.md), [address cleanse](/docs/sdks/dotnet/address-cleanse.md), places, [email](/docs/sdks/dotnet/email-validation.md) and [phone validation](/docs/sdks/dotnet/phone-validation.md), plus [key](/docs/sdks/dotnet/keys.md), [licensee](/docs/sdks/dotnet/licensees.md) and configuration management. Each one has its own [reference page](/docs/sdks/dotnet/endpoints.md).
* **Fits your app.** Pass your own `HttpClient`, register the client with `IHttpClientFactory` and mock `IIdealPostcodesClient` in tests. Every method takes a `CancellationToken`. The source-generated JSON context needs no reflection, so the SDK works with trimming and Native AOT.

## Coding agents

* **Agent skill.** `npx skills add ideal-postcodes/skills` installs the `ideal-postcodes-dotnet-sdk` skill, built from these pages.
* **[Endpoints](/docs/sdks/dotnet/endpoints.md).** Every operation, grouped by API area, with its parameters, response class and a tested example.
* **Markdown pages.** Add `.md` to any page URL for plain markdown, such as [`/docs/sdks/dotnet/errors.md`](/docs/sdks/dotnet/errors.md).
* **[llms.txt](https://docs.ideal-postcodes.co.uk/llms.txt).** An index of every page on this site.
* **[OpenAPI spec](https://openapi.ideal-postcodes.co.uk/openapi.json).** The API contract the SDK is generated from.
* **[Build with AI](/docs/guides/llms.md).** Every asset for AI agents.

## Authentication

Pass your API key to the `IdealPostcodesClient` constructor. Key, licensee and configuration operations also need a Management Key, passed as the second argument. Keep the Management Key on your server. See [setup](/docs/sdks/dotnet/setup.md).

## Errors

An HTTP error throws `ApiException` with the HTTP status and the API error code and message. Every exception the SDK defines derives from `IdealPostcodesException`. A failed connection throws `HttpRequestException`, as any `HttpClient` call does. See [error handling](/docs/sdks/dotnet/errors.md).
