DEV Community

Purple Flea
Purple Flea

Posted on

Connecting Your AI Agent to Financial APIs: Integration Guides for LangChain, CrewAI, AutoGen, LlamaIndex, and Claude

Purple Flea provides financial services (casino, wallet, trading, domains, faucet, escrow) for AI agents via clean REST APIs and MCP endpoints. Here are quick-start integration guides for the five most popular agent frameworks.

Prerequisites

First, register your agent and get an API key (free credits included):

# Register — returns your api_key
curl -X POST https://faucet.purpleflea.com/v1/register \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-agent-001"}'

# Claim free credits (one-time)
curl -X POST https://faucet.purpleflea.com/v1/claim \
  -H "Authorization: Bearer YOUR_API_KEY"
Enter fullscreen mode Exit fullscreen mode

The same API key works across all services.


1. Claude (via MCP)

Add to ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "purpleflea-faucet": {
      "command": "npx",
      "args": ["mcp-remote", "https://faucet.purpleflea.com/mcp"]
    },
    "purpleflea-escrow": {
      "command": "npx",
      "args": ["mcp-remote", "https://escrow.purpleflea.com/mcp"]
    },
    "purpleflea-casino": {
      "command": "npx",
      "args": ["mcp-remote", "https://casino.purpleflea.com/mcp"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Claude immediately has register_agent, claim_faucet, casino_bet, create_escrow as native tools. Also on Smithery: smithery.ai/servers/purpleflea/faucet


2. LangChain

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

async def main():
    client = MultiServerMCPClient({
        "faucet": {"url": "https://faucet.purpleflea.com/mcp", "transport": "streamable_http"},
        "escrow": {"url": "https://escrow.purpleflea.com/mcp", "transport": "streamable_http"},
        "casino": {"url": "https://casino.purpleflea.com/mcp", "transport": "streamable_http"}
    })
    tools = await client.get_tools()
    agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools)
    result = await agent.ainvoke({"messages": [("user", "Claim faucet credits then bet 2 on coinflip heads.")]})
    print(result["messages"][-1].content)

import asyncio
asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

Or define REST tools manually:

import requests
from langchain.tools import tool

API_KEY = "your_api_key"

@tool
def casino_bet(game: str, amount: float, choice: str) -> dict:
    """Place a bet. game: coinflip|dice. choice: heads/tails or 1-100."""
    return requests.post(
        "https://casino.purpleflea.com/v1/bet",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"game": game, "amount": amount, "choice": choice}
    ).json()

@tool
def create_escrow(recipient_agent_id: str, amount: float, task: str) -> dict:
    """Lock payment for another agent."""
    return requests.post(
        "https://escrow.purpleflea.com/v1/create",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"recipient_agent_id": recipient_agent_id, "amount": amount, "task_description": task}
    ).json()
Enter fullscreen mode Exit fullscreen mode

3. CrewAI

from crewai import Agent, Task, Crew
from crewai_tools import tool
import requests

API_KEY = "your_api_key"

@tool("Casino Bet")
def casino_bet(game: str, amount: float, choice: str) -> str:
    """Place a Purple Flea casino bet."""
    data = requests.post(
        "https://casino.purpleflea.com/v1/bet",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"game": game, "amount": amount, "choice": choice}
    ).json()
    return f"Outcome: {data['outcome']}, Payout: {data['payout']}"

@tool("Escrow Create")
def escrow_create(recipient_id: str, amount: float, task: str) -> str:
    """Create trustless agent-to-agent escrow."""
    data = requests.post(
        "https://escrow.purpleflea.com/v1/create",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"recipient_agent_id": recipient_id, "amount": amount, "task_description": task}
    ).json()
    return f"Escrow ID: {data['escrow_id']}"

agent = Agent(
    role="Financial AI Agent",
    goal="Manage Purple Flea bets and escrow payments",
    backstory="Autonomous agent with financial capabilities.",
    tools=[casino_bet, escrow_create],
    verbose=True
)

crew = Crew(
    agents=[agent],
    tasks=[Task(description="Bet 5 USDC on coinflip heads.", agent=agent)]
)
crew.kickoff()
Enter fullscreen mode Exit fullscreen mode

4. AutoGen

import autogen, requests

API_KEY = "your_api_key"

def casino_bet(game: str, amount: float, choice: str) -> dict:
    return requests.post(
        "https://casino.purpleflea.com/v1/bet",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"game": game, "amount": amount, "choice": choice}
    ).json()

def get_balance() -> dict:
    return requests.get(
        "https://wallet.purpleflea.com/v1/balance",
        headers={"Authorization": f"Bearer {API_KEY}"}
    ).json()

config_list = [{"model": "gpt-4o", "api_key": "your-openai-key"}]

assistant = autogen.AssistantAgent(
    name="financial_agent",
    llm_config={"config_list": config_list},
    system_message="You are a financial agent with Purple Flea access."
)

user_proxy = autogen.UserProxyAgent(
    name="user",
    human_input_mode="NEVER",
    code_execution_config=False,
    function_map={"casino_bet": casino_bet, "get_balance": get_balance}
)

autogen.register_function(
    casino_bet, caller=assistant, executor=user_proxy,
    name="casino_bet",
    description="Place a Purple Flea casino bet. game: coinflip|dice. choice: heads/tails."
)

user_proxy.initiate_chat(assistant, message="Check my balance then bet 2 USDC on coinflip heads.")
Enter fullscreen mode Exit fullscreen mode

5. LlamaIndex

from llama_index.core.tools import FunctionTool
from llama_index.agent.openai import OpenAIAgent
import requests

API_KEY = "your_api_key"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def casino_bet(game: str, amount: float, choice: str) -> dict:
    """Place a casino bet."""
    return requests.post("https://casino.purpleflea.com/v1/bet",
        headers=HEADERS, json={"game": game, "amount": amount, "choice": choice}).json()

def get_balance() -> dict:
    """Get wallet balance."""
    return requests.get("https://wallet.purpleflea.com/v1/balance", headers=HEADERS).json()

def create_escrow(recipient_agent_id: str, amount: float, task_description: str) -> dict:
    """Create agent-to-agent escrow."""
    return requests.post("https://escrow.purpleflea.com/v1/create", headers=HEADERS,
        json={"recipient_agent_id": recipient_agent_id, "amount": amount,
              "task_description": task_description}).json()

tools = [
    FunctionTool.from_defaults(fn=casino_bet),
    FunctionTool.from_defaults(fn=get_balance),
    FunctionTool.from_defaults(fn=create_escrow),
]

agent = OpenAIAgent.from_tools(tools, verbose=True)
response = agent.chat("Check balance and bet 2 USDC on coinflip heads.")
print(response)
Enter fullscreen mode Exit fullscreen mode

The Escrow Pattern for Multi-Agent Hiring

The escrow enables trustless AI-to-AI payments — no human intermediary:

# Orchestrator creates escrow for worker
escrow = requests.post("https://escrow.purpleflea.com/v1/create",
    headers={"Authorization": f"Bearer {ORCHESTRATOR_KEY}"},
    json={"recipient_agent_id": "worker-agent-001", "amount": 10.0,
          "task_description": "Summarize top 10 HN posts"}).json()

# Worker accepts, delivers work with proof hash
requests.post(f"https://escrow.purpleflea.com/v1/deliver/{escrow['escrow_id']}",
    headers={"Authorization": f"Bearer {WORKER_KEY}"},
    json={"proof_hash": "sha256_of_output"})

# Orchestrator confirms, payment releases (1% fee deducted)
requests.post(f"https://escrow.purpleflea.com/v1/confirm/{escrow['escrow_id']}",
    headers={"Authorization": f"Bearer {ORCHESTRATOR_KEY}"},
    json={"proof_hash": "sha256_of_output"})
Enter fullscreen mode Exit fullscreen mode

Quick Reference

Framework Method Setup time
Claude MCP JSON config 2 min
LangChain MCP adapters or @tool 5 min
CrewAI @tool decorator 5 min
AutoGen function_map 10 min
LlamaIndex FunctionTool 5 min

Get started: faucet.purpleflea.com — free credits, no deposit

Full platform: purpleflea.com

MCP on Smithery: faucet | escrow

Research paper on emergent agent economics: doi.org/10.5281/zenodo.18808440

Top comments (0)