# Ideal Postcodes Go SDK

[`go.ideal-postcodes.co.uk/sdk`](https://github.com/ideal-postcodes/go-sdk) calls the Ideal Postcodes UK address API from Go 1.26 or later, with a typed method for each operation and no dependencies beyond the standard library.

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
go get go.ideal-postcodes.co.uk/sdk
```

main.gogo

```go
package main

import (
	"context"
	"fmt"
	"log"

	idealpostcodes "go.ideal-postcodes.co.uk/sdk"
)

func main() {
	client := idealpostcodes.NewClient("ak_test")
	res, err := client.FindAddress(context.Background(), &idealpostcodes.FindAddressParams{
		Query: "9 Malyons Road",
	})
	if err != nil {
		log.Fatal(err)
	}
	for _, hit := range res.Result.Hits {
		if s := hit.AsUkAddressSuggestion(); s != nil {
			fmt.Println(s.Suggestion)
		}
	}
}
```

The package name is `idealpostcodes`; import it under that name, as above. Each API operation is one method on the client, named from its operation ID, such as `Postcodes()` or `FindAddress()`. Every method takes a `context.Context` first and returns a typed response and an `error`.

## 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` field naming its source, such as `paf` or `abp`. Its `Native` record holds the raw fields from that source.

## Why the SDK

* **Standard library only.** Requests go through `net/http`. Pass your own `*http.Client` for timeouts, proxies or tracing. There is nothing else to install or keep patched.
* **Generated from the OpenAPI spec.** Every response is a struct. Every dataset's native record has its own type, from `PafAddress` to `UspsAddress`.
* **Responses never fail on shape.** A field the API adds, a value outside a known set or a dataset the SDK has not seen yet decodes without error. See [responses](/docs/sdks/go/responses.md).
* **Every current API operation.** Address search, [postcode lookup](/docs/sdks/go/postcode-lookup.md), [UPRN lookup](/docs/sdks/go/uprn-lookup.md), [autocomplete](/docs/sdks/go/autocomplete.md), [address cleanse](/docs/sdks/go/address-cleanse.md), places, [email](/docs/sdks/go/email-validation.md) and [phone validation](/docs/sdks/go/phone-validation.md), plus [key](/docs/sdks/go/keys.md), [licensee](/docs/sdks/go/licensees.md) and configuration management. Each one has its own [reference page](/docs/sdks/go/endpoints.md).

## Coding agents

* **Agent skill.** `npx skills add ideal-postcodes/skills` installs the `ideal-postcodes-go-sdk` skill, built from these pages.
* **[Endpoints](/docs/sdks/go/endpoints.md).** Every operation, grouped by API area, with its signature, parameters, response type and a tested example.
* **Markdown pages.** Add `.md` to any page URL for plain markdown, such as [`/docs/sdks/go/errors.md`](/docs/sdks/go/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 `NewClient()`. Key, licensee and configuration operations also need a Management Key, passed with `WithManagementKey()`. Keep the Management Key on your server. See [setup](/docs/sdks/go/setup.md).

## Errors

An HTTP error returns `*idealpostcodes.APIError` with the HTTP status and the API error code and message. Match it with `errors.AsType`. A failed connection returns the `net/http` error, wrapped. See [error handling](/docs/sdks/go/errors.md).
