Metadata-Version: 2.4
Name: open-payments-sdk
Version: 1.0.0
Summary: Synchronous and asynchronous Python SDK for Open Payments
License-Expression: Apache-2.0
License-File: LICENSE
Author: Yiannis Giannelos
Author-email: johngiannelos@gmail.com
Requires-Python: >=3.10
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Dist: anyio (>=4.16.0,<5.0.0)
Requires-Dist: cryptography (>=50.0.2,<51.0.0)
Requires-Dist: http-message-signatures (>=2.0.1,<3.0.0)
Requires-Dist: http-sf (>=1.0.7,<1.1.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
Requires-Dist: python-ulid[pydantic] (>=3.1.0,<4.0.0)
Requires-Dist: rfc3986-validator (>=0.1.1,<0.2.0)
Project-URL: Documentation, https://github.com/interledger/open-payments-python-sdk#readme
Project-URL: Issues, https://github.com/interledger/open-payments-python-sdk/issues
Project-URL: Repository, https://github.com/interledger/open-payments-python-sdk
Description-Content-Type: text/markdown

# Python Open Payments SDK

Synchronous and asynchronous Python clients for Open Payments, with typed request and response models.

## Open Payments

Open Payments is an open API standard that can be implemented by account servicing entities (e.g. banks, digital wallet providers, and mobile money providers) to facilitate interoperability in the setup and completion of payments for different use cases including:

- Web Monetization
- Tipping/Donations (low value/low friction)
- eCommerce checkout
- P2P transfers
- Subscriptions
- Invoice Payments

An Open Payments server runs two sub-systems, a resource server which exposes APIs for performing functions against the underlying accounts and authorization server which exposes APIs compliant with the GNAP standard for getting grants to access the resource server APIs.

## Cryptography platform support

The SDK requires cryptography 50.x. Upstream cryptography no longer supports Intel macOS or 32-bit Windows; see its [platform changes](https://cryptography.io/en/50.0.2/changelog/).

## Installation

The distribution is named `open-payments-sdk`; Python imports use `open_payments_sdk`. The SDK requires Python 3.10 or newer. CI tests Python 3.10–3.13 on Ubuntu and Windows; the cryptography platform restrictions above also apply.

Install from this repository using a Python 3.10+ interpreter:

```bash
git clone https://github.com/interledger/open-payments-python-sdk.git
cd open-payments-python-sdk
python -m venv .venv
```

Activate the virtual environment on macOS or Linux:

```bash
source .venv/bin/activate
```

Or in Windows PowerShell:

```powershell
.\.venv\Scripts\Activate.ps1
```

From the repository root, install the SDK into that environment:

```bash
python -m pip install .
```

This builds and installs the package with its runtime dependencies. Poetry manages the development tools and optional live-test, browser, example and notebook tools described below.

## Local development

Install [Poetry](https://python-poetry.org/docs/#installation), then select your Python 3.10+ interpreter and install the locked development dependencies from the repository root:

```bash
poetry env use python
poetry install
```

Poetry creates or uses an isolated environment. Run project commands through `poetry run`; CI uses Poetry 2.5.2. See [managing environments](https://python-poetry.org/docs/managing-environments/) to select a different interpreter.

See the [1.0.0 release notes](https://github.com/interledger/open-payments-python-sdk/blob/main/CHANGELOG.md) and [release preparation guide](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/releasing.md) for compatibility notes, artifact checks and maintainer publication steps.

## Versioning and compatibility

Starting with 1.0.0, the documented clients, resource methods, request and response models, errors, helpers and payment workflows form the supported public API, including the compatibility names listed in the [migration guide](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/migration.md). Incompatible changes to this API require a major version; compatible additions use minor versions, and fixes use patch versions. Internal implementation details are outside this compatibility policy.

Validation fixes can reject input or provider responses that violate the pinned Open Payments contracts, even if an earlier SDK version accepted them. Release notes describe these corrections and any required integration changes. Provider behavior and availability remain separate from SDK API compatibility; see the [dated live verification record](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/live-verification.md).

## Specifications

The SDK 1.0.0 contract baseline is pinned to Open Payments v1.5.1 with release, commit and SHA-256 provenance. Run `poetry run python scripts/sync_specs.py --check` to verify the local files without network access. See [specification synchronization](https://github.com/interledger/open-payments-python-sdk/blob/main/spec/README.md) for explicit restore/update commands.

Updating an existing integration? The [migration guide](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/migration.md) maps supported helper names to URL-based operations and explains return-shape, validation, client-lifetime and saved-state compatibility.

## Running tests

The default suite is offline and blocks real network requests. It uses deterministic test keys and mock HTTP responses, without reading live credentials or requiring a browser:

```bash
poetry install
poetry run python -m pytest -ra
```

The offline payment-flow scenarios exercise discovery, incoming-payment and quote creation, interaction callbacks, JSON state restoration and outgoing creation with distinct sender and recipient assets. They cover approved, pending, denied, expired and uncertain completion outcomes, reject replay after recovery, and exercise resource reconciliation, listing and token management. Run them without provider credentials or browser dependencies:

```bash
poetry run python -m pytest tests/process/test_payment_flow.py -ra
```

These scenarios use synthetic HTTP responses and a published callback-hash vector; they provide no evidence of settlement with a live provider.

The [live verification record](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/live-verification.md) documents nine guide scenarios, eleven confirmed test-wallet payments, and the observed resource-server and consent-page limitations. It distinguishes those executions from the offline, API integration and Selenium browser suites.

Live tests use only accounts you configure. Install their optional dependencies, copy `tests/.env.example` to `tests/.env`, and fill in the wallet and registered key values before opting in:

```bash
poetry install --with live
poetry run python -m pytest tests/integration --run-live -ra
```

Browser workflows additionally require Chrome, browser tooling, and configured sender login credentials. They authorize and send a payment between the configured test wallets. Set `TEST_PAYMENT_AMOUNT` to a positive uint64 string in the recipient asset's smallest units. Existing configurations without it still use `TEST_PRODUCT_VALUE * TEST_PRODUCT_VOLUME`.

```bash
poetry install --with live,browser
poetry run python -m pytest tests/process --run-live --run-browser -ra
```

The configured `TEST_REDIRECT_URI` must be served by your test application. The browser scenario initiates once, saves `pending-payment.json` in its pytest temporary directory, closes the first processor, reloads the original state and claims completion before continuing the grant. The callback must match the saved transaction URI and hash context. It respects the continuation wait, stopping with saved state if more than another 60 seconds is needed. It then creates one outgoing payment and uses read-only polling for up to 60 seconds, subject to request timeouts and token expiry, to confirm receipt at the recipient. Sender fees may make sent and debit amounts differ. It also reads/lists the outgoing payment and checks the current grant's spent amounts. The login/consent selectors follow the contributed Rafiki UI; other provider interfaces may need an adapter and have not been verified here.

On confirmed receipt, the scenario cancels its three grants using their latest known continuation credentials. Partial state and an exclusive local completion claim remain available on failure; no payment write is retried and uncertain outcomes do not trigger grant cancellation. Reconcile the saved transaction with the provider before starting another attempt. The local files are test records, not a replacement for the application's durable transaction store.

Tests with missing optional dependencies or configuration report skips. Incoming-payment tests request a grant and create an unfunded resource for each create/get/list/complete scenario, using the configured wallet's assets and an expiry ten minutes ahead. Listing searches at most five pages of 100 payments. Grants are cancelled during teardown, including when a provider requires interaction; such interactive incoming grants report a skip. These tests create provider records but do not send funds.

Grant tests accept approved or pending initial responses and cancel the returned grant. The interaction test requests read-only outgoing access with redirect interaction and checks its initial response without opening a browser. Token management requires a non-interactive issued token: it rotates that token and revokes the replacement at its returned management URI, then cancels the grant. If interaction is required, that case skips after cleanup. These grant tests create no outgoing payment.

Quote create/read tests additionally require the sender's `TEST_BUYER_WALLET`. They create an unfunded incoming payment for the recipient, request a quote for its receive amount, check both wallets' assets and read the full returned quote URL. Both grants are cancelled after the scenario, including after failure or a pending-grant skip. They create no outgoing payment and need no browser login.

The peer-to-peer example uses `poetry install --with examples`. Optional notebook tooling requires Python 3.11.5 or newer so it can use patched dependencies:

```bash
poetry env use python3.12
poetry install --with notebooks
```

On Python versions below 3.11.5, Poetry omits the notebook tooling. The SDK, offline tests, examples, and browser tests continue to support Python 3.10.

## Client quick start

Import client classes from `open_payments_sdk`:

| Operations | Synchronous client | Native async client |
| --- | --- | --- |
| Public wallet metadata, keys and incoming payments | `UnauthenticatedClient` | `AsyncUnauthenticatedClient` |
| Grants, access tokens and authenticated payment operations | `OpenPaymentsClient` | `AsyncOpenPaymentsClient` |

Start with [public discovery](#public-discovery) if you only need public data. For authenticated operations, register an Ed25519 public key with your wallet provider and load its matching unencrypted private PKCS8 PEM. Use the registered public key's `kid` as `keyid`.

This example reads wallet metadata and requests permission to create and read incoming payments. Replace the wallet address and key ID with your registered values, and put your existing private PEM at `privkey.pem`:

```python
from pathlib import Path
from open_payments_sdk import OpenPaymentsClient

wallet_address = "https://wallet.example/alice"
private_key = Path("privkey.pem").read_text(encoding="utf-8")

with OpenPaymentsClient(
    keyid="my-signing-key",
    private_key=private_key,
) as client:
    wallet = client.wallet.get(wallet_address)
    grant = client.grants.request(
        url=str(wallet.authServer),
        grant_request={
            "client": {"walletAddress": str(wallet.id)},
            "access_token": {
                "access": [
                    {
                        "type": "incoming-payment",
                        "actions": ["create", "read"],
                        "identifier": str(wallet.id),
                    }
                ]
            }
        },
    )
```

The wallet read is public; the initial grant request is signed and contains an explicit wallet-address identity object. The response may contain an issued access token or require interaction. Retain its continuation credentials and handle the returned state before creating a payment; see [grant requests](#initial-grant-requests) and [grant continuation](#grant-continuation-and-cancellation). The example requests permissions without creating a payment, and exits the client context to close its owned transport.

For an async application, use `async with AsyncOpenPaymentsClient(...)` and await resource methods; see the [authenticated async example](#authenticated-async-client). Construction itself performs no network requests or key generation. See [client configuration and lifecycle](#client-configuration-and-lifecycle) for transport injection and ownership.

## Ed25519 keys

`KeyManager.generate_key_pair()` retains its existing `KeyPair` result: `private_key_pem` contains PKCS8 PEM and `jwks` contains public keys only. It generates a UUID key ID unless you supply `key_id`. Register the public key with your wallet provider before making authenticated requests.

```python
from open_payments_sdk import KeyManager, key_to_jwk, load_private_key, load_public_key

key_pair = KeyManager().generate_key_pair(key_id="my-signing-key")
private_key = load_private_key(key_pair.private_key_pem, format="pem")
public_jwk = key_to_jwk(private_key, key_id=key_pair.jwks.keys[0].kid)
public_key = load_public_key(public_jwk, format="jwk")
```

Generate keys during key setup and register their public material before use. For later requests, load the existing private PEM as in the quick start. The client accepts `key_pair.private_key_pem` and the matching `key_pair.jwks.keys[0].kid` after registration.

Both loaders require an explicit format and return native `cryptography` Ed25519 keys. The client constructor continues to accept a PEM string. The same loader/conversion methods are available on `KeyManager`, and the existing `load_ed25519_private_key_from_pem()` method remains available.

| `format` | Input |
| --- | --- |
| `"pem"` | PEM text or bytes: one PKCS8 private key or one SPKI public key |
| `"file"` | A filesystem path (`str` or `Path`) to that PEM |
| `"base64"` | Canonical standard Base64 text or bytes encoding that entire PEM, without line wrapping |
| `"jwk"` | One JWK mapping or Pydantic model; decode JSON text first |

For example, load an existing key without generating or replacing it:

```python
from pathlib import Path

private_key = load_private_key(Path("privkey.pem"), format="file")
public_jwk = key_to_jwk(private_key, key_id="my-signing-key")
```

Encrypted private PEM inputs accept `password=b"your-password"` with `"pem"`, `"file"` or `"base64"`. Invalid inputs raise `ValueError`; loaders do not guess formats, select keys from a JWKS, fetch key URLs or create replacement keys. JWK metadata must permit Ed25519 signing/verification; coordinates must be canonical unpadded Base64url. A private JWK needs matching `x` and `d`; a public JWK must omit `d`.

`key_to_jwk()` exports public material by default and adds a `kid` only when supplied. Exporting private `d` requires `include_private=True`. Private fields are hidden from ordinary `KeyPair` and `SellerOpenPaymentAccount` representations and validation-error messages; explicit attribute access and `model_dump()` still include them for application-owned persistence.

Public `Key` and wallet `JsonWebKey` models require `kid`, `alg="EdDSA"`, `kty="OKP"`, `crv="Ed25519"` and a canonical unpadded Base64url `x` encoding 32 bytes. The optional `use` must be `"sig"` when provided; omission stays absent in dumps, and explicit null is invalid. Public models retain additional JSON fields and reject private `d` material. They do not resolve key URLs. `Key` keeps its string metadata, while `JsonWebKey` keeps the existing enum attributes; both serialize the same JSON values and accept each other's models.

Public-model `kid` follows the specification's string contract. Key generation, loading and signing apply the SDK's additional requirement that a supplied signing key ID be nonempty printable ASCII without surrounding whitespace. Normal public-model assignments validate too; Pydantic's trusted-data construction/copy methods bypass field validation, but serialization still blocks private `d` material.

Grant identities, display and finish URIs, listing wallet URIs and payment resource URIs validate complete RFC3986 syntax, including authority, path, query and fragment boundaries. String fields in identities and display metadata retain valid input spelling; native `AnyUrl` values are checked after conversion to their existing normalized spelling. Invalid escapes, unescaped brackets outside IP literals, repeated fragment delimiters and malformed authority fields are rejected. IPv6 literals and properly percent-encoded components remain supported.

## Wallet URLs and payment pointers

The helpers in `open_payments_sdk.utils.urls` validate and convert addresses without making requests:

```python
from open_payments_sdk.utils.urls import (
    normalize_wallet_address,
    resolve_payment_pointer,
    validate_request_url,
)

assert resolve_payment_pointer("$wallet.example") == "https://wallet.example/.well-known/pay"
assert normalize_wallet_address("$wallet.example/alice/") == "https://wallet.example/alice/"
assert normalize_wallet_address("wallet.example/alice") == "https://wallet.example/alice"
assert validate_request_url("http://localhost:3000/alice") == "http://localhost:3000/alice"
```

[Payment-pointer syntax](https://paymentpointers.org/syntax/) requires a leading `$`, a host and an optional path. Conversion always uses HTTPS; an empty path or `/` becomes `/.well-known/pay`. Ports (including `:443` and an empty `:`), credentials, queries and fragments are invalid in pointers. Other paths keep their escaping and trailing slash.

`validate_request_url` requires an absolute HTTP(S) URL with a host, without userinfo or a fragment. Explicit HTTP URLs and ports support development endpoints. Valid string input retains its scheme/host spelling, path escapes and query order, including an empty query marker; HTTPX may apply its own URL normalization when a request is later prepared. `AnyUrl` and `httpx.URL` inputs are checked using their existing normalized spelling. Invalid inputs raise `InputError` with sanitized diagnostics.

`normalize_wallet_address` also accepts the legacy bare host/path form and adds `https://`. Use an explicit scheme for a URL with a port. Bare hosts receive no well-known path fallback. The legacy `paymentsparser.normalise_wallet_address(wallet_address=...)` delegates to the same rules, preserving explicit HTTP URLs and trailing slashes. Conversion does not verify wallet metadata or production wallet-address requirements. Protocol data fields retain their separate URI schema rules. Wallet discovery methods apply these helpers automatically.

`WalletAddress` metadata requires `id`, `assetCode`, `assetScale`, `authServer` and `resourceServer`. `publicName` is an optional string, including an empty string; omission leaves the attribute as `None` and omits it from serialization, while an explicit null is invalid. URI fields validate complete RFC3986 syntax and keep their existing `AnyUrl` attribute types and normalization. These data fields follow the pinned schema's URI contract; request URL helpers use a separate HTTP(S) policy. Provider extensions accept finite JSON values and retain nested nulls. The optional `cardService` extension identifies a card-service endpoint. It is supported by the SDK but is not a defined property in the pinned Open Payments v1.5.1 wallet schema. It remains a nullable URI with its existing `None` default and serialization behavior.

## Public discovery

Use `UnauthenticatedClient` to read wallet metadata, public keys and public incoming payments without a private key, wallet identity or access token. Construction performs no requests or key generation:

```python
from open_payments_sdk import UnauthenticatedClient

with UnauthenticatedClient() as client:
    wallet = client.wallet.get("$wallet.example/alice")
    keys = client.wallet.get_keys(wallet.id)
```

For an incoming payment, pass the complete resource URL returned by the provider:

```python
from open_payments_sdk import UnauthenticatedClient

with UnauthenticatedClient() as client:
    incoming = client.incoming_payments.get(
        "https://resource.example/tenant/incoming-payments/opaque-id"
    )
```

Use `AsyncUnauthenticatedClient` for the same public operations with native async I/O. Await its resource methods, and use `async with` or `await client.aclose()` for cleanup:

```python
from open_payments_sdk import AsyncUnauthenticatedClient

async def public_details():
    async with AsyncUnauthenticatedClient() as client:
        wallet = await client.wallet.get("$wallet.example/alice")
        keys = await client.wallet.get_keys(wallet.id)
        incoming = await client.incoming_payments.get(
            "https://resource.example/tenant/incoming-payments/opaque-id"
        )
        return wallet, keys, incoming
```

The async client supports asyncio and Trio, and accepts `Configuration`, a borrowed `httpx.AsyncClient`, or a caller-owned `AsyncHttpClientProtocol` with synchronous request construction and async sending. Construction performs no I/O or key loading. It snapshots configuration and preserves caller-owned transports when closed. Cached resource methods reject use after closing the facade. Finish active requests before closing, and keep each client within one backend/event loop. Cancellation propagates without retrying a read; owned cleanup follows the async transport rules below.

Public incoming reads return `PublicIncomingPayment` with the required `authServer` and `methods`; `walletAddress` is not required. Resource URLs must be absolute HTTP(S) URLs, including any path prefix and opaque query data. Payment pointers and bare host/path forms are for wallet discovery. Public clients expose `client.incoming_payments.get_public(url)` and the shorter `get(url)`. Authenticated clients also expose unsigned `get_public(url)`, offer signed `get(url, access_token)` and retain `get_incoming_payment(...)`. Public reads use no access token or signature and do not fall back to a signed request.

During [test-wallet verification on 2 December 2026](https://github.com/interledger/open-payments-python-sdk/blob/main/docs/live-verification.md#get-incoming-payment-without-an-access-token), GET incoming payment without an access token returned HTTP 200 with four required response fields missing, causing `ResponseError(reason="validation", status=200)`. GET with an access token authorized for the incoming-payment `read` action validated normally. See the verification record before relying on public incoming-payment reads with that deployment.

Wallet metadata and JWKS operations accept HTTP(S) URLs, payment pointers and the existing bare host/path form. `wallet.get_wallet_address(wallet_address_server_endpoint=...)` remains available, and `client.wallet_address` is an alias of `client.wallet` on all client facades. Authenticated clients use the same unsigned discovery operations. `get_keys` appends `/jwks.json` to the wallet path before any query string, preserving path prefixes and opaque query data; it does not first fetch the wallet metadata.

Public discovery reads follow at most five redirects with status 301, 302, 303, 307 or 308. Every redirect target must be HTTPS, including redirects from an HTTP development endpoint. Relative `Location` references resolve against the current request URL; malformed targets, credentials, fragments, loops and excess redirects raise `ResponseError`. An origin change drops custom headers; subsequent hops retain only `Host`, `Accept` and `User-Agent`, even if they return to the original origin. Same-origin redirects retain configured headers. No authorization, cookies or signing headers are added to these reads. Redirect state is local to each call; no permanent redirect cache is maintained.

Public clients use the same configuration, injectable transports, timeout snapshots, quiet logger and ownership/close rules described below. Caller-owned event hooks and custom transports control their own behavior.

Package-level imports expose `OpenPaymentsClient`, its `AuthenticatedClient` alias, `AsyncOpenPaymentsClient`, its `AsyncAuthenticatedClient` alias, both unauthenticated clients, `Configuration`, synchronous/asynchronous HTTP transports and their protocols, SDK error types and the URL/pointer helpers alongside the existing cryptography helpers. Client classes are also available from `open_payments_sdk.client`; existing imports from `open_payments_sdk.client.client` and other implementation modules remain valid. Response and request models stay available from their existing `open_payments_sdk.models` modules.

## Authenticated async client

Use `AsyncOpenPaymentsClient` for native async wallet discovery, grants, access-token management, incoming payments, quotes, outgoing payments, listing and grant-spent amounts. Supply the registered key ID and Ed25519 private PEM, then await resource methods:

```python
from open_payments_sdk import AsyncOpenPaymentsClient

async def read_outgoing_payment(key_id, private_key, payment_url, access_token):
    async with AsyncOpenPaymentsClient(
        keyid=key_id,
        private_key=private_key,
    ) as client:
        return await client.outgoing_payments.get(payment_url, access_token)
```

`AsyncAuthenticatedClient` is an exact alias. Resource methods take the same arguments and return the same models as their synchronous counterparts, including compatibility methods. `client.wallet_address` is the same resource as `client.wallet`. Set `client_wallet_address` to provide a default identity for grant requests; an explicit request identity takes precedence. Access tokens remain per-call inputs, and the application retains replacement grant and access-token credentials.

Construction performs no requests or key generation and allocates no native HTTP pool. Use `async with` or `await client.aclose()` to close the facade and its owned transport. Configuration snapshots, borrowed transport ownership, asyncio/Trio support, cancellation and closed-resource checks follow the async rules above. Finish active requests before closing and keep each client within one backend/event loop. Public reads remain unsigned; signed operations do not follow redirects or retry, and the client performs no automatic polling, token refresh or grant cancellation.

## Client configuration and lifecycle

`Configuration` accepts `http_timeout`, `user_agent`, extra `headers`, and a standard-library `logger` or `LoggerAdapter`. Existing `Configuration()` construction and setting its attributes before constructing a client continue to work. Defaults are a ten-second timeout, `User-Agent: open-payments-sdk/python`, and `Accept: application/json`.

```python
from open_payments_sdk.configuration import Configuration
from open_payments_sdk.client.client import OpenPaymentsClient

cfg = Configuration(
    http_timeout=15.0,
    user_agent="my-application/1.0",
    headers={"X-Application-ID": "checkout"},
)
with OpenPaymentsClient(
    keyid=key_id,
    private_key=private_key,
    client_wallet_address="https://wallet.example/client",
    cfg=cfg,
) as client:
    wallet = client.wallet.get_wallet_address("https://wallet.example/alice")
```

Configuration is validated and copied when the SDK client is constructed. Later configuration/header/timeout mutations do not change that client's captured defaults. Extra headers override the default `Accept` and `User-Agent` values; header names and values must be valid ASCII HTTP fields. Authentication, signatures, digests, JSON content type, framing, hop-by-hop and cookie headers are reserved for request preparation. Tokens stay per-operation inputs. Configuration headers are applied before signing and do not mutate caller dictionaries or transport defaults.

The SDK client supports `close()`, `is_closed` and context-manager use. Closing it prevents further calls through its resources, including previously saved resource references, and releases its owned transport. Pass a native `httpx.Client` through `http_client=` to borrow its pool; SDK closure leaves that native client open. Existing SDK `HttpClient` or custom `HttpClientProtocol` backends are also borrowed: `client.http_client` keeps the supplied object, and the caller owns its cleanup. An injected SDK/custom backend retains its own timeout; the configured SDK timeout applies to SDK-created transports and adapters around native HTTPX clients. Finish concurrent requests before closing.

The default SDK logger is `open_payments_sdk.client.client`, with a single `NullHandler` and no per-client stream handlers, following [Python's library logging guidance](https://docs.python.org/3.10/howto/logging.html#configuring-logging-for-a-library). Supplying a logger preserves its handlers, levels and propagation settings. The SDK does not configure the root or HTTPX loggers; application logging configuration controls those separately. The existing `get_log_handler()` helper remains available for explicit use and is no longer installed automatically during client construction.

## HTTP transport ownership

`HttpClient` reuses a single HTTPX connection pool, initialized on its first send. Use its context manager or call `close()` when requests have finished. Construction, context entry and request preparation perform no network requests.

```python
from open_payments_sdk.http import HttpClient
from open_payments_sdk.client.client import OpenPaymentsClient

with HttpClient(http_timeout=10.0) as http:
    client = OpenPaymentsClient(
        keyid=key_id,
        private_key=private_key,
        client_wallet_address="https://wallet.example/client",
        http_client=http,
    )
    wallet = client.wallet.get_wallet_address("https://wallet.example/alice")
```

For an existing native HTTPX client, use `HttpClient(http_timeout=10.0, client=native_client)`. This wrapper borrows the supplied client: closing or exiting the wrapper leaves the native client open for its owner to close. A closed wrapper rejects further use with `ConfigurationError`; `is_closed` also detects a supplied client that its owner has closed. Finish concurrent requests before closing; `close()` does not cancel in-flight work.

`http_timeout` accepts a finite nonnegative number of seconds, `None` to disable timeouts, or an `httpx.Timeout` with separate connect/read/write/pool values. The timeout is captured in each prepared request. A manually supplied HTTPX request retains an explicit timeout extension; otherwise the wrapper supplies its current timeout. See [HTTPX timeout options](https://www.python-httpx.org/advanced/timeouts/).

Owned HTTPX clients read TLS/proxy environment settings when their pool is first created. Invalid certificate files or missing optional proxy dependencies raise a sanitized `ConfigurationError` with reason `http_client` on that operation. Client construction stays network-free, and ordinary diagnostics omit file paths and proxy credentials.

SDK requests use their prepared URL, body and headers without merging native-client default headers, query parameters, cookies or authentication. Transport dispatch disables native redirects and uses no additional authentication flow, preserving per-call GNAP credentials and signatures even when the borrowed client has different defaults. Public discovery reads handle the bounded HTTPS redirects described above through fresh unsigned requests. Signed operations return a response error for redirects and are never automatically replayed. The SDK adds no retries. Injected event hooks and custom transports remain caller-configured behavior and must preserve signed request bytes and avoid replaying payments.

All synchronous wallet, grant, token and payment methods share one request pipeline. Each supplied body/query model is exported once with its existing aliases and omission rules, then HTTPX prepares the final URL and JSON bytes. The SDK calculates the content digest and signs that prepared request before sending it to the shared response handler. Tokens remain call-local and covered request data is preserved during dispatch.

For native async HTTP I/O, use `AsyncHttpClient` with `async with` or `await transport.aclose()`. It prepares requests synchronously and awaits HTTPX dispatch. The pool is allocated on first send and reused; the timeout and prepared-request isolation rules above also apply. Use each transport within one async backend/event loop, and finish active sends before closing it. Asyncio and Trio are supported; applications choosing Trio must install it. For example, this public HTTP request needs no signing key:

```python
import asyncio
from open_payments_sdk import AsyncHttpClient

async def main():
    async with AsyncHttpClient(http_timeout=10.0) as transport:
        request = transport.build_request(
            "GET", "https://wallet.example/alice",
            headers={"Accept": "application/json"},
        )
        response = await transport.send(request)
        return response.json()

# In an async application, await main() from the existing event loop.
# asyncio.run(main()) is suitable for a standalone script.
```

`AsyncHttpClient(http_timeout=10.0, client=native_async_client)` borrows an existing `httpx.AsyncClient` and leaves it open when the wrapper closes. Owned cleanup is performed once, and its initiating task joins it before cancellation propagates. Concurrent close calls share that cleanup; a cleanup failure propagates on subsequent close calls too. Cancellation of a send propagates without retries or an automatic pool close. A cancelled payment request can still have an uncertain provider outcome and must be reconciled before another write. `AsyncHttpClientProtocol` describes the synchronous `build_request()` and async `send()` methods for a caller-owned async transport.

Body/query arguments must match the operation's SDK request model, except that `grants.request` also accepts a mapping and validates it as a `GrantRequest`. Other invalid body/query values, including `None`, raw dictionaries and unrelated models, raise `InputError` before their fields are serialized. Required access tokens must be strings; invalid values raise `InputError` before dispatch. An empty polling model such as `InteractRef()` sends a signed `{}` JSON body; bodyless operations send no JSON payload.

## Initial grant requests

Use `grants.request(url, grant_request)` with the complete authorization endpoint and either a mapping or a `GrantRequest`. When a mapping omits `client`, the SDK fills it from the constructor's `client_wallet_address` before validating and signing the body:

```python
from open_payments_sdk import OpenPaymentsClient

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
    client_wallet_address="https://wallet.example/alice",
) as authenticated_client:
    requested = authenticated_client.grants.request(
        url="https://auth.example/grants",
        grant_request={
            "access_token": {
                "access": [{"type": "incoming-payment", "actions": ["create"]}]
            }
        },
    )
```

An explicit `client` always takes precedence, including a wallet-address object with display metadata or a public JWK identity. An invalid explicit identity, such as null, raises `InputError` without falling back to the configured wallet. The default is captured when the client is constructed; changing its public `client_wallet_address` attribute later does not change the grant service's default. Mappings and their nested values are left unchanged.

The constructor's wallet argument is optional for operations that supply their own identity, including directed JWK grants. Omitting both the per-call identity and the default raises `InputError` before preparing a request. Typed `GrantRequest` instances still require their own explicit identity. The compatibility helper `post_grant_request(grant_request, auth_server_endpoint)` keeps its model-only argument contract and delegates to the same request path.

Initial requests support access-token, subject-only and combined request shapes described below. Each outgoing-payment access entry may specify at most one of `limits.debitAmount` and `limits.receiveAmount`; supplying both raises `InputError` before signing. This request rule also applies through the compatibility helper. The reusable `LimitsOutgoing` data model still accepts both amounts when parsing protocol data. The SDK exports the validated request model once, sends no Authorization header on the initial request and does not follow signed redirects or retry.

`AsyncGrants` provides the same grant operations through an async transport:

```python
import logging
from open_payments_sdk import AsyncHttpClient
from open_payments_sdk.api.async_auth import AsyncGrants

async def request_access(key_id, private_key):
    async with AsyncHttpClient(http_timeout=10.0) as transport:
        grants = AsyncGrants(
            keyid=key_id,
            private_key=private_key,
            logger=logging.getLogger(__name__),
            http_client=transport,
            client_wallet_address="https://wallet.example/alice",
        )
        return await grants.request(
            "https://auth.example/grants",
            {"access_token": {
                "access": [{"type": "incoming-payment", "actions": ["create"]}]
            }},
        )
```

Await `request`, `continue_grant` and `cancel`, or their existing compatibility method names. Identity validation, typed responses, per-call continuation credentials and signing follow the synchronous rules. Async continuation has the same bodyless/explicit JSON distinction described below; the caller verifies callbacks, retains replacement credentials and observes `wait`. No polling schedule or retry is added. Closing the transport releases connections; cancelling a grant remains an explicit operation. Cancellation after dispatch can leave an uncertain authorization outcome that the application must reconcile.

## Grant continuation and cancellation

Use the latest returned continuation URI and continuation access token with an authenticated client. `continue_grant` and `cancel` accept complete HTTP(S) URLs, including opaque path prefixes and queries, without reconstructing the endpoint from an ID.

For redirect interaction, generate an unpredictable client nonce with Python's `secrets` module and send it as `interact.finish.nonce` in the initial grant request. Before redirecting the user, save the original nonce, the exact grant endpoint string used for that request, the returned `interact.finish` server nonce, and the complete pending grant response in your protected transaction store.

Match the callback to that stored transaction and check its session deadline. Pass the callback's `hash` and `interact_ref` values after your web framework has URL-decoded them once. The helper does no URL decoding; a `+` in a padded Base64 hash must reach it as `+` (encoded as `%2B` in a query string).

The SHA-256 interaction-hash helpers offer two explicit encodings:

| `encoding` | Representation |
| --- | --- |
| `"base64"` | Padded standard Base64; the existing SDK helpers' default |
| `"base64url"` | Unpadded URL-safe Base64, as specified by [GNAP interaction hashing](https://www.rfc-editor.org/rfc/rfc9635.html#section-4.2.3) |

Configure the encoding for your authorization server and retain that choice with the transaction. The helper accepts only the selected canonical encoding and compares valid hashes in constant time. Endpoint spelling, including its trailing slash and query bytes, is part of the hash input; use the saved initial endpoint throughout recovery.

The following application function verifies the callback before making one continuation request. `pending` is the saved interactive `Grant` response. `claim_completion` is an application-supplied, zero-argument function bound to this transaction: it must atomically persist a completion claim and return `True` only for the first caller. Retain that claim across failures and restarts, and respect the grant's continuation wait before invoking this function.

```python
from open_payments_sdk import OpenPaymentsClient
from open_payments_sdk.gnap_utils.hash import verify_interaction_hash
from open_payments_sdk.models.auth import InteractRef

def continue_after_interaction(
    key_id,
    private_key,
    pending,
    *,
    client_nonce,
    grant_endpoint,
    interact_ref,
    received_hash,
    encoding,
    claim_completion,
):
    interaction = getattr(pending, "interact", None)
    if interaction is None or not verify_interaction_hash(
        client_nonce=client_nonce,
        server_nonce=interaction.finish,
        interact_ref=interact_ref,
        grant_endpoint=grant_endpoint,
        received_hash=received_hash,
        encoding=encoding,
    ):
        raise ValueError("Invalid interaction callback")

    with OpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        if not claim_completion():
            raise ValueError("Grant continuation already claimed")
        return client.grants.continue_grant(
            url=pending.cont.uri,
            access_token=pending.cont.access_token.value,
            interact_ref=InteractRef(interact_ref=interact_ref),
        )
```

Persist the full returned `GrantContinueResponse` and its replacement `.cont` URI, access token and wait before the next operation. A verified callback can still produce a pending or subject-only result; require an issued access token with the necessary permissions before creating a payment. If a dispatched continuation fails, retain the completion claim and reconcile the authorization-server state before another attempt. Hash verification and the in-memory model are not a durable replay store.

For polling, call `continue_grant` from an open client context and omit `interact_ref` (or pass `None`) to send a signed bodyless POST. Passing `InteractRef()` explicitly sends signed `{}` JSON. The existing `post_grant_continuation_request(interact_ref, continue_uri, access_token)` helper keeps its required model argument and existing JSON behavior. Retain the new `.cont` URI and token after every response and respect `.cont.wait` before scheduling another continuation. For a missing `wait`, [GNAP recommends a polling interval of at least five seconds](https://www.rfc-editor.org/rfc/rfc9635.html#section-5). The SDK does not sleep, poll automatically or retry a failed request. Once an interaction reference has been submitted, further polling uses no interaction reference.

Grant cancellation is a separate operation using the latest continuation metadata:

```python
from open_payments_sdk import OpenPaymentsClient

def cancel_grant(key_id, private_key, continuation):
    with OpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        return client.grants.cancel(
            url=continuation.uri,
            access_token=continuation.access_token.value,
        )
```

A successful cancellation returns `None` for the specified HTTP 204 acknowledgement. The existing `delete_grant(req_id, auth_server_endpoint, access_token)` helper retains its conventional `/continue/{id}` URL adapter. Signed continuation and cancellation requests reject redirects without replaying the request. Client cleanup releases connections; cancellation remains an explicit application choice. For native async clients, verify the callback and claim the transaction before awaiting `client.grants.continue_grant(...)` or `client.grants.cancel(...)` inside `async with`.

## Access token rotation and revocation

Use the access token's current `manage` URI and `value` with `access_tokens.rotate`. The result is an `AccessTokenRotationResponse` matching the specified `{ "access_token": ... }` envelope, including permitted envelope extensions. In these application helpers, `current` is an issued `AccessToken` from a grant response or a previous rotation's `.access_token`:

```python
from open_payments_sdk import OpenPaymentsClient

def rotate_access_token(key_id, private_key, current):
    with OpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        return client.access_tokens.rotate(
            url=current.manage,
            access_token=current.value,
        )

def revoke_access_token(key_id, private_key, current):
    with OpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        return client.access_tokens.revoke(
            url=current.manage,
            access_token=current.value,
        )
```

After rotation, persist the full returned envelope and use its `.access_token` as the current token. Retain its replacement value, management URI, permissions and expiry metadata before subsequent operations. Coordinate rotation with requests sharing that token. The application controls expiry checks and rotation timing. Revoke only when intended, using the latest token; the two helpers perform separate operations.

Both methods accept complete HTTP(S) URLs, including opaque paths and queries, and send signed bodyless requests. Rotation requires an HTTP 200 response with the envelope; revocation requires HTTP 204 and returns `None` without decoding JSON. Each call uses the supplied credentials. Earlier results remain unchanged, and the SDK does not store replacement tokens, schedule rotation, follow signed redirects or retry.

The compatibility helpers keep their existing parameter names and order: `post_rotate_access_token(token_id, auth_server_endpoint, access_token)` and `delete_access_token(token_id, auth_server_endpoint, access_token)`. They retain the conventional `/token/{id}` URL adapter. The rotation helper now validates the correct response envelope and returns its nested `AccessToken`, preserving its existing Python return type. A bare token response is rejected as invalid protocol data.

The native async client supports the same operations and result models:

```python
from open_payments_sdk import AsyncOpenPaymentsClient

async def rotate_access_token_async(key_id, private_key, current):
    async with AsyncOpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        return await client.access_tokens.rotate(
            url=current.manage,
            access_token=current.value,
        )

async def revoke_access_token_async(key_id, private_key, current):
    async with AsyncOpenPaymentsClient(keyid=key_id, private_key=private_key) as client:
        return await client.access_tokens.revoke(
            url=current.manage,
            access_token=current.value,
        )
```

Both helpers await one operation and close their owned transport before returning. `AsyncAccessTokens` remains available from `open_payments_sdk.api.async_auth` for direct use with an async transport. Its compatibility helpers are also awaited and retain their synchronous return types. Closing a client or transport does not revoke an access token. Cancellation propagates without retry or automatic revocation; if a rotation was dispatched, its outcome may be unknown, so reconcile with the authorization server before attempting another rotation.

## Incoming payment operations

Create an incoming payment using the wallet's resource-server base URL and an `IncomingPaymentRequest`. Use the complete returned payment `id` for private reads and completion, supplying the access token authorized for each action:

```python
from open_payments_sdk import OpenPaymentsClient
from open_payments_sdk.models.resource import IncomingPaymentRequest

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
) as client:
    created = client.incoming_payments.create(
        url=wallet.resourceServer,
        payment=IncomingPaymentRequest(
            walletAddress=wallet.id,
            metadata={"externalRef": "INV-2026-0137"},
        ),
        access_token=create_access_token,
    )
    current = client.incoming_payments.get(
        url=created.id,
        access_token=read_access_token,
    )
    completed = client.incoming_payments.complete(
        url=current.id,
        access_token=complete_access_token,
    )
```

These methods accept HTTP(S) strings, `AnyUrl` or `httpx.URL` values. `create` trims trailing slashes from the base path and appends `/incoming-payments`. `get` uses the complete resource URL. `complete` appends `/complete` to that resource path exactly as returned. Suffixes are inserted before any query, retaining its escaping, ordering and explicit empty `?` marker. Paths can contain opaque provider prefixes and identifiers. Creation exports its required model once; reads and completion use signed bodyless requests. Signed operations reject redirects without replaying the request.

Creation and private reads return `IncomingPaymentResponse` with methods and optional metadata; completion returns `IncomingPayment` and validates its completed state. See the incoming-payment model section for the amount and state checks. The existing `post_create_payment(payment, resource_server_endpoint, access_token)`, `get_incoming_payment(payment_id, resource_server_endpoint, access_token)` and `post_complete_incoming_payment(payment_id, resource_server_endpoint, access_token)` helpers keep their parameter names and order and delegate to these operations. Their conventional paths also preserve base-URL queries before appended route suffixes.

For async applications, `AsyncIncomingPayments` exposes the same operations and response models:

```python
import logging

from open_payments_sdk import AsyncHttpClient
from open_payments_sdk.api.async_resource import AsyncIncomingPayments
from open_payments_sdk.models.resource import IncomingPaymentRequest

async def create_and_read_incoming(
    key_id, private_key, wallet, create_access_token, read_access_token
):
    async with AsyncHttpClient(10) as transport:
        incoming = AsyncIncomingPayments(
            keyid=key_id,
            private_key=private_key,
            logger=logging.getLogger(__name__),
            http_client=transport,
        )
        created = await incoming.create(
            wallet.resourceServer,
            IncomingPaymentRequest(walletAddress=wallet.id),
            create_access_token,
        )
        current = await incoming.get(created.id, read_access_token)
        return created, current
```

Use `await incoming.complete(current.id, complete_access_token)` to complete a payment explicitly. `await incoming.get_public(current.id)` reads its public details without a token or signature. `await incoming.list(resource_server, query, access_token)` returns one validated page; request further pages explicitly. The four compatibility helpers are also awaited. Cancellation propagates without replay; a dispatched create or completion request may have taken effect even if its response was not received.

## Payment listing operations

Both authenticated payment clients expose `list(url, query, access_token)`. Supply the resource-server base URL and a `PaymentListQuery` for the wallet and desired page direction:

```python
from open_payments_sdk import OpenPaymentsClient
from open_payments_sdk.models.resource import PaymentListQuery

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
) as client:
    query = PaymentListQuery(walletAddress=wallet.id, first=25)
    incoming_page = client.incoming_payments.list(
        url=wallet.resourceServer,
        query=query,
        access_token=incoming_list_access_token,
    )
    outgoing_page = client.outgoing_payments.list(
        url=wallet.resourceServer,
        query=query,
        access_token=outgoing_list_access_token,
    )
    if incoming_page.pagination.hasNextPage and incoming_page.pagination.endCursor is not None:
        next_incoming_page = client.incoming_payments.list(
            url=wallet.resourceServer,
            query=PaymentListQuery(
                walletAddress=wallet.id,
                first=25,
                cursor=incoming_page.pagination.endCursor,
            ),
            access_token=incoming_list_access_token,
        )
```

Each call returns one validated `PaginatedIncomingPayments` or `PaginatedOutgoingPayments` page. The application makes any next-page request explicitly. `last` selects backward pagination. The existing `get_incoming_payments(query, resource_server_endpoint, access_token)` and `get_outgoing_payments(query, resource_server_endpoint, access_token)` helpers retain their parameter names and order and delegate to `list`.

Base URLs accept HTTP(S) strings, `AnyUrl` and `httpx.URL`. The SDK appends `/incoming-payments` or `/outgoing-payments` before any query, trimming trailing base-path slashes. Provider query components retain their original escaping, order, duplicate keys and empty components. `PaymentListQuery` controls `wallet-address`, `cursor`, `first` and `last`: existing values for those fields, including the `walletAddress` alias and percent-encoded names, are replaced or removed according to the model. This keeps stale URL filters from overriding the requested wallet or page direction. The model is exported once and the final composed URL is signed before sending.

## Quote operations

Use `quotes.create(url, quote, access_token)` with the sender's resource-server base URL and a `QuoteRequest`. For a fixed debit amount, use the sender wallet's asset information:

```python
from open_payments_sdk import OpenPaymentsClient
from open_payments_sdk.models.resource import Amount, QuoteRequest

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
) as client:
    quoted = client.quotes.create(
        url=wallet.resourceServer,
        quote=QuoteRequest(
            walletAddress=wallet.id,
            receiver=incoming_payment.id,
            method="ilp",
            debitAmount=Amount(
                value="1000",
                assetCode=wallet.assetCode,
                assetScale=wallet.assetScale,
            ),
        ),
        access_token=create_quote_access_token,
    )
    current_quote = client.quotes.get(
        url=quoted.id,
        access_token=read_quote_access_token,
    )
```

For a fixed receive amount, supply only `receiveAmount` with the receiver's asset information. Omit both amount fields to let the server infer the amount from the incoming payment. The SDK sends one creation request and does not fetch the receiver to infer an amount. The existing model guards reject conflicting amount directions and invalid protocol fields.

Creation appends `/quotes` before any base-URL query, trimming trailing path slashes. Retrieval accepts the complete returned HTTP(S) quote URL, including opaque provider paths, escaped identifiers and queries. Both methods also accept `AnyUrl` and `httpx.URL`. Creation serializes its required model once and expects HTTP 201; retrieval sends a signed bodyless GET and expects HTTP 200. Both return `Quote` with required debit/receive amounts, independent asset information and the specified optional expiry string. Receiver fields keep the pinned v1.5.1 receiver contract described below. Signed redirects are rejected without replaying the request.

The existing `post_create_quote(quote, resource_server_endpoint, access_token)` and `get_quote(quote_id, resource_server_endpoint, access_token)` helpers keep their parameter names and order and delegate to these methods. Their conventional paths preserve any base query before appended suffixes.

Pass the same `QuoteRequest` models to `AsyncQuotes` for native async creation and retrieval:

```python
import logging

from open_payments_sdk import AsyncHttpClient
from open_payments_sdk.api.async_resource import AsyncQuotes

async def create_and_read_quote(
    key_id, private_key, resource_server, quote_request,
    create_access_token, read_access_token,
):
    async with AsyncHttpClient(10) as transport:
        quotes = AsyncQuotes(
            keyid=key_id,
            private_key=private_key,
            logger=logging.getLogger(__name__),
            http_client=transport,
        )
        created = await quotes.create(
            resource_server, quote_request, create_access_token
        )
        current = await quotes.get(created.id, read_access_token)
        return created, current
```

Both operations return the existing `Quote` model, including its optional expiry string. Await the two compatibility helpers as well. Each request uses the supplied access token without fetching the receiver or retrying. Cancellation propagates; a dispatched creation may have succeeded even if its response was not received.

## Outgoing payment operations

Create an outgoing payment using the sender wallet's resource-server base URL and an `OutgoingPaymentRequest`. Supply a quote ID, or an incoming-payment ID together with a debit amount. Use the complete returned payment ID for subsequent reads:

```python
from open_payments_sdk import OpenPaymentsClient
from open_payments_sdk.models.resource import OutgoingPaymentRequest

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
) as client:
    created_payment = client.outgoing_payments.create(
        url=wallet.resourceServer,
        payment=OutgoingPaymentRequest(
            walletAddress=wallet.id,
            quoteId=current_quote.id,
        ),
        access_token=create_payment_access_token,
    )
    current_payment = client.outgoing_payments.get(
        url=created_payment.id,
        access_token=read_payment_access_token,
    )
```

For creation without a quote, replace `quoteId` with `incomingPayment=incoming_payment.id` and `debitAmount=Amount(value="1000", assetCode=wallet.assetCode, assetScale=wallet.assetScale)`, importing `Amount` from the same models module. The model rejects missing or conflicting sources. Creation exports the required model once, appends `/outgoing-payments` before any base query and expects HTTP 201. Retrieval uses the complete opaque HTTP(S) resource URL, sends a signed bodyless GET and expects HTTP 200. Both methods accept strings, `AnyUrl` and `httpx.URL`; base-path trailing slashes are trimmed only when appending the collection path. Each call uses its supplied access token and rejects signed redirects without replay.

Creation returns `OutgoingPaymentWithSpentAmounts`, including optional grant-spent amounts and permitted provider extensions. Retrieval returns the specified plain `OutgoingPayment` and rejects extra response fields. Both operations apply the same sending-asset, numeric sent/debit and failure-state checks as listing. Consistent pending, fully paid and partly failed responses are accepted, including immediately after creation. Receiving assets may differ from sending assets, and original amount strings are preserved.

The existing `post_create_payment(payment, resource_server_endpoint, access_token)` and `get_outgoing_payment(payment_id, resource_server_endpoint, access_token)` helpers retain their parameter names and order and delegate to these methods. Their conventional paths preserve base queries. The old getter validates the plain wire response first, then preserves its existing `OutgoingPaymentWithSpentAmounts` Python return type with absent optional spent fields. Fields omitted by the server stay unset in the adapted model.

Use `AsyncOutgoingPayments` with the same `OutgoingPaymentRequest` models for native async operations:

```python
import logging

from open_payments_sdk import AsyncHttpClient
from open_payments_sdk.api.async_resource import AsyncOutgoingPayments

async def create_and_read_outgoing(
    key_id, private_key, resource_server, payment_request,
    create_access_token, read_access_token,
):
    async with AsyncHttpClient(10) as transport:
        outgoing = AsyncOutgoingPayments(
            keyid=key_id,
            private_key=private_key,
            logger=logging.getLogger(__name__),
            http_client=transport,
        )
        created = await outgoing.create(
            resource_server, payment_request, create_access_token
        )
        current = await outgoing.get(created.id, read_access_token)
        return created, current
```

Creation returns `OutgoingPaymentWithSpentAmounts` and canonical retrieval returns `OutgoingPayment`, as with the synchronous methods. Within the open transport context, use `await outgoing.list(resource_server, query, access_token)` for one page, or `await outgoing.get_grant_spent_amounts(resource_server, access_token)` for the current grant's spending. Await the three compatibility helpers as well; the getter retains its adapted return type. Each call uses the supplied access token without caching results or retrying. Cancellation propagates; a dispatched creation may have sent a payment even if its response was not received. Reconcile the outcome before starting another payment attempt.

## Outgoing grant-spent amounts

Read the spent amounts for the outgoing payment grant corresponding to the supplied current access token:

```python
from open_payments_sdk import OpenPaymentsClient

with OpenPaymentsClient(
    keyid=key_pair.jwks.keys[0].kid,
    private_key=key_pair.private_key_pem,
) as client:
    spent = client.outgoing_payments.get_grant_spent_amounts(
        url=wallet.resourceServer,
        access_token=outgoing_access_token,
    )
```

Supply the resource-server base URL as an HTTP(S) string, `AnyUrl` or `httpx.URL`. The method trims trailing base-path slashes and appends `/outgoing-payment-grant` before any query, preserving opaque provider prefixes and query spelling. It sends one signed bodyless GET, expects HTTP 200 and returns `OutgoingPaymentGrant`. Signed redirects are rejected without replay.

The response requires both `spentReceiveAmount` and `spentDebitAmount`; each can be an amount or `None`. Explicit nulls remain present in dumps and are not replaced with zero. Amounts retain their original value strings and independent assets, and permitted finite JSON extensions are preserved. The SDK does not infer balances or compare totals with individual payments. For recurring grants, the server reports the current interval's amounts. Each call reads the server using its supplied token without caching earlier totals.

## SDK operation errors

Synchronous and asynchronous wallet, grant, access token and payment operations raise subclasses of `OpenPaymentsError` from `open_payments_sdk.errors`: `ConfigurationError`, `InputError`, `SigningError`, `TransportError`, `TransportTimeoutError`, `HTTPError` or `ResponseError`. Direct Pydantic model construction and standalone cryptography helpers retain their existing exceptions. A timeout is also a transport error; it does not establish whether the server completed a payment. The SDK does not retry failed calls.

`ResponseError.location` exposes a single untrusted redirect `Location` value for deliberate inspection; ordinary exception diagnostics omit it. HTTPX can reject malformed redirect targets before returning a response, even with its redirects disabled. These failures remain structured errors: `ResponseError` with reason `response_url` for invalid URL parsing, or the existing `TransportError` for native protocol failures. Status and location may be unavailable in those cases.

```python
from open_payments_sdk import HTTPError, OpenPaymentsError, UnauthenticatedClient

def discover_wallet(wallet_address):
    try:
        with UnauthenticatedClient() as client:
            return client.wallet.get(wallet_address)
    except HTTPError as error:
        print(error.operation, error.status)  # Fixed operation name and HTTP status.
        raise
    except OpenPaymentsError as error:
        print(error.kind, error.operation)
        raise
```

Errors expose `operation`, `method`, `url`, `status`, `reason` and `validation_errors`. The URL contains only the origin: user information, path, query and fragment are removed because returned management paths can contain secrets. Validation issues contain schema field/index locations and error types; arbitrary map keys are replaced with `<field>` and rejected values and validator messages are omitted. `ResponseError.reason` distinguishes `unexpected_status`, `json`, `encoding` and `validation` failures. Operations require the pinned success status (`201` for payment/quote creation, `200` for reads and grant/token responses, `204` for cancellations); empty cancellation acknowledgements are not decoded as JSON.

HTTP errors retain nested Open Payments server `code`, `description` and object `details` for explicit access. GNAP's alternative string `error` form supplies the code alone, as defined in [RFC 9635 section 3.6](https://www.rfc-editor.org/rfc/rfc9635.html#section-3.6). These fields are untrusted and can contain sensitive values, so they are absent from `str(error)`, `repr(error)` and exception arguments. Original failures remain in suppressed `error.__context__`; normal tracebacks omit them. Explicitly inspecting context, server fields or traceback locals can expose request/response data. The SDK does not automatically log errors or response bodies.

## Request signatures and content digests

The SDK signs prepared requests using Ed25519 and SHA-512 content digests. The helpers below can verify an already signed, fully buffered `httpx.Request` independently of the SDK's request builder. Select the public key and key ID from a trusted registry before calling the verifier.

```python
from httpx import Request
from open_payments_sdk import load_public_key, verify_request_signature

def verify_signed_request(request: Request, trusted_jwk: dict) -> bool:
    public_key = load_public_key(trusted_jwk, format="jwk")
    return verify_request_signature(
        request,
        public_key=public_key,
        key_id=trusted_jwk["kid"],
    )
```

Verification checks the exact prepared method/target URI, the expected key ID, signature bytes and timestamp validity. Authorization must be covered when present. Requests with content or explicit content metadata must cover their content type, byte length and SHA-512 digest; the digest and length must also match the exact body bytes. Host must match the prepared URL. The helper leaves the request unchanged and returns `False` for invalid inputs, unsupported signatures or unread/transfer-encoded streams.

`max_age` defaults to five minutes and accepts a positive `datetime.timedelta`. Age and optional expiry checks use Unix timestamps with five seconds of clock tolerance. The helper supports a single signature and plain covered components. It rejects duplicate signature fields/parameters and repeated covered headers. It accepts the current SDK/Node signing profile's optional `alg="ed25519"` and untagged signatures; a supplied `tag` must be `"gnap"`. This is a verifier for that Open Payments SDK profile; the full [GNAP HTTP signature profile](https://www.rfc-editor.org/rfc/rfc9635.html#section-7.3.1) defines additional requirements. Token authorization, trusted-key discovery and durable nonce/replay tracking remain application responsibilities.

Digest helpers operate on exact bytes without JSON parsing, normalization or encoding guesses:

```python
from open_payments_sdk import calculate_content_digest, verify_content_digest

body = b'{"hello": "world"}'
digest = calculate_content_digest(body)
assert verify_content_digest(body, digest)
assert not verify_content_digest(body + b"\n", digest)
```

`verify_content_digest()` requires a valid SHA-512 member in the structured `Content-Digest` dictionary and compares it in constant time. Other algorithm members are ignored. Digest verification alone does not authenticate the sender; signature verification binds the digest to the selected public key.

## Amounts and pagination models

`Amount` validates a decimal string from `"0"` through `"18446744073709551615"`, with an integer asset scale from 0 through 255. Values keep their exact string spelling, including leading zeros. Asset codes follow the string contract, with ISO4217 recommended where applicable. Additional JSON fields are retained. Amounts remain importable from `open_payments_sdk.models.resource` and are shared with grant-limit models.

```python
from open_payments_sdk.models.resource import Amount, PaymentListQuery, Pagination

amount = Amount(value="1000", assetCode="USD", assetScale=2)
query = PaymentListQuery(
    walletAddress="https://wallet.example/alice",
    first=25,
    cursor=None,
)
assert query.to_query_params() == {
    "wallet-address": "https://wallet.example/alice",
    "first": 25,
}
empty_page = Pagination(hasNextPage=False, hasPreviousPage=False)
assert empty_page.model_dump() == {
    "hasNextPage": False,
    "hasPreviousPage": False,
}
```

`PageInfo` and the existing `Pagination` name share required boolean flags and optional nonempty cursor strings. Omitted response cursors stay absent in serialized output; explicit null cursors are invalid. Cursors retain their opaque spelling. Page metadata rejects unknown fields, while payment-list envelopes retain permitted provider extension fields.

Query counts are integers from 1 through 100. At most one of `first` and `last` may be supplied, matching the Node SDK's direction types; this is an SDK rule beyond the specification's separate count constraints. Optional Python query values of `None` mean omission. `to_query_params()` exports raw values with `wallet-address`; URL encoding belongs to the transport. The public `walletAddress` attribute and JSON request-body field name remain available.

Incoming and outgoing listing requests send the specified `wallet-address` query key, using the query model's serialization alias before preparing and signing the request. Absent or `None` query values are omitted. Cursors retain their opaque value and are encoded once by the HTTP transport. Each call returns one typed page, including empty results; the application chooses when to request another page using its returned cursors. Default Python `PaymentListQuery.model_dump()` continues to use `walletAddress`.

Listing operations also validate each returned payment's related amounts. Incoming items require matching incoming/received assets when `incomingAmount` is present. Outgoing items require matching sent/debit assets, a sent amount no greater than the debit amount, and a consistent `failed` flag: a fully sent payment cannot be marked failed. Numeric comparisons preserve the original amount strings, including leading zeros; cross-currency receive amounts remain independent. Inconsistent items reject the page with `ResponseError`, reason `validation`, and safe locations beginning with `("result", index)`. These operation checks leave reusable data-model contracts unchanged.

Amount values and asset codes require strings; scales and counts require integers; page flags require booleans. Incompatible types and cross-type coercions are rejected. Assignments to amount fields and wallet asset fields are validated too. The Pydantic `model_construct()`/`model_copy(update=...)` escape hatches assume trusted data; query export revalidates before returning parameters.

## Incoming payment models

`IncomingPaymentRequest` accepts the required wallet address and optional incoming amount, expiry and metadata; unknown request fields and explicit nulls are rejected. Metadata must be a JSON object with finite JSON values. Use the wallet's asset code and scale for the incoming amount.

`IncomingPayment` models detailed list/complete results. `IncomingPaymentResponse` adds required payment methods for creation and authenticated reads. `PublicIncomingPayment` models public discovery with required authorization-server and method fields, without requiring a wallet address or metadata. Every response requires `id`, `completed`, `receivedAmount` and `createdAt`; `completed` requires a boolean. Response models retain permitted JSON extensions. Existing `updatedAt`, `methods` and `authServer` fields remain available as typed optional extensions where applicable.

Authenticated create/read/complete operations check that `incomingAmount`, when present, uses the same asset code and scale as `receivedAmount`. Creation additionally requires a numerically zero received amount and `completed=False`; completion requires `completed=True`, including when the full incoming amount has not been received. Leading zeros in amount strings are preserved. Inconsistent successful responses raise `ResponseError` with reason `validation` and safe field locations. The reusable data models continue to represent protocol data independently of these operation rules.

Methods retain the existing `PaymentMethod.ilp` enum, validate the ILP address and Base64url character contracts, and reject unknown fields. Method arrays may be empty and must contain unique entries. Shared secrets are hidden in ordinary representations and validation-error text; explicit attribute access and dumps retain them.

Incoming-payment timestamps use offset [date-time strings](https://spec.openapis.org/registry/format/date-time) or timezone-aware Python `datetime` values. Numeric timestamps, dates without a time and timestamps without an offset are rejected. Serialization uses Python datetime precision and normalization; leap seconds cannot be represented. URI attributes retain the existing `AnyUrl` behavior. Optional known fields are omitted when absent and reject explicit nulls.

## Quote models

`QuoteRequest` requires a wallet address, an incoming-payment receiver and `PaymentMethod.ilp`. Supply `receiveAmount`, `debitAmount`, or neither when the server can infer the amount from the incoming payment. Supplying both amounts is invalid. Unknown request fields and explicit nulls are rejected; omitted amount fields stay absent in dumps.

`Quote` is a separate response model requiring `id`, `walletAddress`, `receiver`, `method`, both amounts and `createdAt`. Cross-currency amounts are preserved independently. It rejects unknown fields, including `sentAmount`. `expiresAt` remains an optional strict string as declared by the pinned schema, with no additional date-time format constraint. `createdAt` uses the offset-aware timestamp contract above.

Receiver validation checks the specification's HTTP(S) incoming-payment pattern and the normalized URL path, so query/fragment text or dot segments cannot supply a missing payment path. It runs with Python optimization enabled. Existing request `HttpUrl`, response `AnyUrl` and payment-method enum attributes remain available. Normal assignments validate before replacing valid values.

## Outgoing payment models

`OutgoingPaymentRequest` requires a wallet address and either `quoteId`, or both `incomingPayment` and `debitAmount`. The forms are exclusive; a quote request cannot also supply a debit amount or incoming payment. Metadata is an optional JSON object. Quote and incoming-payment references follow their URI contracts without imposing resource-path patterns. Unknown fields and explicit nulls are rejected.

`OutgoingPayment` requires `id`, `walletAddress`, `receiver`, `debitAmount`, `receiveAmount`, `sentAmount` and `createdAt`. A missing `quoteId` stays absent, and `failed` defaults to `False` as specified; `exclude_unset=True` also omits that default when absent in the input. Amounts retain their exact strings and timestamps use the offset-aware contract above. The plain response follows its closed schema. `OutgoingPaymentWithSpentAmounts` additionally accepts optional non-null grant-spent amounts and permitted provider JSON extensions, including the legacy typed `updatedAt` field.

`OutgoingPaymentGrant` models the separate grant-spent response. Both keys are required and each may contain an amount or null. Null values remain present in default dumps:

```python
from open_payments_sdk.models.resource import OutgoingPaymentGrant

spent = OutgoingPaymentGrant(spentReceiveAmount=None, spentDebitAmount=None)
assert spent.model_dump() == {
    "spentReceiveAmount": None,
    "spentDebitAmount": None,
}
```

## Grants

Every `GrantRequest` requires a client identity. Use `ClientWalletAddress` for a wallet object, or `ClientDirectedIdentity` with a public JWK for a non-interactive grant. The existing wallet URI string remains supported; the specification marks that string form deprecated. Object identities may include `ClientDisplay` with optional `name`, `uri` and `logo_uri`, including a `data:` image URI. Identity and display objects reject unknown fields and cannot combine `walletAddress` with `jwk`.

```python
from open_payments_sdk.models.auth import (
    ClientDirectedIdentity,
    ClientDisplay,
    ClientWalletAddress,
    GrantRequest,
)

access_request = GrantRequest(
    client=ClientWalletAddress(
        walletAddress="https://wallet.example/alice",
        display=ClientDisplay(name="My application"),
    ),
    access_token={"access": [{"type": "incoming-payment", "actions": ["create"]}]},
)
subject_request = GrantRequest(
    client=access_request.client,
    subject={"sub_ids": [{"id": "https://wallet.example/alice", "format": "uri"}]},
    interact={"start": ["redirect"]},
)
directed_request = GrantRequest(
    client=ClientDirectedIdentity(jwk=key_pair.jwks.keys[0]),
    access_token=access_request.access_token,
)
```

Subject information uses exactly one `sub_ids` entry with a string `id` and `format="uri"`. A subject-only request requires interaction. Access-token requests may also include subject information without interaction, following the specification's alternative request shapes. Directed JWK identities cannot include `interact`. Subject and interaction models retain permitted JSON extensions. Optional request fields stay absent when omitted; explicitly supplied nulls are invalid. Wallet and display URI strings are validated without changing their spelling; an existing `AnyUrl` uses its already normalized string value.

Access permissions keep the existing type/action enums and retain permitted JSON extensions. Access lists contain up to three distinct serialized JSON entries; distinct entries may target the same resource type. Actions must be unique. Empty access and action arrays are permitted. Existing URI attributes on access identifiers and outgoing receivers remain `AnyUrl` values, with their existing normalization behavior.

`LimitsOutgoing` accepts receiver and interval fields with debit and/or receive amounts. Each supplied amount uses the shared validated `Amount` contract. Receivers must match the specification's HTTP(S) incoming-payment URL pattern; interval values follow its string contract. Optional known fields stay absent when omitted and reject explicit nulls.

`AccessOutgoing.cardAuthorization` accepts `CardAuthorization` with required `tlvData` and `requestId`, optional `pinBlock`, and optional `pwk` (`PinWorkingKey` with required `key`, `kvc` and `iv`). Providing `pinBlock` requires `pwk`; a PWK may also be supplied alone. These fields require strings, without imposing additional encoding or identifier formats. Card/PWK objects reject unknown fields. Card data and working-key fields are hidden in ordinary representations and validation-error text; explicit `model_dump()` includes them for transmission or application-owned persistence.

`Grant` retains its `.root` wrapper and forwards attributes such as `.cont` and `.access_token` to the selected pending or approved response. Initial responses must contain interaction instructions or an access token, with continuation metadata. Mixed initial states are rejected. Continuation responses use `GrantContinueResponse`: `continue` is required, while access-token and subject results are independently optional, including pending responses with only continuation metadata.

Response models accept the wire `continue` name or legacy `cont` without changing the input dictionary; supplying both is invalid. Python attributes remain `.cont`. Dumps use the wire `continue` name by default; pass `by_alias=False` for Python field names. Permitted JSON extensions are retained. Optional known fields omit absent values and reject explicit nulls. `wait` and `expires_in` require integers, and token values require strings. Token values are hidden in ordinary representations and validation-error text but remain accessible and included in explicit dumps.

`InteractRef()` serializes to an empty continuation request for polling; provide `interact_ref` after completed interaction. `AccessTokenRotationResponse` models the `{ "access_token": ... }` rotation envelope.

See [initial grant requests](#initial-grant-requests) for request examples and the `post_grant_request` compatibility adapter.

