Skip to main content

A Python reference client for HTTP 402 settlement across x402, L402, MPP, and fallback flows.

Project description

ln-church-agent

Python SDK for calling L402 / HTTP 402 pay-per-use APIs with automatic payment, retry, and async support.

Designed for Autonomous AI Agents. Implementing machine-to-machine payments from scratch is fragile: agents must parse HTTP 402 challenges, handle signing, complete payment, and retry correctly without falling into hallucinated crypto flows. This SDK abstracts that loop into a single client call. It turns Probe → Pay → Execute into a reliable execution path for agents—available in both sync and async execution models. It is also used in LN Church, an experimental observation ground for AI agents interacting with paywalled APIs in the wild.


🚀 Quickstart (3-step)

1. Install

pip install ln-church-agent

2. Configure & Call (Sync)

Call any 402-protected API. The SDK handles the challenge, payment, and retry under the hood.

from ln_church_agent import Payment402Client

client = Payment402Client(
    base_url="[https://your-402-api.com](https://your-402-api.com)",
)

# Detects 402 -> Pays invoice -> Retries -> Returns JSON
result = client.execute_request(
    method="POST",
    endpoint="/api/protected",
    payload={"input": "hello"}
)

print(result)

3. Configure & Call (Async)

For agent runtimes that need concurrent execution, async is supported in v0.9.0+.

import asyncio
from ln_church_agent import Payment402Client

async def main():
    client = Payment402Client(
        base_url="[https://your-402-api.com](https://your-402-api.com)",
    )

    result = await client.execute_request_async(
        method="POST",
        endpoint="/api/protected",
        payload={"input": "hello"}
    )

    print(result)

asyncio.run(main())

⚠️ What this solves

When an AI Agent hits HTTP 402 Payment Required, it often stalls, crashes, or invents invalid payment/signing behavior.

  • Why this is hard: Handling 402 flows means parsing challenge headers, extracting payment instructions, coordinating wallets, signing correctly, and retrying in the right order.
  • What this SDK does: It reduces that economic negotiation to a normal HTTP client call, with typed responses and built-in retry guardrails.

As of v0.9.0, the same economic loop is available in both sync and async execution paths.


📚 Detailed Documentation

Explore the full capabilities of the agentic economic loop:


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ln_church_agent-0.9.2.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ln_church_agent-0.9.2-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file ln_church_agent-0.9.2.tar.gz.

File metadata

  • Download URL: ln_church_agent-0.9.2.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ln_church_agent-0.9.2.tar.gz
Algorithm Hash digest
SHA256 64db6c54a76ae0c773adfef54429614a49061fbaf9ac4ece455665f1fcb028d0
MD5 5a5df1fad99cb2b68c04dd839ea0ad70
BLAKE2b-256 2725b9945f814603e3d6bdb5051be17f836aa9d0b608d6575b70a9ea80c6675a

See more details on using hashes here.

File details

Details for the file ln_church_agent-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ln_church_agent-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5806fdb0d3708b350f91244f8555611daeb638ebd0c6316d8d3b736e58ec97e0
MD5 92c824aba6aef26a08ced8e8fbb2cc9f
BLAKE2b-256 b03eabefb3839ecfe7f92c48702b7dc89c6da00d9be0bd481f3bfd75604f3c86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page