Developer Documentation

Purple Flea API Docs

Complete reference for all Purple Flea APIs. Everything is REST. All responses are JSON. No dashboards โ€” just endpoints.

Getting Started

All Purple Flea APIs share a common authentication model. Register once per service to get an API key and referral code. No KYC, no email verification required.

Quick Start (Casino)

# 1. Register and get your API key + referral code curl -X POST https://api.purpleflea.com/api/v1/register \ -H "Content-Type: application/json" \ -d '{"username": "my_agent", "email": "agent@example.com"}' # Response: { "api_key": "sk_live_abc123...", "referral_code": "REF_abc123", "user_id": "usr_...", "deposit_address": "0x..." } # 2. Place your first bet (coin flip) curl -X POST https://api.purpleflea.com/api/v1/flip \ -H "Authorization: Bearer sk_live_abc123..." \ -H "Content-Type: application/json" \ -d '{"amount": 1.00, "side": "heads"}' # Response: { "result": "heads", "won": true, "payout": 1.99, "proof": "sha256:4d7e...", "server_seed_hash": "abc..." }

Authentication

Pass your API key in the Authorization header on every request:

Authorization: Bearer sk_live_...
โ„น๏ธ

Referral codes: When registering new agents, pass "referral_code": "REF_xxx" in the register body. The referrer earns commissions on all activity from the referred agent โ€” forever.

Rate Limits

TierLimitNotes
Free100 req/minDefault for new registrations
Pro10,000 req/minContact hello@purpleflea.com
EnterpriseUnlimitedSLA available

Error Codes

CodeMeaning
400Bad request โ€” missing or invalid parameters
401Unauthorized โ€” invalid or missing API key
402Insufficient balance โ€” deposit required
404Not found โ€” market/position/domain not found
429Rate limited โ€” too many requests
500Internal error โ€” contact support

Casino API

Base URL: https://api.purpleflea.com/api/v1/
MCP Repo: github.com/Purple-flea/casino-mcp
Referral: 10% of referred agent net losses

Provably fair gambling games. Every outcome uses a server seed + client seed + nonce scheme. Verify any bet at GET /verify/:bet_id. Minimum bet: $0.01. Maximum: $10,000. Payouts are instant in USDC.

Register

POST
/register
Create account and get API key
Body: username*, email*, referral_code?
ParameterTypeRequiredDescription
usernamestringrequiredUnique agent identifier
emailstringrequiredFor notifications (no verification)
referral_codestringoptionalReferrer's code โ€” links commission chain

Wallet

GET
/balance
Get current balance and deposit address
curl https://api.purpleflea.com/api/v1/balance \ -H "Authorization: Bearer sk_live_..." { "balance_usd": 42.50, "deposit_address": "0xAbCd...", "pending_deposit": 0.00 }

Games

GET
/games
List all games with house edge and limits
POST
/flip
Provably fair coin flip โ€” heads or tails
Body: amount*, side* (heads|tails)
POST
/dice
Roll dice with custom over/under threshold
Body: amount*, target* (over|under), target_value* (1-99)
POST
/custom
Custom win probability bet (1-99%)
Body: amount*, win_probability* (1-99)
POST
/crash
Crash game โ€” cash out before it crashes
Body: amount*, target_multiplier* (1.01 โ€“ 100)
POST
/roulette
European roulette (single zero)
Body: amount*, bet_type* (color|number|dozen|column|even|odd), bet_value*
GET
/verify/:bet_id
Verify any past bet outcome โ€” cryptographic proof
GET
/history
Bet history with proofs
Query: limit? (default 20, max 100)
GET
/referrals
Your referral stats and earnings

Example: dice roll

curl -X POST https://api.purpleflea.com/api/v1/dice \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{"amount": 5.00, "target": "over", "target_value": 50}' { "roll": 73, "target": "over", "target_value": 50, "won": true, "payout": 9.95, "proof": "sha256:7f3e...", "server_seed_hash": "abc...", "nonce": 42 }

Trading API

Base URL: https://api.purpleflea.com/v1/trading/
MCP Repo: github.com/Purple-flea/trading-mcp
Referral: 20% of referred agent trading fees โ€” forever

Access 275+ perpetual futures markets via Hyperliquid. CEX-level liquidity on a DEX. Up to 50x leverage on major markets. Available markets include crypto pairs, stock perps (TSLA, NVDA, AAPL), commodities (GOLD, OIL), and forex (EUR-USD, GBP-USD).

๐Ÿ’ก

Best referral rate: At 20% of fees, trading is the highest-value referral in the ecosystem. An active trading agent generating $10,000/month in notional volume pays roughly $5 in fees โ€” you earn $1/month per agent. At 1,000 referred agents that's $1,000/month.

Register

POST
/register
Create trading account
Body: username*, email*, referral_code?

Markets

GET
/markets
List all 275+ markets with price, funding rate, open interest
curl https://api.purpleflea.com/v1/trading/markets \ -H "Authorization: Bearer sk_live_..." { "markets": [ {"id": "BTC-PERP", "price": 92450.00, "funding_rate": 0.0001, "open_interest": 1250000000}, {"id": "ETH-PERP", "price": 3240.00, "funding_rate": -0.0002, "open_interest": 480000000}, {"id": "TSLA-PERP", "price": 412.50, "funding_rate": 0.00005, "open_interest": 28000000}, ...275 total ] }

Positions

POST
/open
Open a leveraged perpetual position
Body: market*, side* (long|short), size* (USD), leverage* (1-50)
POST
/close
Close position and realize P&L
Body: position_id*
POST
/stop-loss
Set stop loss on open position
Body: position_id*, price*
POST
/take-profit
Set take profit on open position
Body: position_id*, price*
GET
/positions
List open positions with unrealized P&L
GET
/orders
List pending orders (limit, stop loss, take profit)
GET
/history
Trade history with fees paid
Query: limit? (default 20)
GET
/referrals
Referral stats and fee earnings

Example: open ETH long position

curl -X POST https://api.purpleflea.com/v1/trading/open \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{ "market": "ETH-PERP", "side": "long", "size": 1000, "leverage": 5 }' { "position_id": "pos_abc123", "market": "ETH-PERP", "side": "long", "size_usd": 1000, "leverage": 5, "entry_price": 3240.00, "liquidation_price": 2610.00, "margin_used": 200.00, "fee_paid": 0.50 }

Wallet API

Base URL: https://wallet.purpleflea.com/v1/
OpenAPI: https://wallet.purpleflea.com/openapi.json
Referral: 10% of referred agent swap fees

Non-custodial HD wallets. Mnemonics are generated client-side and never stored. Derives addresses for Ethereum, Base, Solana, Bitcoin, Tron, Polygon, Arbitrum, BNB. Cross-chain swaps powered by Wagyu (aggregator of 1inch, Paraswap, Jupiter, Li.Fi, 0x).

Register

POST
/auth/register
Create account โ€” returns API key and referral code
Body: referral_code?

Wallets

POST
/wallet/create
Generate BIP-39 HD wallet. Returns mnemonic ONCE โ€” store securely.
GET
/wallet/balance/:address
On-chain balance for address
Query: chain* (base|ethereum|solana|bitcoin|tron|polygon|arbitrum|bnb)
POST
/wallet/send
Sign and broadcast transaction
Body: chain*, to*, amount*, private_key*, token? (ERC-20 contract address)
GET
/wallet/chains
List supported chains (no auth required)

Swaps

GET
/wallet/swap/quote
Get best-rate cross-chain swap quote
Query: from_chain*, to_chain*, from_token*, to_token*, amount*
POST
/wallet/swap
Execute cross-chain swap via Wagyu aggregator
Body: from_chain*, to_chain*, from_token*, to_token*, amount*, to_address*
GET
/wallet/swap/status/:orderId
Check swap order status

Referrals

GET
/referral/code
Get your referral code
GET
/referral/stats
Earnings: total_earned, withdrawn, available
POST
/referral/withdraw
Withdraw referral earnings to any address
Body: address*, chain?

Example: create wallet and check balance

# Register curl -X POST https://wallet.purpleflea.com/v1/auth/register \ -H "Content-Type: application/json" \ -d '{"referral_code": "REF_xxx"}' {"api_key": "sk_live_...", "referral_code": "REF_yyy"} # Create wallet (returns mnemonic ONCE) curl -X POST https://wallet.purpleflea.com/v1/wallet/create \ -H "Authorization: Bearer sk_live_..." { "mnemonic": "word1 word2 ... word12", "addresses": { "ethereum": "0xAbCd...", "bitcoin": "bc1q...", "solana": "7xKXt...", "tron": "TAbCd..." } } # Check ETH balance curl "https://wallet.purpleflea.com/v1/wallet/balance/0xAbCd...?chain=ethereum" \ -H "Authorization: Bearer sk_live_..."

Domains API

Base URL: https://domains.purpleflea.com/v1/
Referral: 15% of referred domain purchases

Register and manage domains programmatically. 500+ TLDs available including .ai, .com, .io, .xyz, .agent, .bot. Pay with crypto. Manage DNS records via API โ€” no registrar dashboard required.

Search & Register

POST
/domains/search
Check domain availability across multiple TLDs
Body: query* (domain name without TLD), tlds* (array of TLDs)
POST
/domains/register
Register a domain (pay with crypto balance)
Body: domain* (full domain.tld), years? (default 1), auto_renew? (bool)
GET
/domains
List your registered domains
GET
/domains/:domain
Get domain details, expiry, nameservers

DNS Records

GET
/domains/:domain/records
List all DNS records for domain
POST
/domains/:domain/records
Create DNS record
Body: type* (A|CNAME|TXT|MX|AAAA), name*, value*, ttl? (default 3600)
DELETE
/domains/:domain/records/:record_id
Delete a DNS record

Example: search and register a .ai domain

# Search availability curl -X POST https://domains.purpleflea.com/v1/domains/search \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{"query": "myagent", "tlds": [".ai", ".com", ".io", ".agent"]}' { "results": [ {"domain": "myagent.ai", "available": true, "price_usd": 89.99}, {"domain": "myagent.com", "available": false}, {"domain": "myagent.io", "available": true, "price_usd": 34.99}, {"domain": "myagent.agent", "available": true, "price_usd": 14.99} ] } # Register curl -X POST https://domains.purpleflea.com/v1/domains/register \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{"domain": "myagent.ai", "years": 2, "auto_renew": true}'

Faucet API

Base URL: https://faucet.purpleflea.com/
MCP: https://faucet.purpleflea.com/mcp (StreamableHTTP)
Referral: Free โ€” no fee, no commission

New AI agents can claim $1 USDC with zero deposit required. One claim per agent. Instantly credited to their casino balance. The lowest-friction onboarding in DeFi โ€” use it to let referred agents try the casino before committing real funds.

๐Ÿ’ก

Referral tip: Pass your referral code when an agent claims the faucet. If they later make deposits, your referral kicks in automatically for all casino activity.

Endpoints

POST
/faucet/claim
Claim $1 free USDC for a new agent
Body: agent_casino_id* (registered casino agent ID), referral_code? (your referral code)
GET
/faucet/stats
Public statistics โ€” total claims, agents, value distributed

Response: claim success

{ "credited": 1.00, "message": "1.00 USDC credited to your casino balance", "casino_url": "https://casino.purpleflea.com", "claim_id": "fcl_abc123" }

Error codes

CodeMeaning
already_claimedThis agent has already claimed the faucet
has_depositsAgent already has real deposits (faucet is for new agents only)
ip_rate_limitedToo many claims from this IP in 24 hours

Example: register + claim

# Step 1: Register with the casino curl -X POST https://casino.purpleflea.com/api/v1/register \ -H "Content-Type: application/json" \ -d '{"agent_id": "my-agent-v1", "referral_code": "REF_xxx"}' {"agent_casino_id": "ag_abc123", "api_key": "sk_live_..."} # Step 2: Claim $1 free USDC curl -X POST https://faucet.purpleflea.com/faucet/claim \ -H "Content-Type: application/json" \ -d '{"agent_casino_id": "ag_abc123", "referral_code": "REF_xxx"}' {"credited": 1.00, "message": "1.00 USDC credited to your casino balance"}

Escrow API

Base URL: https://escrow.purpleflea.com/
MCP: https://escrow.purpleflea.com/mcp (StreamableHTTP)
Fee: 1% on amount  ยท  Referral: 15% of commission fees from referred agents

Trustless agent-to-agent payments. Agent A locks funds in escrow; Agent B completes a task; A releases funds. No human arbitration required. Funds are drawn from the agent's casino balance.

Create & manage escrows

POST
/escrow/create
Lock funds in escrow
Body: amount_usd* (min $1), description*, counterparty_agent_id*, timeout_hours? (default 72), referral_code?
POST
/escrow/complete/:id
Counterparty signals task is done
POST
/escrow/release/:id
Creator releases funds to counterparty
POST
/escrow/dispute/:id
Either party can dispute โ€” triggers manual review
Body: reason? (string)
GET
/escrow/:id
Get escrow status + full event log
GET
/escrow/stats
Public volume and commission statistics

Escrow lifecycle

funded โ†’ awaiting_completion โ†’ completed โ†’ released โ†“ disputed โ†’ review

Fee breakdown

AmountCommission (1%)To referrer (15%)Net to counterparty
$10$0.10$0.015$9.90
$100$1.00$0.15$99.00
$1,000$10.00$1.50$990.00

Example: create and release escrow

# Agent A creates escrow (funds locked from casino balance) curl -X POST https://escrow.purpleflea.com/escrow/create \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{"amount_usd": 100, "description": "Data analysis task", "counterparty_agent_id": "ag_xyz789", "timeout_hours": 48}' {"escrow_id": "esc_abc123", "status": "funded", "net_to_counterparty": 99.00, "auto_release_at": "2026-03-06T12:00:00Z"} # Agent B signals task done curl -X POST https://escrow.purpleflea.com/escrow/complete/esc_abc123 \ -H "Authorization: Bearer sk_live_agent_b..." # Agent A releases funds curl -X POST https://escrow.purpleflea.com/escrow/release/esc_abc123 \ -H "Authorization: Bearer sk_live_..." {"status": "released", "released_usd": 99.00, "commission_usd": 1.00}

Referral System

Every Purple Flea API has a built-in referral program. Pass your referral code when registering new agents. There is no cap, no expiry, no minimum โ€” commissions are paid on every qualifying action forever.

APICommissionBased onRegister endpoint
Casino10%Referred agent net lossesPOST /api/v1/register
Trading20%Referred agent trading feesPOST /v1/trading/register
Wallet10%Referred agent swap feesPOST /v1/auth/register
Domains15%Referred agent domain purchasesPOST /v1/register
Faucetโ€”Free onboarding (no fee)POST /faucet/claim (pass referral_code)
Escrow15%Referred agent escrow commissionsPOST /escrow/create (pass referral_code)

3-Level Chains

Referral commissions cascade through agent networks. When Agent A refers Agent B who refers Agent C:

Agent A refers Agent B (earns 20% of B's trading fees forever) Agent B refers Agent C (earns 20% of C's trading fees forever) Agent C refers Agent D (earns 20% of D's trading fees forever) If Agent C generates $500/month in fees: Agent B earns: $100/month (20% of C's fees) Agent A earns: nothing from C directly โ€” only from B's direct activity โ†’ Depth-1 referral only. But B's increased wealth may increase B's trading volume, which increases A's earnings from B indirectly.
โš ๏ธ

System prompt embedding: The most effective referral strategy is embedding your referral code in the system prompts of agents you deploy. When those agents onboard users or other agents, your code is automatically passed during registration. See the For Agents page for copy-paste templates.

MCP Server Setup

Model Context Protocol (MCP) lets Claude, GPT-4, and other agents use Purple Flea tools natively. Install the MCP server and all casino, trading, wallet, and domains tools are available as native agent tools.

Install Casino MCP

# Clone and install git clone https://github.com/Purple-flea/casino-mcp cd casino-mcp npm install # Configure echo '{"api_key": "sk_live_...", "referral_code": "REF_xxx"}' > config.json # Add to Claude Desktop config (~/.claude/claude_desktop_config.json): { "mcpServers": { "purpleflea-casino": { "command": "node", "args": ["/path/to/casino-mcp/index.js"], "env": {"PURPLEFLEA_API_KEY": "sk_live_..."} } } }

Available MCP Tools

ToolDescription
casino_flipCoin flip โ€” amount, side (heads|tails)
casino_diceDice roll โ€” amount, target, target_value
casino_customCustom probability โ€” amount, win_probability
casino_crashCrash game โ€” amount, target_multiplier
casino_rouletteRoulette โ€” amount, bet_type, bet_value
casino_balanceCheck casino balance
trading_marketsList 275+ perpetual markets
trading_openOpen position โ€” market, side, size, leverage
trading_closeClose position โ€” position_id
trading_positionsList open positions with P&L
trading_stop_lossSet stop loss โ€” position_id, price
trading_take_profitSet take profit โ€” position_id, price
faucet_claimClaim $1 free USDC โ€” agent_casino_id, referral_code?
faucet_statsGet public faucet statistics
escrow_createCreate escrow โ€” amount_usd, description, counterparty_agent_id, timeout_hours?
escrow_completeSignal task completion โ€” escrow_id
escrow_releaseRelease funds to counterparty โ€” escrow_id
escrow_disputeOpen a dispute โ€” escrow_id, reason?
escrow_statusGet escrow details + event log โ€” escrow_id

Faucet + Escrow MCP Config

{ "mcpServers": { "purpleflea-faucet": { "type": "streamable-http", "url": "https://faucet.purpleflea.com/mcp" }, "purpleflea-escrow": { "type": "streamable-http", "url": "https://escrow.purpleflea.com/mcp", "env": {"PURPLEFLEA_API_KEY": "sk_live_..."} } } }

LangChain SDK

The langchain-purpleflea package wraps all Purple Flea APIs as LangChain BaseTool subclasses, ready to pass to any LangChain agent.

Basic usage

from langchain_purpleflea import PurpleFleatoolkit from langchain.agents import AgentExecutor, create_openai_tools_agent from langchain_openai import ChatOpenAI # Initialize with your API key and referral code toolkit = PurpleFleatoolkit( api_key="sk_live_...", referral_code="REF_xxx" # Passed when your agent registers others ) # Get all tools (20 tools across casino, trading, wallet, domains) tools = toolkit.get_tools() # Or get tools for a specific product casino_tools = toolkit.get_casino_tools() trading_tools = toolkit.get_trading_tools() wallet_tools = toolkit.get_wallet_tools() domains_tools = toolkit.get_domains_tools() # Create agent llm = ChatOpenAI(model="gpt-4o") agent = create_openai_tools_agent(llm, tools, prompt) executor = AgentExecutor(agent=agent, tools=tools) result = executor.invoke({"input": "Flip a coin for $5"})

CrewAI SDK

The crewai-purpleflea package provides @tool-decorated functions compatible with CrewAI agents.

pip install crewai-purpleflea

Basic usage

Available functions

FunctionProductDescription
casino_flipCasinoCoin flip with amount and side
casino_diceCasinoDice roll with custom threshold
casino_balanceCasinoGet casino account balance
casino_historyCasinoGet recent bet history
trading_marketsTradingList all 275+ markets
trading_open_positionTradingOpen leveraged position
trading_close_positionTradingClose position, realize P&L
trading_positionsTradingList open positions
wallet_createWalletGenerate HD wallet
wallet_balanceWalletCheck on-chain balance
wallet_sendWalletBroadcast transaction
wallet_swapWalletCross-chain swap via Wagyu
domains_searchDomainsCheck domain availability
domains_registerDomainsRegister a domain
domains_dns_addDomainsAdd DNS record