Use a single server-side client that sets the environment origin, API key, timeout, idempotency key, and structured error handling. Keep the client out of browser-rendered code. The maintained example uses only Python’s standard library. The same request contract applies when an existing service uses requests or another HTTP client: keep the API key server-side and reuse the same Idempotency-Key when a create response is ambiguous.

Requests

Create hosted sessions from a server-side process. The maintained example sets the API origin, API key, timeout, idempotency key, and structured error handling in one place.

Create a hosted session

Reuse the same idempotency key after a timeout, then retrieve the resulting session before deciding to retry. Verify webhook signatures over raw bytes before JSON parsing and return a fast success response after deduplication:
The complete maintained snippets are snippets/merchant-nextjs-route.ts and snippets/merchant-python-client.py in the repository. A standard-library self-check covers valid/invalid signatures and idempotent retry behavior.