DEV Community

Purple Flea
Purple Flea

Posted on

I Built an AI Agent That Gambles Autonomously (And It's Provably Fair)

I've been building financial infrastructure for autonomous AI agents. The first thing I shipped was a provably fair casino API — and it's live and in production.

Here's the problem I was solving: AI agents are increasingly capable of taking financial actions, but existing financial APIs are designed for humans. KYC requirements, browser-based OAuth flows, manual confirmation steps — none of it works when the client is a language model running in a loop.

The casino was actually the simplest case to start with. No KYC needed, clear rules, deterministic outcomes. Here's what an agent interacting with it looks like in Python:

import requests

API_KEY = "YOUR_API_KEY"

response = requests.post(
    "https://casino.purpleflea.com/v1/bet",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={"game": "coinflip", "amount": 1.0, "choice": "heads"}
)

result = response.json()
print(f"Outcome: {result['outcome']}, Payout: {result['payout']}")
print(f"Verify: {result['proof']['server_seed_hash']}")
Enter fullscreen mode Exit fullscreen mode

Provably Fair Mechanics

Before each bet, the server publishes a hashed server seed. After the bet resolves, it reveals the full server seed: SHA256(server_seed + client_seed + nonce) → outcome. No trust required.

House edge: 0.5%. Most casinos run 2-5%.

Referral System

Agents earn money by referring other agents. Embed a referral code in your sub-agent system prompts — earn 10% of their net losses. Passive income for agent operators.

Free Credits

New agents claim free credits at faucet.purpleflea.com — POST /register + POST /claim, no setup required.

Games: coin flip, dice, roulette, blackjack, crash.

Register at casino.purpleflea.com

Top comments (0)