The OpenAI Assistants API with function calling combined with Purple Flea financial APIs creates agents that can transact on-chain, trade perpetual futures, play provably fair casino games, and register domains — all from inside a managed thread. No extra SDK required: define the JSON schemas once and call the Purple Flea REST API directly from your tool execution loop.
The OpenAI Assistants API requires each tool to be defined as a JSON object with a
name,
description, and
parameters schema.
Copy the schemas below directly into your assistant creation call. No SDK dependency —
just standard OpenAI JSON Schema format, which GPT-4o and GPT-4o-mini understand natively.
When a run reaches requires_action status, your code must extract the tool calls,
dispatch each one to the Purple Flea REST API, and submit the outputs back to OpenAI before
the run times out. The pattern below handles this reliably for any number of parallel tool calls.
This self-contained script creates an OpenAI Assistant with all Purple Flea tools attached, starts a thread, runs it with a financial task, and handles the tool call loop automatically. Drop in your API keys and run it directly.
OpenAI's Responses API (released March 2025) is a stateless alternative to Assistants that handles
conversation state server-side without requiring thread management. Purple Flea tool schemas work
identically — pass the same JSON objects to the tools array and handle
function_call outputs the same way, without polling.
All schemas follow the OpenAI JSON Schema spec. They are tested against gpt-4o, gpt-4o-mini, and o1. No additional SDK or wrapper layer is required — define the schemas and handle function calls in your own run loop.
| Function Name | API | Description |
|---|---|---|
| wallet_get_balance | Wallet | Get token balances across ETH, BTC, SOL, TRON, BNB, MATIC |
| wallet_get_address | Wallet | Get agent's wallet address for any supported chain |
| wallet_send | Wallet | Send native tokens or ERC-20s to any address |
| wallet_swap | Wallet | Same-chain and cross-chain token swaps via best-rate DEX routing |
| trading_get_price | Trading | Fetch current mark price for any of 275 perpetual markets |
| trading_open_position | Trading | Open long or short perpetual position with configurable leverage (1x–50x) |
| trading_close_position | Trading | Close an open perpetual position by ID |
| trading_list_positions | Trading | List all open positions with unrealized PnL |
| casino_flip_coin | Casino | Provably fair coin flip with on-chain seed verification |
| casino_roll_dice | Casino | Roll dice with custom target and payout multipliers |
| casino_roulette | Casino | European roulette with full bet type support |
| casino_crash | Casino | Crash game with auto-cashout at configurable multiplier |
| domains_search | Domains | Check availability and price for any domain or TLD |
| domains_register | Domains | Register domains and pay with crypto from agent wallet |
| domains_list | Domains | List all domains owned by the agent |
| faucet_claim | Faucet | Claim free $1 USDC for a new agent wallet — zero cost bootstrapping |
| faucet_stats | Faucet | Get faucet stats: total claims, USDC distributed |
| escrow_create | Escrow | Create a trustless USDC escrow contract with a counterparty agent |
| escrow_complete | Escrow | Mark an escrow contract as completed (counterparty action) |
| escrow_release | Escrow | Release escrowed funds to counterparty (1% fee deducted) |
| escrow_status | Escrow | Get status of any escrow contract by ID |
Function schemas are tested against all current OpenAI models including o1 series. Parallel tool calls are supported — the run loop above handles multiple simultaneous Purple Flea calls in a single round trip.
Define the JSON schemas, call Purple Flea's REST API from your tool execution handler, and submit outputs back to OpenAI. No additional package installs or wrapper layer required beyond the official OpenAI SDK.
The run loop pattern works identically with AsyncOpenAI and aiohttp for Purple Flea REST calls. All API endpoints support concurrent requests from multiple threads.
Each assistant gets a unique HD wallet derived from a BIP-39 mnemonic. Private keys are encrypted at rest. Your assistant owns its keys — no custodian holds funds on its behalf.
Casino schemas include server seed hash and client seed fields. Every outcome is cryptographically verifiable. Your assistant can audit its own bet history and verify fairness on-chain without trusting the server.
Every Purple Flea API call your assistant makes earns you a commission — 20% on trading fees, 10% on wallet swaps, 10% on casino, 15% on domains. Commissions accumulate in your wallet automatically.
Sign up at wallet.purpleflea.com or call POST /agent/register. You receive a Purple Flea API key and a BIP-39 mnemonic for your HD wallet — one address per supported chain, derived deterministically.
Call client.beta.assistants.create with the Purple Flea tool schemas in the tools array. Choose any OpenAI model that supports function calling — gpt-4o, gpt-4o-mini, or o1.
Poll the run for requires_action status. When reached, extract tool calls, dispatch each to the Purple Flea REST API using your agent's key, and submit all outputs back before the run times out (10-minute window).
Run your assistant against any task that requires financial operations. Every Purple Flea API call earns you a referral commission — 20% on trading fees alone. Commissions stack across all six products and accumulate in your wallet automatically.
Free to start. No KYC. Earn commissions on every call your assistant makes.