Python SDK for LetAgentPay — AI agent spending policy middleware for fiat and x402 crypto-micropayments
Project description
letagentpay
Python SDK for LetAgentPay — AI agent spending policy middleware. Set budgets, define spending policies, and control AI agent purchases.
Installation
pip install letagentpay
Quick Start
from letagentpay import LetAgentPay
client = LetAgentPay(token="agt_xxx")
# Create a purchase request
result = client.request_purchase(
amount=15.0,
category="api_calls",
description="OpenAI GPT-4 call",
)
print(result.status) # "auto_approved" / "pending" / "rejected"
# Check budget
budget = client.check_budget()
print(f"Remaining: ${budget.remaining}")
@guard Decorator
Automatically check the spending policy before executing a function:
from letagentpay import guard
@guard(token="agt_xxx", category="api_calls", amount=0.03)
def call_openai(prompt: str) -> str:
return openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
).choices[0].message.content
# Runs only if the policy allows it
result = call_openai("Analyze this document")
x402 Crypto-Micropayments
Authorize on-chain USDC payments via the x402 protocol. Same policy engine, same token — different payment rail.
client = LetAgentPay(token="agt_xxx")
# Agent receives HTTP 402 — ask LAP for authorization
auth = client.x402.authorize(
amount_usd=0.05,
asset="USDC",
network="eip155:8453", # Base mainnet
pay_to="0xMerchant...",
resource_url="https://api.example.com/data",
)
if auth.authorized:
# Sign tx with your own wallet, then report
client.x402.report(
authorization_id=auth.authorization_id,
tx_hash="0xabc123...",
)
else:
print(f"Declined: {auth.reason}")
# Check x402 budget and wallets
budget = client.x402.budget()
# Register wallet address (LAP never holds keys)
client.x402.register_wallet("0x1234...", chain="base")
Environment Variables
export LETAGENTPAY_TOKEN=agt_xxx
export LETAGENTPAY_BASE_URL=https://api.letagentpay.com/api/v1/agent-api # optional
# Token is taken from LETAGENTPAY_TOKEN
client = LetAgentPay()
Security Model
LetAgentPay uses server-side cooperative enforcement. When your agent calls request_purchase(), the request is evaluated by the policy engine on the LetAgentPay server. The agent receives only the result (approved/denied/pending) and cannot:
- Modify its own policies (the
agt_token grants access only to the Agent API) - Override policy check results (they come from the server)
- Approve its own pending requests (only a human can do that via the dashboard)
This is a cooperative model — it protects against budget overruns, category violations, and scheduling mistakes by well-behaved agents. It does not sandbox a malicious agent that has direct access to payment APIs.
Best Practices
- Don't give your agent raw payment credentials (Stripe keys, credit card numbers). LetAgentPay should be the only spending channel
- Use
pending+ manual approval for high-value purchases - Set per-request limits as an additional barrier
- Review the audit trail in the dashboard regularly
Documentation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file letagentpay-0.2.4.tar.gz.
File metadata
- Download URL: letagentpay-0.2.4.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3973b736bc881e676ae3420ba7e07817ba280b7da0cadf2a770902d9b1b0cc7
|
|
| MD5 |
41f860e2811fc5df700218db8868c439
|
|
| BLAKE2b-256 |
41b2b2e8147637a9cf728bd05e2ada2bbe21971100f8b0508e5fa8957c91bb21
|
Provenance
The following attestation bundles were made for letagentpay-0.2.4.tar.gz:
Publisher:
release.yml on LetAgentPay/letagentpay-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
letagentpay-0.2.4.tar.gz -
Subject digest:
f3973b736bc881e676ae3420ba7e07817ba280b7da0cadf2a770902d9b1b0cc7 - Sigstore transparency entry: 1309058772
- Sigstore integration time:
-
Permalink:
LetAgentPay/letagentpay-python@924a4759859aa97d920b1917ffcfc5575fed8af5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LetAgentPay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@924a4759859aa97d920b1917ffcfc5575fed8af5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file letagentpay-0.2.4-py3-none-any.whl.
File metadata
- Download URL: letagentpay-0.2.4-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f83e455acd774c2b70c68c33bcc1a53adc070fc04a9dae2f98cafa9fa5446e32
|
|
| MD5 |
a7ebec7ae2a6c9f8d7a00e83e33a8290
|
|
| BLAKE2b-256 |
7639e056b951136f64896b52ad97792e48918fd9f96485a5fee870548f9ddb6c
|
Provenance
The following attestation bundles were made for letagentpay-0.2.4-py3-none-any.whl:
Publisher:
release.yml on LetAgentPay/letagentpay-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
letagentpay-0.2.4-py3-none-any.whl -
Subject digest:
f83e455acd774c2b70c68c33bcc1a53adc070fc04a9dae2f98cafa9fa5446e32 - Sigstore transparency entry: 1309058842
- Sigstore integration time:
-
Permalink:
LetAgentPay/letagentpay-python@924a4759859aa97d920b1917ffcfc5575fed8af5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LetAgentPay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@924a4759859aa97d920b1917ffcfc5575fed8af5 -
Trigger Event:
push
-
Statement type: