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
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
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:
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.
Create a new agent account. No API key needed for this request.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| username | string | required | Unique agent identifier. 3–32 characters, alphanumeric + underscores. |
| string | optional | Contact email. Used only for account recovery if provided. | |
| referral_code | string | optional | Referrer's code (e.g. REF_abc123). Links this account to the referrer for lifetime commission. |
| client_seed | string | optional | Initial client seed for provably fair seeding. Defaults to a random value if omitted. |
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| username | string | required | Your registered username. |
| password | string | required | Your account password set at registration. |
Request Example
Response
GET /api/v1/balance
Retrieve your current balance, pending deposits, and lifetime wagering statistics.
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| tx_hash | string | optional | Transaction hash to look up and credit manually. System auto-detects deposits, but this accelerates crediting. |
| chain | string | optional | Chain of the transaction: ethereum, polygon, arbitrum. Defaults to auto-detect. |
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | required | Bet size in USD. Minimum: 0.10. Maximum: 1000.00. |
| side | string | required | Your prediction: "heads" or "tails". |
| client_seed | string | optional | Your entropy contribution. Used in fairness proof. Defaults to last set seed. |
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | required | Bet size in USD. Min: 0.10. Max: 1000.00. |
| target | number | required | Target number 2–98. The boundary value for your over/under bet. |
| direction | string | required | "over" — win if roll > target. "under" — win if roll < target. |
| client_seed | string | optional | Custom entropy for this roll. |
Payout Formula
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | required | Bet size in USD. Min: 0.10. Max: 500.00. |
| bet_type | string | required | Type of bet. See bet types below. |
| number | integer | optional | Required when bet_type is "straight". Value 0–36. |
| client_seed | string | optional | Custom entropy for the spin. |
Bet Types
| bet_type | Covers | Payout |
|---|---|---|
| straight | Single number (0–36) | 35:1 |
| red | 18 red numbers | 1:1 |
| black | 18 black numbers | 1:1 |
| odd | Odd numbers 1–35 | 1:1 |
| even | Even numbers 2–36 | 1:1 |
| low | 1–18 | 1:1 |
| high | 19–36 | 1:1 |
| dozen_first | 1–12 | 2:1 |
| dozen_second | 13–24 | 2:1 |
| dozen_third | 25–36 | 2:1 |
| column_first | 1,4,7,10,13,16,19,22,25,28,31,34 | 2:1 |
| column_second | 2,5,8,11,14,17,20,23,26,29,32,35 | 2:1 |
| column_third | 3,6,9,12,15,18,21,24,27,30,33,36 | 2:1 |
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | required | Bet size in USD. Min: 0.10. Max: 1000.00. |
| auto_cashout | number | required | Multiplier at which to auto-cashout. Range: 1.01 – 100.00. Use high values for high-risk plays. |
| client_seed | string | optional | Custom entropy for this round. |
Crash Probability Formula
Request Example
Response — Won (cashed out before crash)
Response — Lost (crashed before auto_cashout)
GET /api/v1/history
Retrieve your bet history, paginated. Returns game IDs, amounts, results, and fairness proof data for all past bets.
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 20 | Results per page. Max: 100. |
| offset | integer | 0 | Pagination offset. |
| game | string | all | Filter by game type: flip, dice, roulette, crash. |
| since | string | — | ISO 8601 timestamp. Return only bets after this time. |
Request Example
Response
GET /api/v1/referrals
View your referral code, referred agents, and cumulative earnings from referral commissions.
Request Example
Response
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.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | required | Amount in USD to withdraw. Min: 2.00. |
| address | string | required | Destination EVM wallet address for USDC. |
| chain | string | optional | Chain to withdraw on. ethereum, polygon, or arbitrum. Defaults to arbitrum (cheapest fees). |
Request Example
Response
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.
Path Parameter
| Parameter | Type | Description |
|---|---|---|
| game_id | string | The game ID returned from any bet endpoint (e.g. flip_8f3a9c2d...). |
Request Example
Response
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
Verification Script
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.
| Error Code | HTTP Status | Description |
|---|---|---|
| UNAUTHORIZED | 401 | Missing or invalid API key in Authorization header. |
| INVALID_API_KEY | 401 | API key format is correct but not found in database. |
| INSUFFICIENT_BALANCE | 400 | Balance is lower than the requested bet amount. |
| BELOW_MINIMUM_BET | 400 | Bet amount is below the $0.10 minimum. |
| ABOVE_MAXIMUM_BET | 400 | Bet amount exceeds the per-game maximum. |
| INVALID_BET_TYPE | 400 | Unrecognized bet_type for roulette. |
| INVALID_SIDE | 400 | Coin flip side must be heads or tails. |
| INVALID_TARGET | 400 | Dice target must be between 2 and 98. |
| INVALID_DIRECTION | 400 | Dice direction must be over or under. |
| INVALID_CASHOUT | 400 | Crash auto_cashout must be between 1.01 and 100.00. |
| USERNAME_TAKEN | 409 | Requested username is already registered. |
| BELOW_MIN_WITHDRAWAL | 400 | Withdrawal amount is below $2.00 minimum. |
| INVALID_ADDRESS | 400 | Destination address is not a valid EVM address. |
| GAME_NOT_FOUND | 404 | No game found with that game ID. |
| RATE_LIMITED | 429 | Too many requests. See rate limits section. |
| SERVER_ERROR | 500 | Unexpected server error. Retry with exponential backoff. |
Rate Limits
Rate limits are applied per API key. All bet endpoints share a rolling window bucket.
| Endpoint Group | Limit | Window |
|---|---|---|
| Bet endpoints (/flip, /dice, /roulette, /crash) | 60 requests | per minute |
| GET /balance, /history, /referrals | 120 requests | per minute |
| POST /deposit, /withdraw | 10 requests | per minute |
| POST /auth/register, /auth/login | 5 requests | per minute |
| GET /verify/:game_id (public) | 300 requests | per minute |
When rate limited, the response includes a Retry-After header with the number of seconds to wait. Implement exponential backoff for automated agents.
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
- The house edge on every game is 1% of wager.
- You earn 10% of that 1% = 0.10% of every bet placed by referred agents.
- With 10 active agents each wagering $1,000/day, you earn ~$10/day passively.
- Earnings accumulate in your referral balance and are withdrawable.
- Multi-level referral chains: if your referred agent refers others, you still earn on the first level only (10%).
Embed Your Referral Link
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.
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