5 Minutes to Tax-Compliant: AgentTax Quickstart for Python Agents
You built an AI agent that sells services. Congratulations — you owe sales tax. Let's fix that in 5 minutes.
This guide shows you how to add AgentTax to a Python agent so every transaction is tax-compliant before payment settles. No tax expertise required. Just an API call.
What You Need
- An AI agent that sells or buys digital services
- Python 3.8+
requestslibrary (pip install requests)
- An AgentTax API key (free tier: 100 calls/day) — get one at agenttax.io
Step 1: The Core Integration (30 seconds)
Here's the entire AgentTax integration for a seller agent:
import requests
AGENTTAX_URL = "https://agenttax.io/api/v1/calculate"
AGENTTAX_KEY = "atx_live_your_key_here" # or omit for demo mode
def calculate_tax(amount: float, buyer_state: str,
transaction_type: str = "api_access",
counterparty_id: str = "unknown") -> dict:
"""Calculate tax obligation before payment settlement."""
response = requests.post(
AGENTTAX_URL,
json={
"role": "seller",
"amount": amount,
"buyer_state": buyer_state,
"transaction_type": transaction_type,
"counterparty_id": counterparty_id
},
headers={"X-API-Key": AGENTTAX_KEY} if AGENTTAX_KEY else {},
timeout=5
)
return response.json()
That's it. One function. One API call. You now have tax calculation.
Step 2: Integrate Into Your Agent's Transaction Flow
Here's how to insert the tax check into a typical agent sale:
def handle_sale(buyer_id: str, buyer_state: str,
service: str, amount: float):
"""Complete a sale with tax compliance."""
# 1. Calculate tax BEFORE payment
tax_result = calculate_tax(
amount=amount,
buyer_state=buyer_state,
transaction_type="api_access", # or: compute, saas, ai_labor, etc.
counterparty_id=buyer_id
)
# 2. Extract the numbers
tax_amount = tax_result.get("total_tax", 0)
total_charge = amount + tax_amount
# 3. Log what happened
sales_tax = tax_result.get("sales_tax", {})
print(f"Sale: ${amount:.2f} + ${tax_amount:.2f} tax = ${total_charge:.2f}")
print(f"Jurisdiction: {sales_tax.get('jurisdiction', 'N/A')}")
print(f"Rate: {sales_tax.get('rate', 0):.2%}")
print(f"Type: {sales_tax.get('type', 'N/A')}")
# 4. Route payment with tax split
process_payment(
buyer_id=buyer_id,
total=total_charge,
operating_amount=amount,
tax_reserve_amount=tax_amount,
jurisdiction=sales_tax.get("state", buyer_state)
)
return {
"charged": total_charge,
"tax": tax_amount,
"transaction_id": tax_result.get("transaction_id")
}
Step 3: Handle Exemptions
Some transactions will be exempt — the buyer's state doesn't tax digital services, or you don't have nexus there. AgentTax handles this automatically:
def handle_sale_with_exemptions(buyer_id, buyer_state, amount):
tax_result = calculate_tax(amount, buyer_state, "saas", buyer_id)
exemption = tax_result.get("exemption")
if exemption:
# No tax to collect — but log why
print(f"Exempt: {exemption['type']} in {exemption['state']}")
print(f"Reason: {exemption.get('reason', 'N/A')}")
# Charge only the base amount
process_payment(buyer_id=buyer_id, total=amount,
operating_amount=amount, tax_reserve_amount=0)
else:
# Tax applies — collect and route
tax = tax_result["total_tax"]
process_payment(buyer_id=buyer_id, total=amount + tax,
operating_amount=amount, tax_reserve_amount=tax)
Step 4: Add Error Handling
Your agent should never fail a sale because of a tax API issue. Here's the resilient pattern:
def calculate_tax_safe(amount, buyer_state, tx_type, counterparty):
"""Tax calculation with graceful fallback."""
try:
result = calculate_tax(amount, buyer_state, tx_type, counterparty)
if result.get("success"):
return result
# API returned an error — log and fall back
print(f"AgentTax error: {result.get('error', 'Unknown')}")
except requests.exceptions.Timeout:
print("AgentTax timeout — using fallback")
except requests.exceptions.RequestException as e:
print(f"AgentTax unavailable: {e}")
# Fallback: use conservative estimate (highest state rate)
# You'll reconcile later via the dashboard
fallback_rate = 0.0725 # conservative fallback
return {
"success": False,
"total_tax": round(amount * fallback_rate, 2),
"fallback": True,
"note": "Using fallback rate — reconcile via dashboard"
}
Step 5: Buyer Agent Integration
If your agent buys services, the integration is nearly identical — just change the role:
def check_purchase_tax(amount, seller_id, my_state="CA"):
"""Check tax obligations when BUYING services."""
response = requests.post(
AGENTTAX_URL,
json={
"role": "buyer",
"amount": amount,
"buyer_state": my_state,
"transaction_type": "compute",
"counterparty_id": seller_id
},
headers={"X-API-Key": AGENTTAX_KEY} if AGENTTAX_KEY else {},
timeout=5
)
result = response.json()
# Check if use tax applies
use_tax = result.get("use_tax", {})
if use_tax.get("amount", 0) > 0:
print(f"⚠ Use tax owed: ${use_tax['amount']:.2f} to {use_tax['jurisdiction']}")
# Check 1099 threshold
tracking = result.get("tracking_1099", {})
if tracking.get("threshold_exceeded"):
print(f"⚠ 1099 required for {seller_id} (YTD: ${tracking['vendor_ytd_total']:.2f})")
return result
The Complete Pattern
Here's the full pattern your agent should follow for every transaction:
[Transaction Initiated]
↓
[POST /api/v1/calculate] ← One API call
↓
[Tax result returned]
↓
[Route payment with tax split]
↓
[Dashboard updated automatically]
No manual data entry. No spreadsheets. No quarterly scrambles. The API call handles calculation and logging in a single request.
Transaction Types
Choose the right transaction_type for accurate classification:
| Type | Use When |
|------|----------|
| compute | GPU time, processing jobs, batch compute |
| api_access | API calls, inference endpoints, model serving |
| data_purchase | Datasets, embeddings, training data |
| saas | Software subscriptions, cloud tools |
| ai_labor | Work performed by an agent for another agent |
| storage | Data storage, model hosting, vector stores |
Classification matters because taxability varies by type and state. A compute sale might be taxable in Texas but exempt in California.
What Happens Next
Once integrated, your dashboard at agenttax.io tracks everything automatically:
- Sales by state — see where you're selling and your nexus exposure
- Tax collected — amounts routed to tax reserves by jurisdiction
- Use tax owed — buyer-side obligations flagged in real time
- 1099 tracking — vendor totals with threshold alerts
- Export — CSV/JSON for filing season
You went from zero tax compliance to fully instrumented in 5 minutes. Your future self (and your accountant) will thank you.
Get your free API key at agenttax.io and start calculating in minutes.
Sources:
- AgentTax API Documentation, agenttax.io/api/v1/health
- Tax Foundation, "State and Local Sales Tax Rates, 2026"