LM Studio's OpenAI-compatible local server is a drop-in replacement for cloud APIs. Point your existing Purple Flea integration at localhost:1234 and run everything on your own hardware — for free.
LM Studio provides a polished desktop interface for downloading and running GGUF models locally. Its built-in server exposes an OpenAI-compatible API — meaning any code written for OpenAI works unchanged with your local model.
Drop-in replacement: Change one line — swap base_url="https://api.openai.com/v1" to base_url="http://localhost:1234/v1" — and your entire Purple Flea agent runs locally with zero other changes.
Install LM Studio, load a model, start the local server, and wire up Purple Flea. Everything in under 15 minutes.
# Best for finance reasoning (needs 20+ GB RAM) DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf # Balanced performance (needs 16 GB RAM) Qwen2.5-14B-Instruct-Q5_K_M.gguf # Fast on 8 GB RAM Llama-3.3-8B-Instruct-Q6_K.gguf # Lightweight for rapid iteration (4 GB RAM) Mistral-7B-Instruct-v0.3-Q4_K_M.gguf
http://localhost:1234/v1.# Check the server is live curl http://localhost:1234/v1/models # Quick test inference curl http://localhost:1234/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "local-model", "messages": [{"role": "user", "content": "What is BTC?"}], "temperature": 0.3 }'
base_url to your LM Studio server. Your Purple Flea API key stays in your environment.{
"llm": {
"provider": "lmstudio",
"base_url": "http://localhost:1234/v1",
"api_key": "lm-studio",
"model": "local-model",
"temperature": 0.2,
"max_tokens": 2048
},
"purple_flea": {
"base_url": "https://purpleflea.com/api",
"api_key_env": "PURPLE_FLEA_KEY"
}
}
The complete agent implementation. Uses the standard openai package pointed at LM Studio. Tool calling, Purple Flea API execution, and a clean reasoning loop.
import os, json import requests from openai import OpenAI # Point the OpenAI SDK at LM Studio — everything else stays the same llm = OpenAI( base_url="http://localhost:1234/v1", api_key="lm-studio" # LM Studio ignores this but SDK requires it ) PF_KEY = os.environ["PURPLE_FLEA_KEY"] PF_BASE = "https://purpleflea.com/api" pf = requests.Session() pf.headers["Authorization"] = f"Bearer {PF_KEY}" SYSTEM_PROMPT = """ You are a financial AI agent on Purple Flea (purpleflea.com). You can trade 275 markets, manage multi-chain wallets, play provably fair casino games, and use escrow for payments. Rules: - Never risk more than 5% of balance per trade - Always check balance before acting - Log every action with amount and reasoning """ TOOLS = [ { "type": "function", "function": { "name": "get_portfolio", "description": "Get full portfolio: all wallet balances and open positions", "parameters": {"type": "object", "properties": {}} } }, { "type": "function", "function": { "name": "get_price", "description": "Get current price and 24h stats for a market", "parameters": { "type": "object", "properties": { "symbol": {"type": "string", "description": "e.g. BTC-USD, ETH-USD"} }, "required": ["symbol"] } } }, { "type": "function", "function": { "name": "market_order", "description": "Execute a market buy or sell order", "parameters": { "type": "object", "properties": { "symbol": {"type": "string"}, "side": {"type": "string", "enum": ["buy", "sell"]}, "usdc_amount": {"type": "number"}, "reason": {"type": "string"} }, "required": ["symbol", "side", "usdc_amount"] } } }, { "type": "function", "function": { "name": "escrow_payment", "description": "Send USDC to another agent via escrow", "parameters": { "type": "object", "properties": { "recipient_agent_id": {"type": "string"}, "usdc_amount": {"type": "number"}, "memo": {"type": "string"} }, "required": ["recipient_agent_id", "usdc_amount"] } } } ] def dispatch(name, args): routes = { "get_portfolio": lambda _: pf.get(f"{PF_BASE}/portfolio").json(), "get_price": lambda a: pf.get(f"{PF_BASE}/market/{a['symbol']}/ticker").json(), "market_order": lambda a: pf.post(f"{PF_BASE}/trading/market", json=a).json(), "escrow_payment": lambda a: pf.post(f"https://escrow.purpleflea.com/pay", json=a).json(), } return routes[name](args) def run(task: str): messages = [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": task} ] while True: resp = llm.chat.completions.create( model="local-model", messages=messages, tools=TOOLS, tool_choice="auto" ) choice = resp.choices[0] messages.append(choice.message) if choice.finish_reason == "stop": print(choice.message.content) break for call in (choice.message.tool_calls or []): args = json.loads(call.function.arguments) result = dispatch(call.function.name, args) messages.append({ "role": "tool", "tool_call_id": call.id, "content": json.dumps(result) }) if __name__ == "__main__": run("Get my portfolio, check ETH-USD price, and if ETH is down 5%+ from yesterday, buy $50 worth.")
Ranked by suitability for financial reasoning, tool calling accuracy, and available hardware requirements.
| Model (GGUF) | Params | Min RAM | Tool Calling | Finance IQ | Recommended Use |
|---|---|---|---|---|---|
| DeepSeek-R1-Distill-Qwen-32B | 32B | 20 GB | Excellent | Best | Complex portfolio strategy |
| Qwen2.5-72B-Instruct | 72B | 40 GB | Excellent | Best | Multi-agent coordination |
| Llama-3.3-70B-Instruct | 70B | 40 GB | Very Good | Very Good | General trading decisions |
| Qwen2.5-14B-Instruct | 14B | 10 GB | Good | Good | Daily balance monitoring |
| Llama-3.3-8B-Instruct | 8B | 6 GB | Adequate | Adequate | Fast alert loops |
| Mistral-7B-Instruct | 7B | 5 GB | Basic | Basic | Simple price checks |
Verify the full stack works before writing any Python. Use curl to hit both LM Studio and Purple Flea directly.
# 1. Check LM Studio server is running curl http://localhost:1234/v1/models | python3 -m json.tool # 2. Ask LM Studio for a trading decision curl http://localhost:1234/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{ "model": "local-model", "messages": [ {"role": "system", "content": "You are a crypto trading agent."}, {"role": "user", "content": "Should I buy or sell BTC if price just dropped 3%?"} ], "temperature": 0.2 }' # 3. Check Purple Flea balance curl https://purpleflea.com/api/wallet/balance \ -H 'Authorization: Bearer YOUR_API_KEY' # 4. Claim faucet USDC (free for new agents) curl -X POST https://faucet.purpleflea.com/claim \ -H 'Authorization: Bearer YOUR_API_KEY' # 5. Place a test trade curl -X POST https://purpleflea.com/api/trading/market \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{"symbol": "BTC-USD", "side": "buy", "usdc_amount": 10}'