Complete API reference for integrating x402 autonomous payments with Thirdfy.
Open Access: No API key required! These endpoints are open to any AI agent. Authentication is handled through on-chain USDC payments on Base.
Find Thirdfy's x402 service metadata:
GET https://api.thirdfy.com/api/v1/credits/x402-metadata
Returns available credit packages and payment details.
Purchase credits using x402 protocol:
POST https://api.thirdfy.com/api/v1/credits/buy-with-x402
Content-Type: application/json
{
"sku": "credits_1000",
"userAddress": "0xYOUR_WALLET_ADDRESS"
}
| SKU | Credits | Price (USDC) |
|---|
credits_100 | 100 | 2.00 |
credits_1000 | 1,000 | 18.00 |
credits_10000 | 10,000 | 160.00 |
First call returns HTTP 402 with payment challenge:
{
"x402Challenge": {
"invoiceId": "inv_credits_1000_abc123",
"amount": "18",
"recipient": "0x572D1443f0aAfd492E396516ED26Dc269C516fd7",
"currency": "USDC",
"network": "base"
}
}
Transfer USDC to the recipient address on Base:
const tx = await usdcContract.transfer(
challenge.recipient,
parseUnits(challenge.amount, 6)
);
Retry request with payment proof:
POST https://api.thirdfy.com/api/v1/credits/buy-with-x402
Content-Type: application/json
X-Payment-Receipt: 0xYOUR_TX_HASH
X-Invoice-Id: inv_credits_1000_abc123
{
"sku": "credits_1000",
"userAddress": "0xYOUR_WALLET_ADDRESS"
}
Response (HTTP 200):
{
"success": true,
"credits": 1000,
"balance": 1000,
"message": "✅ Successfully purchased 1000 credits"
}
- Currency: USDC on Base
- Network: Base (Chain ID 8453)
- Settlement: ~2 seconds
- Fees: No protocol fees
- Payment Address:
0x572D1443f0aAfd492E396516ED26Dc269C516fd7
import requests
from web3 import Web3
THIRDFY_API = "https://api.thirdfy.com"
MY_WALLET = "0xYOUR_WALLET_ADDRESS"
# 1. Request purchase
response = requests.post(
f"{THIRDFY_API}/api/v1/credits/buy-with-x402",
json={"sku": "credits_1000", "userAddress": MY_WALLET}
)
challenge = response.json()['x402Challenge']
# 2. Pay USDC on Base
w3 = Web3(Web3.HTTPProvider("https://mainnet.base.org"))
usdc = w3.eth.contract(address=USDC_BASE, abi=ERC20_ABI)
tx_hash = usdc.functions.transfer(
challenge['recipient'],
int(float(challenge['amount']) * 1e6)
).transact({'from': MY_WALLET})
w3.eth.wait_for_transaction_receipt(tx_hash)
# 3. Confirm purchase
response = requests.post(
f"{THIRDFY_API}/api/v1/credits/buy-with-x402",
json={"sku": "credits_1000", "userAddress": MY_WALLET},
headers={
"X-Payment-Receipt": tx_hash.hex(),
"X-Invoice-Id": challenge['invoiceId']
}
)
print(f"Credits: {response.json()['credits']}")
print(f"Balance: {response.json()['balance']}")