← All guides · Markdown: /guides/python.md

Python: x402 with requests or httpx

Pay per call from Python with the x402 package: a requests Session (or httpx client) that answers 402s with a signed USDC payment.

For: Python 3.10+. Endpoint shape: GET https://shop.lordevo.com/api/quick/<tool>?<input>; (HTTP 402 with x402 terms until paid). All guides: https://shop.lordevo.com/guides

Prerequisites

Pay per call: requests (sync)

Save as lordevo.py. The helper also does the free trial, and is reused by the LangChain, CrewAI and OpenAI Agents guides.

# pip install "x402[requests,evm]" eth_account requests
import json, os, time
import requests
from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client

BASE = "https://shop.lordevo.com"
pay = None  # a requests.Session that pays x402 402s in USDC on Base; without AGENT_WALLET_KEY only free trial calls work
if os.environ.get("AGENT_WALLET_KEY"):
    _x402 = x402ClientSync()
    register_exact_evm_client(_x402, EthAccountSigner(Account.from_key(os.environ["AGENT_WALLET_KEY"])))
    pay = x402_requests(_x402)
_no_trial_until = 0.0  # after "used_up_today", skip the free attempt until 00:00 UTC


class LordevoError(Exception):
    def __init__(self, status, body=None, retry_after=None, message=None):
        self.status, self.body, self.retry_after = status, body, retry_after
        super().__init__(message or (body or {}).get("message") or f"HTTP {status}")


def _answer(r):
    try:
        body = r.json()
    except ValueError:
        body = None
    if r.status_code < 400:
        return body
    raise LordevoError(r.status_code, body if isinstance(body, dict) else None, int(r.headers.get("retry-after") or 0) or None)


def lordevo(tool, params=None, trial=False):
    """One Lordevo call. trial=True asks for a free call first and pays only when no free call is left.
    Raises LordevoError(status, body, retry_after); refused or failed calls are not charged."""
    global _no_trial_until
    url = f"{BASE}/api/quick/{tool}"
    q = {k: str(v) for k, v in (params or {}).items() if v not in (None, "")}
    if trial and time.time() >= _no_trial_until:
        r = requests.get(url, params=q, headers={"accept": "application/json", "x-lordevo-trial": "1"}, timeout=60)
        if r.status_code != 402:
            return _answer(r)
        why = ((r.json() or {}).get("free_trial") or {}).get("status")
        if why in ("used_up_today", "daily_cap_reached"):
            _no_trial_until = (int(time.time()) // 86400 + 1) * 86400
        if pay is None:
            raise LordevoError(402, message=f"No free call left ({why or 'not_eligible'}); set AGENT_WALLET_KEY to pay per call.")
    if pay is None:
        raise LordevoError(402, message="Set AGENT_WALLET_KEY to pay per call, or use trial=True.")
    return _answer(pay.get(url, params=q, headers={"accept": "application/json"}, timeout=60))


def lordevo_tool(tool, params):
    """For agent tools: errors come back as JSON the model can read, instead of an exception."""
    try:
        return json.dumps(lordevo(tool, params, trial=True))
    except LordevoError as e:
        return json.dumps({"error": (e.body or {}).get("error") or f"http_{e.status}", "message": str(e), "retry_after_seconds": e.retry_after, "charged": False})


if __name__ == "__main__":
    print(lordevo("dns-lookup", {"host": "example.com"}, trial=True))

Try it free (no wallet)

Leave AGENT_WALLET_KEY unset and call lordevo(..., trial=True): it sends X-Lordevo-Trial: 1 and no payment (3 free calls per IP per UTC day on tools up to $0.005). With the key set, trial=True uses the free calls first and then pays.

Pay per call: httpx (async)

# pip install "x402[httpx,evm]" eth_account
import asyncio, os
from eth_account import Account
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client

client = x402Client()
register_exact_evm_client(client, EthAccountSigner(Account.from_key(os.environ["AGENT_WALLET_KEY"])))


async def main():
    async with x402HttpxClient(client) as http:
        r = await http.get("https://shop.lordevo.com/api/quick/dns-lookup", params={"host": "example.com"}, headers={"accept": "application/json"})
        await r.aread()
        print(r.status_code, r.json() if r.status_code < 500 else r.text)

asyncio.run(main())

Or use the shop's own client: pip install "lordevo-x402>=0.1.5" (LordevoSync.from_private_key(...), try_free(...); LangChain and CrewAI tools built in).

Errors (nothing is charged on any of these)

lordevo() raises LordevoError with .status, .body and .retry_after; lordevo_tool() returns the same as JSON for agent tools.

Next tools to try

Checked

Written 2026-10-30 against the current public docs:

The snippets follow those docs; they were not executed end to end by the shop. Tell us if something has moved: hello@lordevo.com