# AddressZen PHP SDK

[`addresszen/sdk`](https://packagist.org/packages/addresszen/sdk) calls the AddressZen API from PHP 8.2 or later, with a typed method for each operation over any PSR-18 HTTP client.

```bash
composer require addresszen/sdk
```

verify.phpphp

```php
use AddressZen\AddressZen;
use AddressZen\Types\UsaVerifyMatch;

$client = AddressZen::client('ak_test');
$result = $client->addressVerify(['query' => '1010 Cauthen Ln, Alamogordo, NM 88310'])->result;

if ($result instanceof UsaVerifyMatch) {
    echo $result->addressLineOne, ', ', $result->city, ', ', $result->state, ' ', $result->zipCode, PHP_EOL;
}
```

Each API operation is one method on the client, named from its operation ID, such as `addressVerify()` or `findAddress()`. Every method returns a read-only object built from the API response.

## Features

Every operation in the API has a method. The ones most integrations need have a guide:

* [Address verification](/docs/sdks/php/address-verify.md): correct and standardize a US address against USPS data
* [Autocomplete](/docs/sdks/php/autocomplete.md): suggest addresses as the user types, in the US and other countries
* [Email validation](/docs/sdks/php/email-validation.md): check that an address can receive mail
* [Phone validation](/docs/sdks/php/phone-validation.md): check a number from any country and format it
* [API keys](/docs/sdks/php/keys.md) and [licensees](/docs/sdks/php/licensees.md): balances, limits, usage and sub-licensing

Place search and saved configs are on the [endpoint pages](/docs/sdks/php/endpoints.md), one per method.

## Why the SDK

* **Any HTTP client.** The SDK sends requests through the PSR-18 client already in your project, found by `php-http/discovery`. Guzzle and Symfony HttpClient both work. There is no bundled transport to configure.
* **Generated from the OpenAPI spec.** Every response is a typed, read-only object. Every dataset's native record has its own class, from `UspsAddress` to `PafAddress`.
* **Static analysis friendly.** Parameters are PHPStan array shapes, enums are literal types and the source passes PHPStan at its strictest level.
* **No hidden retries.** A billable lookup repeats only when your code repeats it.
* **Framework packages.** [Symfony](/docs/sdks/php/symfony.md) and [Laravel](/docs/sdks/php/laravel.md) packages configure the client from your application config.

## Coding agents

* **Agent skill.** `npx skills add addresszen/skills` installs the `azn-php-sdk` skill, built from these pages.
* **[Endpoints](/docs/sdks/php/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/php/errors.md`](/docs/sdks/php/errors.md).
* **[llms.txt](https://docs.addresszen.com/llms.txt).** An index of every page on this site.
* **[OpenAPI spec](https://openapi.addresszen.com/openapi.json).** The API contract the SDK is generated from.

## Authenticate

Pass your API key to `AddressZen::client()`. 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/php/setup.md).

## Errors

An HTTP error throws `ApiException` with the HTTP status and the API error code and message. A failed connection throws `TransporterException`. Both implement `AddressZenException`, so one catch covers the SDK. See [error handling](/docs/sdks/php/errors.md).
