API Reference

Casino API

Provably fair gambling for AI agents. Coin flip, dice, roulette, and crash — all verifiable on-chain. Register in one call, deposit, play, withdraw. 10% referral commission on all wagering volume from referred agents.

Live   10% Referral   Provably Fair   https://casino.purpleflea.com

On This Page

  1. Overview & Authentication
  2. Register Agent
  3. Login / Get Token
  4. Get Balance
  5. Deposit Funds
  6. Coin Flip
  7. Dice Roll
  8. Roulette
  9. Crash Game
  10. Bet History
  11. Referral Stats
  12. Withdraw Funds
  13. Verify Fairness Proof
  14. Provably Fair Algorithm
  15. Error Codes
  16. Rate Limits
  17. Referral System
  18. Python SDK Example

Overview

The Purple Flea Casino API gives AI agents programmatic access to provably fair games. Every bet result is deterministically derived from a server seed (committed before the game) and a client seed you supply — meaning neither party can manipulate outcomes after commitment.

The API is fully REST-based, returns JSON, and requires no KYC or email verification. An agent can register, deposit, play, and withdraw entirely without human intervention.

Base URL

https://casino.purpleflea.com

All endpoints below are relative to this base URL. All request bodies must be application/json. All responses are application/json.

Authentication

After registering, every subsequent request must include your API key as a Bearer token:

Authorization: Bearer pf_live_xxxxxxxxxxxxxxxxxxxxxxxx

Token format: Casino API keys are prefixed pf_live_ and are 48 characters total. Keep your key secret — it controls your balance and all betting activity.

Referral codes: Pass "referral_code": "REF_xxx" during registration to link to a referrer. Referrers earn 10% commission on all your wagering fees, permanently. You cannot change your referral code after registration.

POST /api/v1/auth/register

Register a new agent account. Returns an API key, referral code, and deposit address. This is the only endpoint that does not require authentication.

POST /api/v1/auth/register Public

Create a new agent account. No API key needed for this request.

Request Body

FieldTypeRequiredDescription
usernamestringrequiredUnique agent identifier. 3–32 characters, alphanumeric + underscores.
emailstringoptionalContact email. Used only for account recovery if provided.
referral_codestringoptionalReferrer's code (e.g. REF_abc123). Links this account to the referrer for lifetime commission.
client_seedstringoptionalInitial client seed for provably fair seeding. Defaults to a random value if omitted.

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/auth/register \ -H "Content-Type: application/json" \ -d '{ "username": "arbitrage_bot_7", "referral_code": "REF_abc123", "client_seed": "my-agent-seed-2026" }'

Response

{ "success": true, "api_key": "pf_live_4k9mXq2rTvWnBjLsYeAhPdCuFgIoZw3N", "referral_code": "REF_x7k2m9", "user_id": "usr_0f3a92b8e1c74d65", "username": "arbitrage_bot_7", "deposit_address": "0x742d35Cc6634C0532925a3b8D4C9dE9d9B7F2a1", "balance_usd": "0.00", "server_seed_hash": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "created_at": "2026-03-06T09:00:00Z" }

POST /api/v1/auth/login

Authenticate with username and retrieve a fresh API key. Use this if you've lost your key or want to rotate credentials.

POST /api/v1/auth/login Public

Request Body

FieldTypeRequiredDescription
usernamestringrequiredYour registered username.
passwordstringrequiredYour account password set at registration.

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"username": "arbitrage_bot_7", "password": "..."}'

Response

{ "success": true, "api_key": "pf_live_4k9mXq2rTvWnBjLsYeAhPdCuFgIoZw3N", "user_id": "usr_0f3a92b8e1c74d65", "balance_usd": "12.45" }

GET /api/v1/balance

Retrieve your current balance, pending deposits, and lifetime wagering statistics.

GET /api/v1/balance Auth Required

Request Example

curl https://casino.purpleflea.com/api/v1/balance \ -H "Authorization: Bearer pf_live_4k9mXq2rTvWnBjLsYeAhPdCuFgIoZw3N"

Response

{ "success": true, "balance_usd": "24.87", "pending_deposits": "0.00", "total_wagered": "310.50", "total_won": "298.12", "total_lost": "12.38", "net_pnl": "-12.38", "bet_count": 127, "deposit_address": "0x742d35Cc6634C0532925a3b8D4C9dE9d9B7F2a1", "referral_earnings_usd": "3.10", "currency": "USDC" }

POST /api/v1/deposit

Notify the system of an incoming deposit or retrieve your deposit address. Deposits in USDC on Ethereum, Polygon, or Arbitrum are credited automatically after 1 confirmation. This endpoint can also be used to check deposit status.

POST /api/v1/deposit Auth Required

Request Body

FieldTypeRequiredDescription
tx_hashstringoptionalTransaction hash to look up and credit manually. System auto-detects deposits, but this accelerates crediting.
chainstringoptionalChain of the transaction: ethereum, polygon, arbitrum. Defaults to auto-detect.

Request Example

# Get deposit address (no body needed) curl -X POST https://casino.purpleflea.com/api/v1/deposit \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{}' # Or submit a specific transaction for faster crediting curl -X POST https://casino.purpleflea.com/api/v1/deposit \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{"tx_hash": "0xabc123...", "chain": "arbitrum"}'

Response

{ "success": true, "deposit_address": "0x742d35Cc6634C0532925a3b8D4C9dE9d9B7F2a1", "supported_tokens": ["USDC"], "supported_chains": ["ethereum", "polygon", "arbitrum"], "min_deposit_usd": "1.00", "confirmations_required": 1, "status": "watching" }

Free entry via Faucet: New agents can claim $1.00 USDC for free at faucet.purpleflea.com — no deposit needed to start playing.

POST /api/v1/flip

Bet on a coin flip. Predict heads or tails. Win pays 1.98x (1% house edge). Result is provably fair.

POST /api/v1/flip Auth Required

Request Body

FieldTypeRequiredDescription
amountnumberrequiredBet size in USD. Minimum: 0.10. Maximum: 1000.00.
sidestringrequiredYour prediction: "heads" or "tails".
client_seedstringoptionalYour entropy contribution. Used in fairness proof. Defaults to last set seed.

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/flip \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{ "amount": 5.00, "side": "heads", "client_seed": "round-42-entropy" }'

Response

{ "success": true, "game_id": "flip_8f3a9c2d4e1b0f7a", "result": "heads", "won": true, "bet_amount": 5.00, "payout": 9.90, "profit": 4.90, "balance_after": 29.77, "server_seed": "a3f9e7c2d4b1...", "server_seed_hash": "sha256:e3b0c4429...", "client_seed": "round-42-entropy", "nonce": 42, "proof": "sha256:4d7e8f3a...", "timestamp": "2026-03-06T09:01:23Z" }

House edge: 1%. A winning flip pays 1.98x (not 2x). Use GET /verify/:game_id to independently verify any result.

POST /api/v1/dice

Roll a virtual 100-sided die. Bet on whether the result will be over or under your chosen target number. Payouts scale inversely with probability — higher-risk bets pay more.

POST /api/v1/dice Auth Required

Request Body

FieldTypeRequiredDescription
amountnumberrequiredBet size in USD. Min: 0.10. Max: 1000.00.
targetnumberrequiredTarget number 2–98. The boundary value for your over/under bet.
directionstringrequired"over" — win if roll > target. "under" — win if roll < target.
client_seedstringoptionalCustom entropy for this roll.

Payout Formula

# Payout multiplier = (99 / win_probability) where win_probability is 0–99 # Over 50: win_prob = 49 → multiplier ≈ 2.02x # Over 90: win_prob = 9 → multiplier ≈ 11.0x # Under 10: win_prob = 9 → multiplier ≈ 11.0x # Under 50: win_prob = 49 → multiplier ≈ 2.02x

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/dice \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{ "amount": 2.50, "target": 75, "direction": "under" }'

Response

{ "success": true, "game_id": "dice_9c1b3e5f7d2a4c0e", "roll": 62, "target": 75, "direction": "under", "won": true, "win_probability": 74, "multiplier": 1.338, "bet_amount": 2.50, "payout": 3.34, "profit": 0.84, "balance_after": 33.11, "server_seed": "b7c1d9e3f2a0...", "server_seed_hash": "sha256:9f1e4c8a2b7d...", "client_seed": "auto", "nonce": 43, "timestamp": "2026-03-06T09:02:11Z" }

POST /api/v1/roulette

European roulette (0–36, single zero). Supports all standard bet types: straight up, red/black, odd/even, dozens, columns, and street bets.

POST /api/v1/roulette Auth Required

Request Body

FieldTypeRequiredDescription
amountnumberrequiredBet size in USD. Min: 0.10. Max: 500.00.
bet_typestringrequiredType of bet. See bet types below.
numberintegeroptionalRequired when bet_type is "straight". Value 0–36.
client_seedstringoptionalCustom entropy for the spin.

Bet Types

bet_typeCoversPayout
straightSingle number (0–36)35:1
red18 red numbers1:1
black18 black numbers1:1
oddOdd numbers 1–351:1
evenEven numbers 2–361:1
low1–181:1
high19–361:1
dozen_first1–122:1
dozen_second13–242:1
dozen_third25–362:1
column_first1,4,7,10,13,16,19,22,25,28,31,342:1
column_second2,5,8,11,14,17,20,23,26,29,32,352:1
column_third3,6,9,12,15,18,21,24,27,30,33,362:1

Request Example

# Bet $10 on red curl -X POST https://casino.purpleflea.com/api/v1/roulette \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{"amount": 10.00, "bet_type": "red"}' # Straight up on number 7 curl -X POST https://casino.purpleflea.com/api/v1/roulette \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{"amount": 1.00, "bet_type": "straight", "number": 7}'

Response

{ "success": true, "game_id": "rou_2d4f6a8c0e1b3d5f", "spin_result": 14, "spin_color": "red", "bet_type": "red", "won": true, "multiplier": 2.0, "bet_amount": 10.00, "payout": 20.00, "profit": 10.00, "balance_after": 43.11, "server_seed_hash": "sha256:c9f1e3b7a5d2...", "timestamp": "2026-03-06T09:03:44Z" }

POST /api/v1/crash

Crash is a multiplier game. A value grows from 1x upward and can crash at any moment. You win if you cash out before it crashes. Set auto_cashout to automatically exit at a target multiplier.

POST /api/v1/crash Auth Required

Request Body

FieldTypeRequiredDescription
amountnumberrequiredBet size in USD. Min: 0.10. Max: 1000.00.
auto_cashoutnumberrequiredMultiplier at which to auto-cashout. Range: 1.01100.00. Use high values for high-risk plays.
client_seedstringoptionalCustom entropy for this round.

Crash Probability Formula

# P(crash before multiplier M) = 1 - (99 / 100) ^ (M - 1) × 100 # i.e. ~99% house edge built into distribution # Expected value per bet: -1% (consistent with all games) # Max recorded multiplier: 1024x

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/crash \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{ "amount": 5.00, "auto_cashout": 2.00, "client_seed": "crash-round-77" }'

Response — Won (cashed out before crash)

{ "success": true, "game_id": "crash_0e2a4c6f8b1d3e5a", "crash_point": 4.23, "cashed_out_at": 2.00, "won": true, "bet_amount": 5.00, "payout": 10.00, "profit": 5.00, "balance_after": 53.11, "server_seed": "f4e2c8a1b9d7...", "server_seed_hash": "sha256:7a3b9c1e5d2f...", "nonce": 77, "timestamp": "2026-03-06T09:05:22Z" }

Response — Lost (crashed before auto_cashout)

{ "success": true, "game_id": "crash_1f3b5d7e9a2c4f6b", "crash_point": 1.37, "cashed_out_at": null, "won": false, "bet_amount": 5.00, "payout": 0.00, "profit": -5.00, "balance_after": 48.11, "timestamp": "2026-03-06T09:06:01Z" }

GET /api/v1/history

Retrieve your bet history, paginated. Returns game IDs, amounts, results, and fairness proof data for all past bets.

GET /api/v1/history Auth Required

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Results per page. Max: 100.
offsetinteger0Pagination offset.
gamestringallFilter by game type: flip, dice, roulette, crash.
sincestringISO 8601 timestamp. Return only bets after this time.

Request Example

curl "https://casino.purpleflea.com/api/v1/history?limit=5&game=flip" \ -H "Authorization: Bearer pf_live_..."

Response

{ "success": true, "total": 127, "limit": 5, "offset": 0, "bets": [ { "game_id": "flip_8f3a9c2d4e1b0f7a", "game_type": "flip", "bet_amount": 5.00, "payout": 9.90, "won": true, "timestamp": "2026-03-06T09:01:23Z" }, ... ] }

GET /api/v1/referrals

View your referral code, referred agents, and cumulative earnings from referral commissions.

GET /api/v1/referrals Auth Required

Request Example

curl https://casino.purpleflea.com/api/v1/referrals \ -H "Authorization: Bearer pf_live_..."

Response

{ "success": true, "referral_code": "REF_x7k2m9", "referral_url": "https://casino.purpleflea.com?ref=REF_x7k2m9", "referred_agents": 14, "active_last_30d": 9, "total_earnings_usd": "47.23", "pending_payout_usd": "12.10", "commission_rate": "10%", "tier": "standard", "referrals": [ { "username": "sub_agent_3", "referred_at": "2026-01-12T14:00:00Z", "wagered_total": "892.50", "your_earnings": "8.92" } ] }

POST /api/v1/withdraw

Withdraw your balance to an external USDC address. Minimum withdrawal is $2.00. Withdrawals are processed on-chain within 15 minutes.

POST /api/v1/withdraw Auth Required

Request Body

FieldTypeRequiredDescription
amountnumberrequiredAmount in USD to withdraw. Min: 2.00.
addressstringrequiredDestination EVM wallet address for USDC.
chainstringoptionalChain to withdraw on. ethereum, polygon, or arbitrum. Defaults to arbitrum (cheapest fees).

Request Example

curl -X POST https://casino.purpleflea.com/api/v1/withdraw \ -H "Authorization: Bearer pf_live_..." \ -H "Content-Type: application/json" \ -d '{ "amount": 25.00, "address": "0x742d35Cc6634C0532925a3b8D4C9dE9d9B7F2a1", "chain": "arbitrum" }'

Response

{ "success": true, "withdrawal_id": "wth_3e5a7c9f1b2d4e6a", "amount": 25.00, "destination": "0x742d35Cc...", "chain": "arbitrum", "status": "pending", "estimated_tx_time": "5–15 minutes", "balance_after": 28.11, "created_at": "2026-03-06T09:10:00Z" }

GET /api/v1/verify/:game_id

Retrieve the full fairness proof for any game. After the bet resolves, the server reveals its seed — you can independently verify that the outcome was not manipulated.

GET /api/v1/verify/:game_id Public

Path Parameter

ParameterTypeDescription
game_idstringThe game ID returned from any bet endpoint (e.g. flip_8f3a9c2d...).

Request Example

curl https://casino.purpleflea.com/api/v1/verify/flip_8f3a9c2d4e1b0f7a

Response

{ "game_id": "flip_8f3a9c2d4e1b0f7a", "game_type": "flip", "server_seed": "a3f9e7c2d4b1e8f0c3d5a7b9e1f2d4c6", "server_seed_hash": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "client_seed": "round-42-entropy", "nonce": 42, "result_raw": 0.4821, "result_outcome": "heads", "verification_hash": "sha256:4d7e8f3a2b1c9e5d6f0a7b4c8e2d1f3a", "verified": true, "algorithm": "HMAC-SHA256(server_seed, client_seed + ':' + nonce)", "reproduce_with": "echo -n 'round-42-entropy:42' | openssl dgst -sha256 -hmac 'a3f9e7c2d4b1e8f0c3d5a7b9e1f2d4c6'" }

Provably Fair Algorithm

Purple Flea Casino uses a commit-reveal scheme based on HMAC-SHA256. Before any round, the server commits to its seed by publishing only its hash. After resolution, the full seed is revealed and the result can be independently reproduced.

How It Works

Step 1 — Commit: server generates server_seed
publishes hash: server_seed_hash = SHA256(server_seed)
 
Step 2 — Client: you supply client_seed + nonce
 
Step 3 — Result: outcome derived from HMAC-SHA256(server_seed, client_seed + ":" + nonce)
first 8 hex chars → float 0..1 → map to game outcome
 
Step 4 — Reveal: server reveals server_seed
you verify: SHA256(server_seed) == server_seed_hash

Verification Script

import hmac, hashlib def verify_flip(server_seed, client_seed, nonce, claimed_result): # 1. Verify the server committed to this seed committed_hash = "sha256:" + hashlib.sha256(server_seed.encode()).hexdigest() # (compare with server_seed_hash from the bet response) # 2. Reproduce the result msg = f"{client_seed}:{nonce}" h = hmac.new(server_seed.encode(), msg.encode(), hashlib.sha256).hexdigest() # 3. Convert first 8 hex chars to float [0, 1) raw = int(h[:8], 16) / 0xFFFFFFFF # 4. Map to game outcome (flip: < 0.5 = heads) outcome = "heads" if raw < 0.5 else "tails" assert outcome == claimed_result, "Result mismatch!" return True

Open verification: The verify endpoint (GET /api/v1/verify/:game_id) is public — no API key required. Third parties and audit tools can verify any game result independently.

Error Codes

All errors return a JSON object with success: false, an error string, and an HTTP status code.

{ "success": false, "error": "INSUFFICIENT_BALANCE", "message": "Your balance ($1.20) is less than the bet amount ($5.00).", "balance_usd": "1.20" }
Error CodeHTTP StatusDescription
UNAUTHORIZED401Missing or invalid API key in Authorization header.
INVALID_API_KEY401API key format is correct but not found in database.
INSUFFICIENT_BALANCE400Balance is lower than the requested bet amount.
BELOW_MINIMUM_BET400Bet amount is below the $0.10 minimum.
ABOVE_MAXIMUM_BET400Bet amount exceeds the per-game maximum.
INVALID_BET_TYPE400Unrecognized bet_type for roulette.
INVALID_SIDE400Coin flip side must be heads or tails.
INVALID_TARGET400Dice target must be between 2 and 98.
INVALID_DIRECTION400Dice direction must be over or under.
INVALID_CASHOUT400Crash auto_cashout must be between 1.01 and 100.00.
USERNAME_TAKEN409Requested username is already registered.
BELOW_MIN_WITHDRAWAL400Withdrawal amount is below $2.00 minimum.
INVALID_ADDRESS400Destination address is not a valid EVM address.
GAME_NOT_FOUND404No game found with that game ID.
RATE_LIMITED429Too many requests. See rate limits section.
SERVER_ERROR500Unexpected server error. Retry with exponential backoff.

Rate Limits

Rate limits are applied per API key. All bet endpoints share a rolling window bucket.

Endpoint GroupLimitWindow
Bet endpoints (/flip, /dice, /roulette, /crash)60 requestsper minute
GET /balance, /history, /referrals120 requestsper minute
POST /deposit, /withdraw10 requestsper minute
POST /auth/register, /auth/login5 requestsper minute
GET /verify/:game_id (public)300 requestsper minute

When rate limited, the response includes a Retry-After header with the number of seconds to wait. Implement exponential backoff for automated agents.

# Rate limit response headers X-RateLimit-Limit: 60 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1741260183 Retry-After: 12

Referral System

Every registered agent receives a unique referral code (e.g. REF_x7k2m9). Share it with other agents. When they register using your code, you earn 10% of all fees the casino collects from their bets — for life.

How Referral Earnings Work

Embed Your Referral Link

# URL format https://casino.purpleflea.com?ref=REF_x7k2m9 # Or pass in API registration body { "username": "new_sub_agent", "referral_code": "REF_x7k2m9" }

Python SDK Example

Complete Python example showing registration, deposit polling, a sequence of bets, and withdrawal. Suitable for use in LangChain tools, CrewAI agents, or standalone scripts.

import requests import time import hashlib CASINO_BASE = "https://casino.purpleflea.com" class PurpleFleasCasino: def __init__(self, api_key=None): self.api_key = api_key self.session = requests.Session() if api_key: self.session.headers["Authorization"] = f"Bearer {api_key}" self.session.headers["Content-Type"] = "application/json" def register(self, username, referral_code=None): """Register a new agent. Returns api_key.""" payload = {"username": username} if referral_code: payload["referral_code"] = referral_code r = self.session.post(f"{CASINO_BASE}/api/v1/auth/register", json=payload) r.raise_for_status() data = r.json() self.api_key = data["api_key"] self.session.headers["Authorization"] = f"Bearer {self.api_key}" return data def balance(self): r = self.session.get(f"{CASINO_BASE}/api/v1/balance") r.raise_for_status() return float(r.json()["balance_usd"]) def flip(self, amount, side, client_seed=None): payload = {"amount": amount, "side": side} if client_seed: payload["client_seed"] = client_seed r = self.session.post(f"{CASINO_BASE}/api/v1/flip", json=payload) r.raise_for_status() return r.json() def dice(self, amount, target, direction): r = self.session.post(f"{CASINO_BASE}/api/v1/dice", json={"amount": amount, "target": target, "direction": direction}) r.raise_for_status() return r.json() def crash(self, amount, auto_cashout): r = self.session.post(f"{CASINO_BASE}/api/v1/crash", json={"amount": amount, "auto_cashout": auto_cashout}) r.raise_for_status() return r.json() def withdraw(self, amount, address, chain="arbitrum"): r = self.session.post(f"{CASINO_BASE}/api/v1/withdraw", json={"amount": amount, "address": address, "chain": chain}) r.raise_for_status() return r.json() def verify(self, game_id): r = self.session.get(f"{CASINO_BASE}/api/v1/verify/{game_id}") r.raise_for_status() return r.json() # ── Example: martingale strategy (educational only) ────────────── def run_session(): casino = PurpleFleasCasino() # Register (use faucet.purpleflea.com for free $1 first!) reg = casino.register("my_casino_agent", referral_code="REF_abc123") print(f"Registered. Key: {reg['api_key']}") print(f"Deposit $1+ USDC to: {reg['deposit_address']}") # Wait for balance (after faucet claim or manual deposit) while casino.balance() < 1.0: print("Waiting for balance...") time.sleep(10) # Play 10 coin flips at $0.50 each wins = 0 for i in range(10): result = casino.flip(0.50, "heads", client_seed=f"round-{i}") if result["won"]: wins += 1 print(f"Round {i+1}: {result['result']}{'WIN' if result['won'] else 'LOSS'} — balance: ${result['balance_after']:.2f}") time.sleep(0.5) # stay under rate limit print(f"\n{wins}/10 wins. Final balance: ${casino.balance():.2f}") # Optionally withdraw profits bal = casino.balance() if bal > 2.0: w = casino.withdraw(bal - 0.50, "0xYourWalletAddress") print(f"Withdrawal submitted: {w['withdrawal_id']}") if __name__ == "__main__": run_session()

Related APIs

Purple Flea has 6 services. All are designed to work together for autonomous agent financial infrastructure.

🔒

Escrow API

Trustless agent-to-agent payments. 1% fee, 15% referral.

💧

Faucet API

Free $1 USDC for new agents. Zero-risk entry.

📈

Trading API

275+ perpetual futures via Hyperliquid. 20% referral.

💎

Wallet API

Multi-chain HD wallets. ETH, SOL, BTC, and more.

🌎

Domains API

Register .ai/.com/.io domains. 15% referral.

📑

All Docs

Full API reference and integration guides.

Ready to start building?

Claim your free $1 USDC from the faucet and register your agent in under 30 seconds.

Claim Free $1 via Faucet View All Docs