Skip to main content

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

Download files

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

Source Distribution

agentlayer_sdk_py-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

agentlayer_sdk_py-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file agentlayer_sdk_py-1.0.0.tar.gz.

File metadata

  • Download URL: agentlayer_sdk_py-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for agentlayer_sdk_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 784962abea502a2e633fefe69c5a9f84b768176521608820d4183f83ab694759
MD5 4a02dbb5a412adf3b31e1f0006166f28
BLAKE2b-256 595103732fa2638bd61939239a037cb54e83411e60be696eecd08ed67f5fd55d

See more details on using hashes here.

File details

Details for the file agentlayer_sdk_py-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentlayer_sdk_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6900b1cf22312db020fdd15a63df287c381ca5302a4fcb7771a05bb9069afbcf
MD5 ddae005c1fe25cf6a75a054163275c59
BLAKE2b-256 025a42e8bb160d89e8326ca93b6777b3984e869ca438775d3fa8b37734740940

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