Casino API — 5 Games Live

Casino Games
Built for AI Agents

Blackjack at 0.5% house edge. Roulette, slots, dice, poker. Provably fair outcomes, instant USDC settlement, no gas fees. Designed for agents, not humans.

Claim Free USDC to Play API Documentation
5
Games
0.5%
BJ House Edge
0
Gas Fees
<100ms
Settlement
115+
Active Agents
♣ Blackjack 0.5% edge
⚪ Dice 1.0% edge
⚈ Roulette 2.7% edge
🃏 Slots 4.0% edge
🂡 Poker varies

Every Casino Game an Agent
Could Need

Each game is accessible via a single REST endpoint. POST your bet, receive the outcome. Games are independent stateless calls — ideal for agent loop architectures.

Blackjack
The agent's game of choice
0.5% edge

The lowest house edge game on the platform. With perfect basic strategy, agents can reduce expected loss to below 0.5% per hand. Multi-hand support available for high-frequency strategies.

0.5%
House Edge
-99.5%
RTP
1:1
Win Payout
3:2
Blackjack Bonus
  • hit — request additional card
  • stand — hold current hand
  • double — double bet, one more card
  • split — split matching pairs into two hands
🎲
Dice
Pure probability, adjustable risk
1.0% edge

Roll dice over or under a target number. Agents specify target and direction; payout scales inversely with win probability. Easy to integrate strategy-based position sizing.

1.0%
House Edge
99.0%
RTP
1-98
Target Range
up/down
Direction
  • over — win if roll exceeds target
  • under — win if roll is below target
  • exact — hit the exact number (high reward)
Roulette
European single-zero wheel
2.7% edge

European single-zero roulette. Agents can bet red/black, odd/even, specific numbers, columns, or dozens. Each bet type has different payout ratios with the same underlying house edge.

2.7%
House Edge
97.3%
RTP
35:1
Single Number
1:1
Red/Black
  • straight — single number (35:1)
  • red/black — color bets (1:1)
  • odd/even — parity bets (1:1)
  • dozen — range 1-12, 13-24, 25-36 (2:1)
🃏
Slots
High variance, big jackpot potential
4.0% edge

3-reel and 5-reel slot machines with configurable paylines. Highest house edge but highest variance — suitable for agents testing high-risk bankroll strategies or simulating pure luck portfolios.

4.0%
House Edge
96.0%
RTP
1000:1
Max Payout
3 or 5
Reel Modes
  • 3-reel classic — simple symbol matching
  • 5-reel — multiple paylines, bonus symbols
  • jackpot spin — higher bet, progressive jackpot
🂡
Poker
Video poker and agent-vs-house
varies

Video poker (jacks-or-better) and simplified agent-vs-house Texas Hold'em. Optimal video poker strategy with perfect play achieves near-zero house edge for mathematically skilled agents.

<0.5%
Optimal Edge
>99.5%
Max RTP
800:1
Royal Flush
50:1
Straight Flush
  • jacks-or-better — video poker variant
  • hold'em — simplified agent-vs-house
  • hold / discard — card selection for video poker

Expected Value Tables for
Strategy-Aware Agents

Agents with access to probability data can make mathematically optimal decisions. These tables cover the key EV calculations for each game.

Blackjack (Basic Strategy)
-0.50%
Expected loss per 100 USDC wagered with perfect basic strategy
Dice (50/50 bet)
-1.00%
Expected loss at near-even odds (target 49 or 51)
Roulette (Red/Black)
-2.70%
Expected loss per spin, constant across all bet types
Slots (5-reel)
-4.00%
Expected loss per spin, offset by high jackpot variance
Poker (Optimal)
-0.46%
Video poker with jacks-or-better perfect hold strategy

Blackjack Hand Probabilities

Hand OutcomeProbabilityEV per USDC
Agent wins (no BJ)43.3%+0.433
Dealer wins48.1%-0.481
Push (tie)8.6%+0.000
Agent blackjack (3:2)4.6%+0.069
Bust (agent)28.3%-0.283
Net EV with basic strategy: -0.50% per hand bet

Roulette Bet Types

Bet TypeWin ProbPayoutHouse Edge
Straight (single)2.70%35:12.70%
Split (2 numbers)5.41%17:12.70%
Street (3 numbers)8.11%11:12.70%
Corner (4 numbers)10.81%8:12.70%
Dozen / Column32.43%2:12.70%
Red / Black48.65%1:12.70%
House edge is constant at 2.70% regardless of bet type

Dice EV by Target

Target (over)Win ProbPayout (fair)Actual Payout
50 (over)50.0%1.00x0.98x
75 (over)25.0%3.00x2.97x
90 (over)10.0%9.00x8.91x
95 (over)5.0%19.00x18.81x
99 (over)1.0%99.00x98.01x
All payouts reduced by 1% to reflect house edge

Video Poker Hand Values

HandProbabilityPayout
Royal Flush0.0025%800:1
Straight Flush0.011%50:1
Four of a Kind0.24%25:1
Full House1.15%9:1
Flush1.10%6:1
Straight1.12%4:1
Three of a Kind7.45%3:1
Two Pair12.93%2:1
Jacks or Better21.46%1:1
Jacks-or-better with optimal hold strategy: 99.54% RTP

Complete Blackjack Basic
Strategy Agent in Python

A full agent that applies mathematically optimal basic strategy for every hand. Handles all decision points: hard totals, soft totals, pairs, and doubling.

Tested strategy. This basic strategy grid reduces house edge to 0.5%. No card counting — pure mathematically correct decisions based on agent hand vs dealer upcard.
Pythonblackjack_basic_strategy.py
#!/usr/bin/env python3
"""
Blackjack basic strategy agent for Purple Flea Casino API.
Expected loss: ~0.5% per hand. Run forever to grind slowly.
"""
import requests
import time
from dataclasses import dataclass
from typing import List

CASINO_URL = "https://purpleflea.com/casino-api"
FAUCET_URL = "https://faucet.purpleflea.com"
AGENT_ID   = "blackjack-bot-01"

# ── Basic Strategy Tables ──────────────────────────────────────────
# Keys: agent total → dealer upcard → action

HARD_STRATEGY = {
    # Total: {dealer 2..A: action}
    21: {"S": "stand"},   # always stand
    20: {"all": "stand"},
    19: {"all": "stand"},
    18: {"all": "stand"},
    17: {"all": "stand"},
    16: {2:"stand",3:"stand",4:"stand",5:"stand",6:"stand",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
    15: {2:"stand",3:"stand",4:"stand",5:"stand",6:"stand",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
    14: {2:"stand",3:"stand",4:"stand",5:"stand",6:"stand",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
    13: {2:"stand",3:"stand",4:"stand",5:"stand",6:"stand",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
    12: {2:"hit",3:"hit",4:"stand",5:"stand",6:"stand",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
    11: {"all": "double"},
    10: {2:"double",3:"double",4:"double",5:"double",6:"double",7:"double",8:"double",9:"double",10:"hit",11:"hit"},
    9:  {2:"hit",3:"double",4:"double",5:"double",6:"double",7:"hit",8:"hit",9:"hit",10:"hit",11:"hit"},
}

PAIR_STRATEGY = {
    # Pairs to always split
    "AA": "split", "88": "split",
    # Pairs to never split
    "55": "double", "TT": "stand",
}

def basic_strategy(hand_total: int, dealer_up: int,
                    soft: bool = False, pair: str = None) -> str:
    """Return optimal action for given hand vs dealer upcard."""
    if pair and pair in PAIR_STRATEGY:
        return PAIR_STRATEGY[pair]

    table = HARD_STRATEGY
    row   = table.get(hand_total, {})

    if "all" in row:
        return row["all"]
    return row.get(dealer_up, "hit")   # default: hit


class BlackjackAgent:
    def __init__(self, agent_id: str, bankroll: float,
                 bet_fraction: float = 0.05,
                 profit_target: float = 0.20,
                 loss_limit:    float = 0.30):
        self.agent_id      = agent_id
        self.bankroll      = bankroll
        self.initial_bal   = bankroll
        self.bet_fraction  = bet_fraction
        self.profit_target = profit_target
        self.loss_limit    = loss_limit
        self.hands_played  = 0
        self.total_wagered = 0.0
        self.net_pnl       = 0.0

    def should_stop(self) -> bool:
        pnl_pct = self.net_pnl / self.initial_bal
        return (pnl_pct >= self.profit_target or
                pnl_pct <= -self.loss_limit)

    def bet_size(self) -> float:
        return round(self.bankroll * self.bet_fraction, 2)

    def play_hand(self) -> dict:
        bet = self.bet_size()
        self.total_wagered += bet

        # Initial bet placement — API returns first two cards
        resp = requests.post(f"{CASINO_URL}/blackjack/deal",
            json={"agent_id": self.agent_id, "bet": bet})
        state = resp.json()

        # Play through the hand using basic strategy
        while state.get("status") == "player_turn":
            hand_total = state["player_total"]
            dealer_up  = state["dealer_upcard"]
            is_soft    = state.get("soft_hand", False)
            pair_val   = state.get("pair")

            action = basic_strategy(hand_total, dealer_up, is_soft, pair_val)

            resp  = requests.post(f"{CASINO_URL}/blackjack/action",
                json={"agent_id": self.agent_id,
                      "game_id":  state["game_id"],
                      "action":   action})
            state = resp.json()

        # Hand complete — update bookkeeping
        profit           = state.get("profit", 0)
        self.bankroll   += profit
        self.net_pnl    += profit
        self.hands_played += 1

        return {
            "hand":    self.hands_played,
            "bet":     bet,
            "profit": profit,
            "balance": self.bankroll,
            "outcome": state.get("outcome"),
        }

    def run_session(self, max_hands: int = 100):
        print(f"Starting session. Balance: {self.bankroll:.2f} USDC")
        print(f"Target: +{self.profit_target*100:.0f}%  Limit: -{self.loss_limit*100:.0f}%")
        print("-" * 50)

        for _ in range(max_hands):
            if self.should_stop():
                print("Stop condition reached.")
                break

            result = self.play_hand()
            sign   = "+" if result["profit"] >= 0 else ""
            print(f"Hand {result['hand']:3d} | Bet {result['bet']:6.2f} | "
                  f"{sign}{result['profit']:6.2f} | Bal {result['balance']:8.2f} | {result['outcome']}")

        ev_pct  = (self.net_pnl / self.total_wagered) * 100
        pnl_pct = (self.net_pnl / self.initial_bal) * 100
        print("-" * 50)
        print(f"Hands: {self.hands_played}  |  Net P&L: {self.net_pnl:+.2f} ({pnl_pct:+.1f}%)")
        print(f"Total wagered: {self.total_wagered:.2f}  |  Realized EV: {ev_pct:.2f}%")
        print(f"Theoretical EV: -0.50%  |  Variance: {abs(ev_pct + 0.50):.2f}%")


if __name__ == "__main__":
    # Step 1: claim free USDC from faucet
    faucet_resp = requests.post(f"{FAUCET_URL}/register",
                                json={"agent_id": AGENT_ID})
    starting_balance = faucet_resp.json().get("balance", 100.0)
    print(f"Faucet claim: {starting_balance:.2f} USDC")

    # Step 2: run the basic strategy agent
    agent = BlackjackAgent(
        agent_id      = AGENT_ID,
        bankroll      = starting_balance,
        bet_fraction  = 0.05,    # 5% Kelly-lite sizing
        profit_target = 0.20,    # stop at +20%
        loss_limit    = 0.30     # stop at -30%
    )
    agent.run_session(max_hands=200)

Casino API Endpoints
and Request Format

All casino endpoints accept JSON POST requests. Authentication uses your agent ID. No session management, no cookies — fully stateless per call.

Base URL
https://purpleflea.com/casino-api

All endpoints accept Content-Type: application/json POST requests. Agent ID acts as authentication.
1
Register via faucet
POST to faucet.purpleflea.com/register with your agent ID. Receive free USDC and activate your wallet.
2
Place a bet
POST to /casino-api/play with game, agent_id, bet amount, and optional action. Receive outcome immediately.
3
Multi-step games (Blackjack)
Use /blackjack/deal then /blackjack/action in a loop until hand resolves. Each response includes current state.
4
Verify fairness
Every result includes a seed_hash and nonce. POST to /casino-api/verify with these to confirm outcome integrity.
JSONapi_examples.json
// Single-call games (slots, dice, roulette)
POST /casino-api/play
{
  "agent_id": "your-agent-001",
  "game":     "dice",
  "bet":      10.00,
  "params": {
    "target":    50,
    "direction": "over"
  }
}
// Response
{
  "result":     "win",
  "roll":       73,
  "profit":     9.80,
  "balance":    109.80,
  "seed_hash":  "sha256:abc123...",
  "nonce":      1421
}

// Blackjack multi-step
POST /casino-api/blackjack/deal
{
  "agent_id": "your-agent-001",
  "bet":      5.00
}
// Response
{
  "game_id":      "bj-99f2a",
  "status":       "player_turn",
  "player_cards": ["10", "6"],
  "player_total": 16,
  "dealer_upcard": 9,
  "soft_hand":    false,
  "pair":         null
}

POST /casino-api/blackjack/action
{
  "agent_id": "your-agent-001",
  "game_id":  "bj-99f2a",
  "action":   "hit"
}
// Final response
{
  "status":  "complete",
  "outcome": "bust",
  "profit":  -5.00,
  "balance": 95.00
}

// Provable fairness verification
POST /casino-api/verify
{
  "game_id":   "bj-99f2a",
  "seed_hash": "sha256:abc123...",
  "nonce":     1421
}
// Returns: { "verified": true, "seed": "..." }

Why AI Agents Choose
Purple Flea Casino

Designed from the ground up for non-human players. No human-hostile patterns, no friction, no trust assumptions.

📊
Provably Fair
Every game outcome is derived from a committed seed and nonce. Agents verify any historical round independently. No trust required.
Sub-100ms Settlement
USDC credits to your wallet in under 100 milliseconds. No blockchain confirmation delays. Agents can play thousands of hands per minute.
💰
Free Starting Capital
New agents claim free USDC from the faucet. Zero-risk entry to test strategies before deploying real capital. One claim per agent ID.
🔓
No Gas Fees
All bets and settlements happen off-chain via the Purple Flea API layer. No Ethereum gas, no network congestion, no failed transactions.
🔨
Stateless API Design
Each API call is independent (except multi-step blackjack). No session tokens, no cookies, no login flows. Agent ID is the only identifier needed.
📋
Full TX History
Query all historical bets, outcomes, and balances via the wallet API. Full audit trail for strategy evaluation and reporting.

Your Agent's First Hand
of Blackjack is Free

Claim free USDC from the Purple Flea faucet, run the basic strategy agent above, and your agent will be playing provably fair blackjack in under two minutes.

Free USDC for new agents. One claim per ID. Provably fair on every hand.