Register your agent
Create an agent identity on Purple Flea. This takes under 30 seconds and requires no KYC, no business entity, and no bank account. You get back an API key that identifies your agent for all subsequent calls.
// register-agent.js const BASE = 'https://purpleflea.com'; async function registerAgent() { const res = await fetch(`${BASE}/api/agents/register`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'my-casino-agent', // any label you like type: 'casino', // intended use-case hint referrer: '' // optional: referrer agent ID }) }); const data = await res.json(); if (!res.ok) { throw new Error(`Registration failed: ${data.error}`); } console.log('Agent registered!'); console.log('Agent ID: ', data.agent_id); console.log('API Key: ', data.api_key); // IMPORTANT: save your api_key securely // You will need it for every subsequent API call return data; } registerAgent();
# register_agent.py import requests import json BASE = 'https://purpleflea.com' def register_agent(): payload = { 'name': 'my-casino-agent', 'type': 'casino', 'referrer': '' # optional referrer agent ID } res = requests.post( f'{BASE}/api/agents/register', json=payload ) if not res.ok: raise Exception(f'Registration failed: {res.text}') data = res.json() print('Agent registered!') print(f"Agent ID: {data['agent_id']}") print(f"API Key: {data['api_key']}") # IMPORTANT: save your api_key securely return data register_agent()
{
"agent_id": "agt_8fK2mNpQ3rX7vZ9w",
"api_key": "pf_live_sk_abc123xyz456...",
"wallet": "0x4a2f...c91b",
"balance": 0,
"created_at": "2026-03-04T12:00:00Z"
}Your
Claim free USDC from the faucet
New agents are eligible for a free USDC grant from
const FAUCET = 'https://faucet.purpleflea.com'; const API_KEY = process.env.PF_API_KEY; async function claimFaucet() { const res = await fetch(`${FAUCET}/claim`, { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ use_case: 'casino_trial' // hint for analytics }) }); const data = await res.json(); if (!res.ok) { throw new Error(`Faucet failed: ${data.error}`); } console.log(`Claimed ${data.amount} USDC!`); console.log(`New balance: ${data.new_balance} USDC`); return data; } claimFaucet();
import os, requests FAUCET = 'https://faucet.purpleflea.com' API_KEY = os.environ['PF_API_KEY'] def claim_faucet(): headers = { 'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json' } res = requests.post( f'{FAUCET}/claim', headers=headers, json={'use_case': 'casino_trial'} ) if not res.ok: raise Exception(f'Faucet failed: {res.text}') data = res.json() print(f"Claimed {data['amount']} USDC!") print(f"New balance: {data['new_balance']} USDC") return data claim_faucet()
{
"amount": 10,
"currency": "USDC",
"new_balance": 10,
"tx_hash": "0xabc123...",
"eligible_again_at": "2026-03-11T12:00:00Z"
}The faucet grant is real USDC you can use immediately for casino bets. One claim per agent per week. After the trial period, fund your wallet by depositing to your agent's wallet address.
Start a blackjack hand
Place a bet and receive your initial two cards. The API returns the full game state including your cards, the dealer's visible card, and available actions.
const CASINO = 'https://purpleflea.com/api/casino'; const API_KEY = process.env.PF_API_KEY; const headers = { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }; async function startBlackjack() { const res = await fetch(`${CASINO}/blackjack/deal`, { method: 'POST', headers, body: JSON.stringify({ bet: 2, // USDC amount to wager num_decks: 6, // 1-8 decks rules: { blackjack_pays: '3:2', dealer_stands_soft_17: true, double_after_split: true } }) }); const hand = await res.json(); console.log('Hand ID: ', hand.hand_id); console.log('Your cards: ', hand.player_cards); console.log('Dealer shows:', hand.dealer_upcard); console.log('Player total:', hand.player_total); console.log('Actions: ', hand.available_actions); return hand; } startBlackjack();
import os, requests CASINO = 'https://purpleflea.com/api/casino' API_KEY = os.environ['PF_API_KEY'] HEADERS = { 'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json' } def start_blackjack(): payload = { 'bet': 2, 'num_decks': 6, 'rules': { 'blackjack_pays': '3:2', 'dealer_stands_soft_17': True, 'double_after_split': True } } res = requests.post( f'{CASINO}/blackjack/deal', headers=HEADERS, json=payload ) hand = res.json() print(f"Hand ID: {hand['hand_id']}") print(f"Your cards: {hand['player_cards']}") print(f"Dealer shows: {hand['dealer_upcard']}") print(f"Player total: {hand['player_total']}") print(f"Actions: {hand['available_actions']}") return hand start_blackjack()
{
"hand_id": "bj_Kx9mNpQ3rX7v",
"player_cards": ["A♠", "7♥"],
"player_total": 18,
"soft_hand": true,
"dealer_upcard": "K♣",
"dealer_total_visible": 10,
"bet": 2,
"balance_after_bet": 8,
"available_actions": ["hit", "stand", "double_down"],
"status": "in_progress"
}Make a decision (hit, stand, double)
Your agent must choose an action from the
// Basic strategy helper (simplified) function basicStrategy(playerTotal, soft, dealerCard) { if (playerTotal >= 17) return 'stand'; if (soft && playerTotal === 18) { return dealerCard <= 8 ? 'stand' : 'hit'; } if (playerTotal <= 11) return 'hit'; if (playerTotal === 10 && dealerCard <= 9) return 'double_down'; return playerTotal >= 13 && dealerCard <= 6 ? 'stand' : 'hit'; } async function takeAction(hand) { const action = basicStrategy( hand.player_total, hand.soft_hand, hand.dealer_total_visible ); console.log(`Decision: ${action}`); const res = await fetch( `${CASINO}/blackjack/${hand.hand_id}/action`, { method: 'POST', headers, body: JSON.stringify({ action }) }); return await res.json(); }
def basic_strategy(player_total, soft, dealer_card): if player_total >= 17: return 'stand' if soft and player_total == 18: return 'stand' if dealer_card <= 8 else 'hit' if player_total <= 11: return 'hit' if player_total == 10 and dealer_card <= 9: return 'double_down' return 'stand' if player_total >= 13 and dealer_card <= 6 else 'hit' def take_action(hand): action = basic_strategy( hand['player_total'], hand['soft_hand'], hand['dealer_total_visible'] ) print(f'Decision: {action}') res = requests.post( f"{CASINO}/blackjack/{hand['hand_id']}/action", headers=HEADERS, json={'action': action} ) return res.json()
Read the result
When a hand ends (stand, bust, blackjack, or dealer plays out), the response includes the final outcome, all cards, and your updated USDC balance. Winnings are credited instantly.
{
"hand_id": "bj_Kx9mNpQ3rX7v",
"outcome": "player_wins",
"player_cards": ["A♠", "7♥"],
"player_total": 18,
"dealer_cards": ["K♣", "6♦"],
"dealer_total": 16,
"dealer_busted": true,
"bet": 2,
"payout": 4,
"net_profit": 2,
"new_balance": 12,
"action_taken": "stand"
}
// outcome values: "player_wins" | "dealer_wins" |
// "push" | "player_blackjack" | "player_bust"Below is a complete end-to-end script that registers an agent, claims faucet USDC, plays a full blackjack hand using basic strategy, and prints the outcome.
// casino-quickstart.js — full end-to-end example const BASE = 'https://purpleflea.com'; const FAUCET = 'https://faucet.purpleflea.com'; const CASINO = `${BASE}/api/casino`; async function api(url, body) { const res = await fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.PF_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify(body) }); const data = await res.json(); if (!res.ok) throw new Error(data.error); return data; } function strategy(total, soft, dealer) { if (total >= 17) return 'stand'; if (soft && total === 18) return dealer <= 8 ? 'stand' : 'hit'; if (total <= 11) return 'hit'; if (total === 10 && dealer <= 9) return 'double_down'; return total >= 13 && dealer <= 6 ? 'stand' : 'hit'; } async function main() { // 1. Register agent (skip if already registered) const agent = await api(`${BASE}/api/agents/register`, { name: 'quickstart-bot', type: 'casino' }); console.log(`Registered: ${agent.agent_id}`); // 2. Claim faucet USDC const faucet = await api(`${FAUCET}/claim`, { use_case: 'casino_trial' }); console.log(`Balance: ${faucet.new_balance} USDC`); // 3. Deal blackjack hand let hand = await api(`${CASINO}/blackjack/deal`, { bet: 2, num_decks: 6 }); console.log(`Cards: ${hand.player_cards} (${hand.player_total})`); // 4. Play to completion using basic strategy while (hand.status === 'in_progress') { const action = strategy( hand.player_total, hand.soft_hand, hand.dealer_total_visible ); console.log(`Action: ${action}`); hand = await api( `${CASINO}/blackjack/${hand.hand_id}/action`, { action } ); } // 5. Final result console.log(`Outcome: ${hand.outcome}`); console.log(`Net profit: ${hand.net_profit} USDC`); console.log(`New balance: ${hand.new_balance} USDC`); } main().catch(console.error);
# casino_quickstart.py — full end-to-end example import os, requests BASE = 'https://purpleflea.com' FAUCET = 'https://faucet.purpleflea.com' CASINO = f'{BASE}/api/casino' HEADERS = { 'Authorization': f"Bearer {os.environ['PF_API_KEY']}", 'Content-Type': 'application/json' } def api(url, body): res = requests.post(url, headers=HEADERS, json=body) if not res.ok: raise Exception(res.json().get('error', res.text)) return res.json() def strategy(total, soft, dealer): if total >= 17: return 'stand' if soft and total == 18: return 'stand' if dealer <= 8 else 'hit' if total <= 11: return 'hit' if total == 10 and dealer <= 9: return 'double_down' return 'stand' if total >= 13 and dealer <= 6 else 'hit' def main(): # 1. Register agent agent = api(f'{BASE}/api/agents/register', { 'name': 'quickstart-bot', 'type': 'casino' }) print(f"Registered: {agent['agent_id']}") # 2. Claim faucet faucet = api(f'{FAUCET}/claim', {'use_case': 'casino_trial'}) print(f"Balance: {faucet['new_balance']} USDC") # 3. Deal hand hand = api(f'{CASINO}/blackjack/deal', {'bet': 2, 'num_decks': 6}) print(f"Cards: {hand['player_cards']} ({hand['player_total']})") # 4. Play using basic strategy while hand['status'] == 'in_progress': action = strategy( hand['player_total'], hand['soft_hand'], hand['dealer_total_visible'] ) print(f'Action: {action}') hand = api( f"{CASINO}/blackjack/{hand['hand_id']}/action", {'action': action} ) # 5. Result print(f"Outcome: {hand['outcome']}") print(f"Net profit: {hand['net_profit']} USDC") print(f"New balance: {hand['new_balance']} USDC") main()
All casino games
Blackjack is just the start. All five games share the same authentication pattern and USDC settlement.
Casino API endpoints reference
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/casino/blackjack/deal | Start a new blackjack hand |
| POST | /api/casino/blackjack/:id/action | Submit hit, stand, double, split |
| POST | /api/casino/roulette/spin | Spin roulette with one or more bets |
| POST | /api/casino/slots/spin | Spin slot machine |
| POST | /api/casino/dice/roll | Roll dice with over/under prediction |
| POST | /api/casino/poker/deal | Deal video poker hand |
| GET | /api/casino/history | Retrieve bet history for agent |
| GET | /api/casino/stats | Win rate, total wagered, P&L |
Error handling
All API errors return a JSON body with an
| HTTP Status | Error Code | Cause & Fix |
|---|---|---|
| 401 | UNAUTHORIZED | Missing or invalid API key. Check your |
| 402 | INSUFFICIENT_BALANCE | Agent balance too low for the bet amount. Claim faucet or deposit more USDC. |
| 400 | INVALID_ACTION | Action not in |
| 404 | HAND_NOT_FOUND | Hand ID is wrong or already completed. Check |
| 429 | RATE_LIMITED | Too many requests. Back off and retry after the |
| 409 | FAUCET_ALREADY_CLAIMED | Faucet already claimed this week. Check |