Python SDK for Tab - Micropayments for AI Agents
Project description
Tab Payments SDK
Python SDK for Tab - Micropayments for AI Agents.
Installation
pip install tab-payments
Quick Start
from tab_payments import TabClient
# Initialize with your API key
client = TabClient(api_key="tab_live_xxx")
# Check your balance
balance = client.balance()
print(f"Balance: {balance['balance_formatted']}")
# Pay another agent
payment = client.pay(
to="agent_abc123",
amount_microcents=5_000_000, # $0.05
memo="Tool usage fee"
)
print(f"Payment token: {payment['payment_token']}")
# Verify a payment (as a tool provider)
result = client.verify(payment_token="tab_pay_xxx")
if result['valid']:
print(f"Payment verified from {result['from_agent']}")
Async Usage
from tab_payments import AsyncTabClient
async with AsyncTabClient(api_key="tab_live_xxx") as client:
balance = await client.balance()
print(f"Balance: {balance['balance_formatted']}")
Understanding Microcents
Tab uses microcents for sub-cent precision:
- 1 cent = 1,000,000 microcents
- $1.00 = 100,000,000 microcents
- $0.001 = 1,000 microcents
Error Handling
from tab_payments import (
TabClient,
TabError,
InsufficientBalanceError,
InvalidPaymentError,
AuthenticationError,
)
client = TabClient(api_key="tab_live_xxx")
try:
payment = client.pay(to="agent_xxx", amount_microcents=1_000_000)
except InsufficientBalanceError:
print("Not enough balance!")
except InvalidPaymentError:
print("Invalid payment parameters")
except AuthenticationError:
print("Invalid API key")
except TabError as e:
print(f"Tab error: {e.message}")
API Reference
TabClient
balance() -> dict
Returns your current balance.
Response:
{
"agent_id": "agent_xxx",
"balance_microcents": 100000000,
"balance_formatted": "$1.00"
}
pay(to: str, amount_microcents: int, memo: str = None) -> dict
Transfer microcents to another agent.
Response:
{
"id": "txn_xxx",
"payment_token": "tab_pay_xxx",
"amount_microcents": 5000000,
"balance_after_microcents": 95000000
}
verify(payment_token: str, expected_amount_microcents: int = None) -> dict
Verify a payment token (for tool providers).
Response:
{
"valid": True,
"from_agent": "agent_xxx",
"amount_microcents": 5000000
}
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
tab_payments-0.1.0.tar.gz
(3.8 kB
view details)
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 tab_payments-0.1.0.tar.gz.
File metadata
- Download URL: tab_payments-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fbb66aec3ae7e044247d8586c03edf0dfc1b156496cbdfe2119cb5dd60bacd2
|
|
| MD5 |
4fe1501437cef36799234da8e1727046
|
|
| BLAKE2b-256 |
a41dcfc2d30b6b6ebda6d2e1d95e26c05ca9f77c6bfd6d74599f0b72520ba36e
|
File details
Details for the file tab_payments-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tab_payments-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5527498266e7321f277288f8e3841c6ed88c9b7f45bb8df78d8fd8cc57228f7e
|
|
| MD5 |
f220e037541f8dfecd331f706aa6354a
|
|
| BLAKE2b-256 |
7fcac534ec68e5045163a82b8405b65dc6c96a0ce0d1f77fe3c3bff8c7037c5a
|