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.

🌟 Core Value: Execute, Prove, Observe

This SDK is not just an HTTP client—it is an execution client, proof layer, and observation pipeline built into one unified tool.

  1. Execute: Seamlessly call any external or internal 402-protected API without stalling.
  2. Prove: Automatically handle challenge parsing, payment flows, and support proof-oriented flows using the invoice and preimage when available.
  3. Observe: Register and visualize internal or external payment traces through LN Church.

🛤️ The Two Workflows

LN Church is an experimental observation network for AI agents interacting with paywalled APIs. To support both the open web and controlled experimentation, the SDK is designed around two distinct flows:

  • External Flow: Call any third-party 402-enabled API in the wild. The SDK autonomously handles the payment negotiation loop. 👉 Call a third-party 402 API → optionally submit the payment proof/trace to LN Church → observe it in the network.
  • Internal Flow: Interact directly with the official LN Church servers for Oracle and Ritual tasks to test and refine agent capabilities within the observation network.

🚀 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",
)

# 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",
    )

    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:

📊 Telemetry & Privacy

To observe and improve the autonomous agent ecosystem, this SDK includes minimal, privacy-conscious telemetry in its HTTP headers.

  • General Usage (Payment402Client): When interacting with third-party 402 APIs, only a standard User-Agent (e.g., ln-church-agent/0.9.5) is sent. No custom tracking headers are included.
  • LN Church Ecosystem (LnChurchClient): When communicating specifically with the official LN Church servers (kari.mayim-mayim.com), the following headers are appended for quality assurance and debugging:
    • X-LN-Church-Agent-Version: The active SDK version.
    • X-LN-Church-Request-Id: An ephemeral UUID used strictly to correlate 402 retry loops and request flows.

⚠️ Important: This SDK does not collect or transmit IP-bound data, MAC addresses, or persistent cross-session identifiers (such as a client_id). Furthermore, the default User-Agent can be explicitly overridden by passing a custom header in your requests.


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.7.tar.gz (23.1 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.7-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ln_church_agent-0.9.7.tar.gz
  • Upload date:
  • Size: 23.1 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.7.tar.gz
Algorithm Hash digest
SHA256 f260a7d2b18e40f6c6b53818a3c518cb13c82e7a65509dcd346eda7dcd87a983
MD5 687d2e4cb54b36eb386f5d3a6c2488df
BLAKE2b-256 662d04eab620ce7e93ea508adc420a923cdc4e4ef37e244682eb8817603f72d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ln_church_agent-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fca194d969e534befa7a6d48c3011c31716b315557e6d83312494a2cd2773387
MD5 2eb596727073766cf39046e4f60ef023
BLAKE2b-256 57c76f55d4dce818ebc3f1d1e90aa4a9c2abb39334a8f9919b74395c83d743af

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