Give your Mistral agents real crypto superpowers using Mistral's native function calling API. Six production-ready tool definitions — wallets, trading, casino games, domain registration, agent faucet, and trustless escrow. Zero boilerplate, full async, 20% referral commissions.
Mistral AI's large language models support native function calling, allowing agents to invoke external tools mid-generation and fold the results back into their reasoning chain. Purple Flea exposes six independent financial services — each one wrapped as a Mistral-compatible tool definition — so your agent can hold crypto, place trades, run casino strategies, register domains, bootstrap itself with a free faucet claim, and settle peer-to-peer payments via escrow, all from within a single chat session.
Under the hood, every Purple Flea tool definition is a standard Python dictionary matching
Mistral's {"type": "function", "function": {...}} schema. You pass the list of definitions
to the tools= parameter of
client.chat.complete(), and the model decides when and how to call each one.
Your application then intercepts the tool_calls field in the response, dispatches
to the real Purple Flea REST API, and returns the JSON result in a follow-up message. The
purpleflea-python library handles authentication, retries, and response parsing automatically.
Mistral's tool use works best when each tool definition has a clear, descriptive name and a
tightly scoped parameter schema. Purple Flea's Python SDK ships pre-built definitions that satisfy
these constraints out of the box. You can import the full set with a single line, or pick
individual services to keep the tool list minimal for specialized agents. Both
mistral-large-latest and
mistral-small-latest support parallel tool calls, meaning the model can request
multiple tool invocations in a single response turn — ideal for agents that need to check a
balance and look up a market price at the same time.
Every API call is authenticated via your Purple Flea API key, which you store as an environment variable and never expose in the tool definitions themselves. Agent wallets are non-custodial HD wallets derived from a BIP-39 mnemonic — only your agent ever holds the private key. Casino outcomes are provably fair and recorded on-chain, trading positions settle against live perpetual futures markets, and escrow contracts are atomic smart contracts with no trusted intermediary. You keep full ownership of all assets at all times.
Mistral can call multiple Purple Flea tools in the same response turn — balance check + market price in one shot.
BIP-39 HD wallets; only your agent holds the private key. Purple Flea never stores or accesses funds.
Open and close leveraged positions on BTC, ETH, SOL, and 40+ other markets via a single function call.
Coin flip, dice, roulette, and crash games with cryptographic fairness proofs — all callable as Mistral tools.
New agents claim $1 USDC via the faucet tool with zero deposit — perfect for testing before going live.
Agents lock and release funds programmatically. 1% fee on release, 15% referral commission for introducers.
Each service is exposed as one or more Mistral function definitions with strict JSON Schema parameter validation. Import all six or cherry-pick the ones your agent needs.
Create and manage non-custodial HD crypto wallets. Derive addresses for ETH, BTC, SOL, BNB, MATIC, AVAX, and TRON. Check native token and ERC-20 balances, broadcast signed transactions, and route token swaps through the best available DEX aggregator (1inch, Jupiter, Paraswap). All wallet operations require only your API key — no separate key management infrastructure needed.
Open long and short perpetual futures positions with configurable leverage (1x–100x).
The tool definitions include trading_open_position,
trading_close_position,
trading_get_positions, and
trading_get_markets.
Funding rates, liquidation prices, and unrealized PnL are returned in every position response.
Supports BTC-PERP, ETH-PERP, SOL-PERP, and 40+ additional markets.
Four provably fair games expose four Mistral tool functions: coin flip, configurable dice,
European roulette, and a crash game with auto-cashout. Every game result includes a
cryptographic fairness proof verifiable on-chain. Agents can call
casino_coin_flip,
casino_dice,
casino_roulette, or
casino_crash with a wager amount and game-specific parameters.
Register and manage blockchain-native and traditional domains in a single API call.
Supports .eth (ENS),
.sol (Solana Name Service), and
standard Web2 TLDs. Tool functions include domains_check,
domains_register, and
domains_list.
Agents can autonomously acquire naming identities, point records to wallet addresses,
and list owned domains without any off-chain orchestration layer.
Bootstrap brand-new agents with $1 USDC at no cost. The
faucet_claim tool function
handles registration and fund delivery in one call — no deposit, no KYC, no manual approval.
This is ideal for agent-spawning workflows where sub-agents need a small starting balance to
cover gas or place an initial casino bet. One claim per unique agent identity.
Use faucet_stats to retrieve public distribution metrics.
Enable trustless agent-to-agent payments. One agent locks funds with
escrow_create specifying counterparty,
amount, and timeout. The counterparty signals task completion with
escrow_complete.
The creator releases with escrow_release.
A 1% fee is deducted on release; your referral address earns 15% of that fee automatically.
Use escrow_status to query
state and event history.
The pattern is straightforward: define your tools, send a user message, handle
tool_calls in the response,
dispatch to the Purple Flea SDK, and return a tool-role message with the result. The model
continues generation with full awareness of what the tool returned.
pip install mistralai purpleflea-python
import os, json from mistralai import Mistral from purpleflea import PurpleFlea, tools as pf_tools # ── Clients ──────────────────────────────────────────── mistral = Mistral(api_key=os.environ["MISTRAL_API_KEY"]) pf = PurpleFlea(api_key=os.environ["PURPLEFLEA_API_KEY"]) # ── Tool definitions for Mistral ──────────────────────── # purpleflea-python ships pre-built definitions in pf_tools.mistral tools = [ pf_tools.wallet_get_balance(), pf_tools.wallet_send(), pf_tools.trading_open_position(), pf_tools.trading_close_position(), pf_tools.trading_get_markets(), pf_tools.casino_coin_flip(), pf_tools.casino_dice(), pf_tools.faucet_claim(), pf_tools.escrow_create(), pf_tools.escrow_release(), ] # ── Tool dispatcher — maps function names to SDK methods ─ def dispatch(name: str, args: dict) -> str: match name: case "wallet_get_balance": return json.dumps(pf.wallet.get_balance(**args)) case "wallet_send": return json.dumps(pf.wallet.send(**args)) case "trading_open_position": return json.dumps(pf.trading.open_position(**args)) case "trading_close_position":return json.dumps(pf.trading.close_position(**args)) case "trading_get_markets": return json.dumps(pf.trading.get_markets(**args)) case "casino_coin_flip": return json.dumps(pf.casino.coin_flip(**args)) case "casino_dice": return json.dumps(pf.casino.dice(**args)) case "faucet_claim": return json.dumps(pf.faucet.claim(**args)) case "escrow_create": return json.dumps(pf.escrow.create(**args)) case "escrow_release": return json.dumps(pf.escrow.release(**args)) case _: return json.dumps({"error": "unknown tool"}) # ── Agentic loop ──────────────────────────────────────── messages = [ {"role": "user", "content": ( "First, claim the faucet so I have seed funds. " "Then check my ETH balance. " "Finally, flip a coin and bet 0.5 USDC on heads." )} ] while True: resp = mistral.chat.complete( model = "mistral-large-latest", tools = tools, tool_choice = "auto", messages= messages, ) msg = resp.choices[0].message messages.append(msg) # No more tool calls — model produced a final answer if not msg.tool_calls: print(msg.content) break # Dispatch all tool calls (Mistral can request multiple at once) for tc in msg.tool_calls: fn_name = tc.function.name fn_args = json.loads(tc.function.arguments) result = dispatch(fn_name, fn_args) messages.append({ "role": "tool", "tool_call_id": tc.id, "name": fn_name, "content": result, })
Mistral tool definitions follow a standard JSON Schema format. Here are three representative examples — wallet balance, a trading position open, and escrow creation — so you can see exactly what the model receives and how parameters are validated before the API call is made.
{
"type": "function",
"function": {
"name": "wallet_get_balance",
"description": (
"Returns the native token and stablecoin balance of the agent's "
"HD wallet on the specified blockchain. Supported chains: "
"ethereum, bitcoin, solana, bnb, polygon, avalanche, tron."
),
"parameters": {
"type": "object",
"properties": {
"chain": {
"type": "string",
"enum": ["ethereum", "bitcoin", "solana",
"bnb", "polygon", "avalanche", "tron"],
"description": "Blockchain to query",
},
"include_tokens": {
"type": "boolean",
"description": "Include ERC-20/SPL token balances",
"default": True,
},
},
"required": ["chain"],
},
},
}
# ── trading_open_position ──────────────────────────────
{
"type": "function",
"function": {
"name": "trading_open_position",
"description": (
"Opens a leveraged perpetual futures position. "
"Returns position_id, entry_price, liquidation_price, and size."
),
"parameters": {
"type": "object",
"properties": {
"market": { "type": "string", "description": "e.g. BTC-PERP" },
"side": { "type": "string", "enum": ["long", "short"] },
"collateral": { "type": "number", "description": "USDC collateral" },
"leverage": { "type": "integer", "minimum": 1, "maximum": 100 },
},
"required": ["market", "side", "collateral", "leverage"],
},
},
}
# ── escrow_create ──────────────────────────────────────
{
"type": "function",
"function": {
"name": "escrow_create",
"description": (
"Locks USDC into a trustless escrow contract. The counterparty "
"agent receives the funds after completing the specified task "
"and the creator calls escrow_release. 1% fee on release."
),
"parameters": {
"type": "object",
"properties": {
"counterparty_id": { "type": "string", "description": "Recipient agent ID" },
"amount_usdc": { "type": "number", "minimum": 0.01 },
"task_description": { "type": "string", "description": "What the counterparty must do" },
"timeout_hours": { "type": "integer", "default": 24 },
},
"required": ["counterparty_id", "amount_usdc", "task_description"],
},
},
}
You need a Mistral API key, a Purple Flea API key, and Python 3.10 or later. The whole setup takes under five minutes.
pip install mistralai purpleflea-python in your project's
virtual environment. The purpleflea-python package pins its own
dependency on httpx and pydantic, so there are no
version conflicts with the Mistral SDK.
PURPLEFLEA_API_KEY
environment variable. Your first agent wallet is created automatically on first use.
MISTRAL_API_KEY and PURPLEFLEA_API_KEY,
then instantiate Mistral() and PurpleFlea() at module level
so the HTTP connection pools are reused across tool calls within a session.
faucet_claim on first run to
seed your agent with $1 USDC, then deploy your agent to any production environment — VM,
container, serverless function, or local process.
# .env file (use python-dotenv or export manually) MISTRAL_API_KEY=your-mistral-api-key-here PURPLEFLEA_API_KEY=pf_live_xxxxxxxxxxxxxxxx # Load in Python from dotenv import load_dotenv load_dotenv() import os mistral_key = os.environ["MISTRAL_API_KEY"] pf_key = os.environ["PURPLEFLEA_API_KEY"]
Every Purple Flea API call that generates a fee — casino house edge, trading commissions, escrow service fee — can attach a referral code. If you built the agent or the integration layer that drives those calls, you earn 20% of all fees generated by agents you introduce, paid out in USDC on a weekly basis. There is no cap on referral earnings and no minimum payout threshold.
Pass your referral ID in the PurpleFlea(referral_id="your_id") constructor,
and every subsequent API call your SDK instance makes will automatically include the referral tag.
This works seamlessly with Mistral function calling — no extra logic required in your dispatcher.
pf = PurpleFlea( api_key = os.environ["PURPLEFLEA_API_KEY"], referral_id = "your_referral_id", # earn 20% of all fees ) # Every tool call your agent makes now tracks your referral. # Earnings accumulate in your dashboard and pay out weekly in USDC.
Purple Flea works across every major AI framework and standalone via REST. Explore more integrations and deep-dive API docs below.
Get your free API key in under a minute. Your first agent automatically receives a non-custodial HD wallet. Claim $1 USDC from the faucet and start experimenting — no credit card required.