AgentLayer Python SDK
The official Python SDK for AgentLayer — the financial governance layer for AI agents.
Installation
pip install agentlayer-sdk
Quick Start
from agentlayer import AgentLayer
agent = AgentLayer(token="agt_live_xxxxxxxxxxxxxxxxxxxxxxxx")
# Pay autonomously
result = agent.pay(10, "Market data purchase")
print(result["transaction"]["tx_id"])
Agent API
Initialize with your agent token (generated from the dashboard):
agent = AgentLayer(
token="agt_live_xxx", # required
base_url="https://..." # optional, defaults to AgentLayer production
)
agent.pay(amount, description)
Execute a payment from the agent wallet.
result = agent.pay(10, "API call fee")
# {
# "success": True,
# "transaction": { "tx_id", "amount", "description", "timestamp", "balance_after" },
# "agent": { "agent_id", "agent_name", "balance_after", "trust_level" }
# }
agent.balance()
Check the agent's current balance and spend limits.
bal = agent.balance()
# {
# "balance": 990,
# "spent_today": 10,
# "max_daily": 500,
# "max_per_transaction": 100,
# "trust_level": "verified",
# "did": "did:agentlayer:..."
# }
agent.identity()
Get the agent's cryptographic identity (KYA report).
identity = agent.identity()
# {
# "did": "did:agentlayer:bd18c2df...",
# "trust_level": "verified",
# "trust_score": 30,
# "certificate_valid": { "valid": True, "expired": False }
# }
agent.can_pay(amount)
Check if a payment is possible before executing it.
check = agent.can_pay(50)
# {
# "can_pay": True,
# "balance": 990,
# "remaining_today": 490,
# "max_per_transaction": 100
# }
agent.safe_pay(amount, description)
Pay only if possible — returns a blocked reason instead of raising.
result = agent.safe_pay(500, "Large purchase")
if not result["success"]:
print(result["reason"]) # 'Exceeds per-transaction limit ($100)'
Admin API
Initialize with your API key for server-side operations:
from agentlayer import AgentLayerAdmin
admin = AgentLayerAdmin(api_key="al_live_xxxxxxxxxxxxxxxxxxxxxxxx")
admin.create_wallet(agent_name, max_per_transaction, max_daily)
wallet = admin.create_wallet("Procurement Agent", 100, 500)
# { "agent_id", "agent_name", "balance", "kya": { "did", "trust_level" } }
admin.list_wallets()
wallets = admin.list_wallets()
admin.pay(agent_id, amount, description)
result = admin.pay("agent-id", 25, "Payment")
admin.verify_agent(agent_id)
verification = admin.verify_agent("agent-id")
# { "verified": True, "did", "trust_level", "certificate_valid" }
admin.delegate(parent_agent_id, child_agent_name, budget, max_per_transaction)
delegation = admin.delegate("parent-id", "Sub Agent", 100, 20)
# { "success": True, "child_wallet", "delegation_chain" }
Error Handling
from agentlayer import AgentLayer, AgentLayerError
agent = AgentLayer(token="agt_live_xxx")
try:
result = agent.pay(1000, "Too much")
except AgentLayerError as e:
print(e) # 'Dépasse la limite par transaction (max $100)'
print(e.status) # 403
Real-world Example
from agentlayer import AgentLayer
import os
agent = AgentLayer(token=os.environ["AGENTLAYER_TOKEN"])
def buy_market_data(data_source, price):
# Check before paying
check = agent.can_pay(price)
if not check["can_pay"]:
print(f"Cannot pay: ${check['remaining_today']} remaining today")
return None
# Pay autonomously
result = agent.safe_pay(price, f"Market data: {data_source}")
if not result["success"]:
print(f"Blocked: {result['reason']}")
return None
print(f"Paid ${price} for {data_source} — TX: {result['transaction']['tx_id']}")
return result["transaction"]
# Your agent runs autonomously
buy_market_data("Bloomberg API", 15)
LangChain Integration Example
from langchain.tools import tool
from agentlayer import AgentLayer
import os
agent = AgentLayer(token=os.environ["AGENTLAYER_TOKEN"])
@tool
def pay_for_api(amount: float, description: str) -> str:
"""Pay for an external API or service using AgentLayer."""
result = agent.safe_pay(amount, description)
if result["success"]:
return f"Payment successful. TX: {result['transaction']['tx_id']}"
return f"Payment blocked: {result['reason']}"
# Use in your LangChain agent
# agent_executor.run("Pay $5 for the weather API")
Links
License
MIT
Metadata
Release files for agentlayer-sdk-py 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| agentlayer_sdk_py-1.0.0.tar.gz | 4.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentlayer_sdk_py-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / agentlayer_sdk_py-1.0.0.tar.gz
| Download URL | agentlayer_sdk_py-1.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
784962abea502a2e633fefe69c5a9f84b768176521608820d4183f83ab694759
|
|
BLAKE2b-256 checksum How to use checksums |
595103732fa2638bd61939239a037cb54e83411e60be696eecd08ed67f5fd55d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Release files / agentlayer_sdk_py-1.0.0-py3-none-any.whl
| Download URL | agentlayer_sdk_py-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6900b1cf22312db020fdd15a63df287c381ca5302a4fcb7771a05bb9069afbcf
|
|
BLAKE2b-256 checksum How to use checksums |
025a42e8bb160d89e8326ca93b6777b3984e869ca438775d3fa8b37734740940
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.12
|
Security for agentlayer-sdk-py 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.