Python SDK v0.5.0
Python SDK
The official Python SDK for Skalor. Built for LangChain, CrewAI, AutoGen, and any Python agent framework.
Quickstart
1
Install
pip install skalor-sdk2
Register your agent (no API key needed)
register.py
from skalor import Client
# Self-service registration - returns an API key
result = Client.register_agent(
"My Research Agent",
platform="langchain",
email="dev@company.com",
)
print(f"Agent ID: {result.agent_id}")
print(f"API Key: {result.api_key}") # Save this!Save the API key securely. You will not see it again.
3
Create a client and check your budget
check_budget.py
from skalor import Client
zc = Client(api_key="zc_your_key_here")
# Check budget before spending
budget = zc.check_budget()
print(f"Can spend: {budget.can_spend}")
print(f"Remaining: ${budget.remaining_usd}")
print(f"Max single payment: ${budget.max_single_payment_usd}")4
Authorize a payment
authorize.py
result = zc.authorize_spend(
amount=0.05,
merchant="api.openai.com",
intent="Purchasing GPT-4o tokens for lead scoring pipeline",
)
if result.approved:
print(f"CLEARED: ${result.amount_usd}")
print(f"Transaction ID: {result.transaction_id}")
# Now safe to call the paid API
else:
print(f"DENIED: {result.denial_reason}")
print(f"Message: {result.message}")All Methods
| Method | Auth | Description |
|---|---|---|
authorize_spend() | Key | Clear 5 fiduciary gates and authorize a payment |
pay_x402_invoice() | Key | Pay an HTTP 402 invoice and get a signed receipt (JWT) |
check_budget() | Key | Query remaining budget, limits, and daily spend |
get_mandate() | Key | Full mandate details (all 5 gate configs) |
list_transactions() | Key | Audit trail with filters (all/approved/denied) |
transfer() | Key | A2A agent-to-agent payment via Tempo |
create_api_key() | Key | Generate a new API key for sub-agents |
Client.register_agent() | None | Self-service agent registration (static method) |
Client.discover() | None | Service discovery - pricing, networks, SDKs |
Examples
View your fiduciary mandate
mandate.py
mandate = zc.get_mandate()
# All 5 gate configs from the CFO
print(f"Kill switch: {mandate.gate_1_kill_switch['status']}")
print(f"Vendors: {mandate.gate_2_vendor_allowlist['authorized_vendors']}")
print(f"Per-tx limit: ${mandate.gate_3_per_transaction_limit['limit_usd']}")
print(f"Daily budget: ${mandate.gate_4_daily_budget['daily_limit_usd']}")
print(f"Human approval: {mandate.gate_5_human_approval['description']}")Query transaction history
transactions.py
history = zc.list_transactions(limit=10, status="approved")
print(f"Total spend: ${history.total_approved_spend_usd}")
for tx in history.transactions:
print(f" ${tx.amount_usd} to {tx.merchant} - {tx.reasoning}")Agent-to-Agent transfer
transfer.py
result = zc.transfer(
recipient_agent_id="550e8400-e29b-41d4-a716-446655440000",
amount=2.50,
intent="Purchasing weather data from DataProvider agent",
)
if result.approved:
print(f"Sent ${result.net_amount_usd} to {result.recipient_name}")
print(f"Fee: ${result.platform_fee_usd} (2.9%)")LangChain integration
langchain_agent.py
from skalor.skalor_tool import SkalorPaymentTool
# Drop into any LangChain agent
tool = SkalorPaymentTool(
agent_id="your-agent-id",
api_key="zc_your_key",
)
# The agent calls this tool when it hits an HTTP 402 paywall
# All 5 fiduciary gates are enforced automaticallyEd25519 DID signing
did_signing.py
from skalor import Client, generate_agent_keypair
# Generate a keypair for cryptographic identity
keys = generate_agent_keypair()
print(f"Public key (register this): {keys['public_key']}")
# Create a client with DID signing enabled
zc = Client(
api_key="zc_your_key",
agent_private_key=keys["private_key"],
)
# Every request is now cryptographically signed
result = zc.authorize_spend(
amount=1.00,
merchant="api.openai.com",
intent="Signed inference call for audit compliance",
)