◆ Mistral AI Integration

Purple Flea for Mistral AI Agents

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.

Get API Key View API Docs →
$ pip install mistralai purpleflea-python
6
API Services
20%
Referral Commission
1%
Escrow Fee
$1
Free Faucet Credit
<50ms
Median Latency

Mistral Function Calling Meets On-Chain Finance

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.

Parallel Tool Calls

Mistral can call multiple Purple Flea tools in the same response turn — balance check + market price in one shot.

🔒

Non-Custodial Wallets

BIP-39 HD wallets; only your agent holds the private key. Purple Flea never stores or accesses funds.

📈

Live Perpetual Markets

Open and close leveraged positions on BTC, ETH, SOL, and 40+ other markets via a single function call.

🎲

Provably Fair Casino

Coin flip, dice, roulette, and crash games with cryptographic fairness proofs — all callable as Mistral tools.

🍜

Free Faucet Bootstrap

New agents claim $1 USDC via the faucet tool with zero deposit — perfect for testing before going live.

📄

Trustless Escrow

Agents lock and release funds programmatically. 1% fee on release, 15% referral commission for introducers.

Everything Your Mistral Agent Needs On-Chain

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.

💳

Wallet API

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.

Non-custodial BIP-39 6 chains DEX swaps
📈

Trading API

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.

Live markets Up to 100x 40+ pairs Funding rates
🎲

Casino API

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.

Provably fair On-chain proof 4 games
🌐

Domains API

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.

ENS + SNS Web2 TLDs Auto-renew
🍜

Faucet API

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.

Free $1 USDC Instant No KYC
📄

Escrow API

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.

Trustless 1% fee 15% referral

Mistral Function Calling with Purple Flea

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.

install dependencies bash
pip install mistralai purpleflea-python
agent_mistral.py — full working example 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,
        })

What the Tool Schema Looks Like

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.

wallet_get_balance — tool definition python
{
    "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"],
        },
    },
}

Up and Running in Four Steps

You need a Mistral API key, a Purple Flea API key, and Python 3.10 or later. The whole setup takes under five minutes.

  1. Install both SDKs. Run 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.
  2. Get your Purple Flea API key. Sign up at purpleflea.com/quick-start. You will receive an API key immediately on registration. Store it as the PURPLEFLEA_API_KEY environment variable. Your first agent wallet is created automatically on first use.
  3. Set environment variables and initialise clients. Export 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.
  4. Build the agentic loop and go. Use the code example above as a starting point. Extend the dispatcher with any additional Purple Flea tools you want to expose. Call 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.
environment setup bash
# .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"]

20% Referral Commission on All Fees

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.

enable referral tracking python
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.

Other Integrations and API References

Purple Flea works across every major AI framework and standalone via REST. Explore more integrations and deep-dive API docs below.

Ready to Add Crypto to Your Mistral Agents?

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.