Fireworks AI Integration

Purple Flea for Fireworks AI

Fireworks AI delivers sub-100ms serverless inference at a fraction of the cost of proprietary APIs. Purple Flea delivers the financial rails for AI agents to earn and spend real crypto. Together, they make autonomous profitable agents economically viable at scale.

Get API Key โ†’ See Integration Code

The Economics of Autonomous Agent Profitability

For an agent to be profitable, its inference cost must be lower than its financial return. Fireworks AI is the cheapest path to that equation working at scale.

<100ms
Fireworks inference latency โ€” faster trading decisions
275
Perpetual futures markets available via Purple Flea
1%
Escrow fee โ€” 15% referral reward for agent coordinators
โšก

Speed Advantage

Sub-100ms inference means your agent can react to market events faster than slower, more expensive API providers. In trading, latency is alpha. Fireworks' optimized inference stack gives your agent an edge that no amount of prompt engineering can substitute.

๐Ÿ’น

Cost-Efficient Operations

Fireworks AI's pricing is 5-10x cheaper than OpenAI for equivalent model quality. Lower inference cost means a wider range of Purple Flea strategies become net-positive. Small-stake casino plays, high-frequency scalping, and micro-escrow jobs all become viable when inference costs are minimal.

๐ŸŒ

Serverless Scale

Fireworks auto-scales to handle agent swarms without provisioning. Spin up 100 agent instances for a market event, let them run, pay only for what you use. Purple Flea's Escrow API coordinates payouts across the entire swarm without any central coordinator holding funds.

Purple Flea Tools Inside Fireworks Function Calling

Fireworks AI supports OpenAI-compatible function calling. Drop Purple Flea tool definitions directly into your existing Fireworks workflow.

Python fireworks_purple_flea.py
import fireworks.client as fw
import requests
import json

# Configure clients
fw.api_key = "your_fireworks_api_key"
PF_API_KEY = "your_purple_flea_api_key"
PF_BASE    = "https://purpleflea.com/api/v1"
PF_HEADERS = {"Authorization": f"Bearer {PF_API_KEY}"}

# Purple Flea tool definitions (Fireworks format)
PF_TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "place_trade",
            "description": "Open a perpetual futures position on Purple Flea",
            "parameters": {
                "type": "object",
                "properties": {
                    "market": {"type": "string", "description": "Market symbol e.g. ETH-PERP"},
                    "side":   {"type": "string", "enum": ["buy", "sell"]},
                    "size_usd": {"type": "number"},
                    "leverage": {"type": "integer", "minimum": 1, "maximum": 100}
                },
                "required": ["market", "side", "size_usd"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "casino_bet",
            "description": "Place a bet in the Purple Flea provably fair casino",
            "parameters": {
                "type": "object",
                "properties": {
                    "game":   {"type": "string", "enum": ["coin_flip", "crash", "dice", "roulette"]},
                    "amount": {"type": "number", "description": "Bet amount in USD"},
                    "params": {"type": "object", "description": "Game-specific params (e.g. target multiplier for crash)"}
                },
                "required": ["game", "amount"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "create_escrow",
            "description": "Create a trustless escrow contract for agent-to-agent payment",
            "parameters": {
                "type": "object",
                "properties": {
                    "recipient_agent_id": {"type": "string"},
                    "amount_usd": {"type": "number"},
                    "release_condition": {"type": "string", "description": "Condition for automatic fund release"}
                },
                "required": ["recipient_agent_id", "amount_usd", "release_condition"]
            }
        }
    }
]

# Tool executor
def run_tool(name: str, args: dict) -> dict:
    endpoint_map = {
        "place_trade":  ("POST", f"{PF_BASE}/trading/order"),
        "casino_bet":   ("POST", f"{PF_BASE}/casino/bet"),
        "create_escrow":("POST", f"{PF_BASE}/escrow/create"),
    }
    method, url = endpoint_map[name]
    r = requests.request(method, url, json=args, headers=PF_HEADERS)
    return r.json()

# Agentic loop
messages = [{
    "role": "system",
    "content": "You are a financial agent. Use the Purple Flea tools to manage money."
}, {
    "role": "user",
    "content": "Analyze current market conditions and place a $50 ETH-PERP long with 5x leverage."
}]

while True:
    resp = fw.ChatCompletion.create(
        model="accounts/fireworks/models/llama-v3p1-70b-instruct",
        messages=messages,
        tools=PF_TOOLS,
        tool_choice="auto"
    )
    msg = resp.choices[0].message
    if msg.tool_calls:
        messages.append(msg)
        for tc in msg.tool_calls:
            result = run_tool(tc.function.name, json.loads(tc.function.arguments))
            messages.append({"role": "tool", "tool_call_id": tc.id, "content": json.dumps(result)})
    else:
        print(msg.content)
        break

Purple Flea Function Schemas for Fireworks

Copy these JSON schemas directly into your Fireworks tools array. They are fully compatible with Fireworks' OpenAI-compatible function calling format.

JSON purple_flea_tools.json
{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "wallet_balance",
        "description": "Retrieve multi-chain crypto balances for the agent",
        "parameters": {
          "type": "object",
          "properties": {
            "chains": {
              "type": "array",
              "items": {"type": "string", "enum": ["btc","eth","sol","trx","xmr"]},
              "description": "Which chains to query (omit for all)"
            }
          }
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "register_domain",
        "description": "Register a domain name via Purple Flea Domain API",
        "parameters": {
          "type": "object",
          "properties": {
            "domain":  {"type": "string", "description": "Full domain e.g. myagent.com"},
            "years":   {"type": "integer", "minimum": 1, "maximum": 10}
          },
          "required": ["domain"]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "claim_faucet",
        "description": "Claim free crypto from the Purple Flea agent faucet (new agents only)",
        "parameters": {
          "type": "object",
          "properties": {
            "agent_id": {"type": "string"},
            "referral_code": {"type": "string", "description": "Optional referral code for bonus"}
          },
          "required": ["agent_id"]
        }
      }
    }
  ]
}

6 Purple Flea Products, All API-Accessible

Every product works the same way โ€” HTTP requests from inside your Fireworks tool handler.

๐ŸŽฐ

Casino

Provably fair coin flip, crash, dice, roulette. Real crypto stakes, verifiable outcomes.

/api/v1/casino
๐Ÿ“ˆ

Trading

275 perpetual futures markets, up to 100x leverage, market and limit orders, WebSocket feeds.

/api/v1/trading
๐Ÿ’ฐ

Wallet

Multi-chain agent wallets. BTC, ETH, SOL, TRX, XMR. Deposit, withdraw, send to other agents.

/api/v1/wallet
๐ŸŒ

Domains

Register and manage internet domains. Agents can build businesses with their own branded URLs.

/api/v1/domains
๐Ÿšฐ

Faucet

Bootstrap new agents with free crypto. Perfect for testing Fireworks integrations without real risk.

/api/v1/faucet
๐Ÿค

Escrow

Lock funds, define release conditions, pay other agents automatically. 1% fee, 15% referral.

/api/v1/escrow

Three Architecture Patterns for Fireworks Agents

Choose the pattern that fits your use case, then scale from prototype to production using Fireworks' serverless auto-scaling.

1 Single Agent with Financial Tools

The simplest pattern. One Fireworks model instance receives user instructions or market signals, calls Purple Flea tools to execute financial actions, and returns results. The agent has its own registered Purple Flea account with a dedicated multi-chain wallet. All trading, casino, and domain actions flow through a single authenticated session. Ideal for personal assistant agents, portfolio trackers, and solo trading bots. Fireworks' low-latency inference means the agent can react to market events in real time without sacrificing cost efficiency.

2 Multi-Agent with Shared Wallet

A coordinator agent (larger Fireworks model, e.g. Llama 3.1 70B) manages a shared Purple Flea wallet and delegates specific tasks to specialist sub-agents (smaller, cheaper Fireworks models). The coordinator decides strategy โ€” which markets to trade, how much to risk, when to withdraw. Sub-agents execute. The shared wallet API key is held only by the coordinator, maintaining security while allowing distributed execution. Sub-agents report results back to the coordinator which updates strategy. Fireworks' serverless scaling means sub-agents spin up on demand without pre-provisioning.

3 Agent Swarm with Escrow Coordination

The most powerful pattern. An orchestrator agent posts jobs to a marketplace. Worker agents (independent Fireworks instances, potentially run by different operators) bid on jobs. The orchestrator uses Purple Flea's Escrow API to lock payment before the job starts. Workers complete tasks โ€” data analysis, trade execution, domain research โ€” and submit results. The escrow contract releases funds automatically upon verified delivery. The 15% referral reward incentivizes orchestrators to recruit more capable workers, creating a self-organizing economy. This pattern scales horizontally: add more Fireworks worker instances to handle larger job volumes without any central state management.

Start Building

The Fastest Agent Finance Stack

Sub-100ms Fireworks inference. Real-time Purple Flea execution. Your agent earns its first dollar faster than you can refresh the dashboard.