How to Integrate Anthropic for fintech with Cloudflare Workers for multi-agent systems
Anthropic for fintech gives you strong model reasoning for regulated workflows, while Cloudflare Workers gives you the low-latency edge runtime to orchestrate agent traffic close to users and APIs. Put them together and you can build multi-agent systems that route payment disputes, KYC checks, fraud triage, and policy lookups without dragging everything through a central app server.
Prerequisites
- •Python 3.10+
- •An Anthropic API key
- •A Cloudflare account with Workers enabled
- •
wranglerinstalled and authenticated - •A Cloudflare Worker route or service binding ready for agent orchestration
- •Access to your fintech data sources:
- •transaction ledger API
- •customer profile service
- •fraud/risk scoring endpoint
- •Python packages:
- •
anthropic - •
requests - •
python-dotenv
- •
Integration Steps
- •
Set up your environment variables
Keep secrets out of code. Store your Anthropic key and Cloudflare endpoint in
.env.from dotenv import load_dotenv import os load_dotenv() ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY") CLOUDFLARE_WORKER_URL = os.getenv("CLOUDFLARE_WORKER_URL") if not ANTHROPIC_API_KEY or not CLOUDFLARE_WORKER_URL: raise RuntimeError("Missing ANTHROPIC_API_KEY or CLOUDFLARE_WORKER_URL") - •
Build the Anthropic agent that decides what to do
Use Anthropic to classify incoming fintech requests into agent tasks like
fraud_check,kyc_lookup, ordispute_summary. The key method here isclient.messages.create().import anthropic import json client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY) def classify_request(text: str) -> dict: resp = client.messages.create( model="claude-3-5-sonnet-latest", max_tokens=300, temperature=0, messages=[ { "role": "user", "content": f""" Classify this fintech request into one of: - fraud_check - kyc_lookup - dispute_summary - payment_status Return JSON with keys: task, confidence, reason. Request: {text} """ } ], ) return json.loads(resp.content[0].text) - •
Send the task to Cloudflare Workers for edge orchestration
The Worker acts as the multi-agent router. Your Python app posts the task payload to a Worker endpoint, which can fan out to specialized services or return a routing decision.
import requests def dispatch_to_worker(task_payload: dict) -> dict: response = requests.post( CLOUDFLARE_WORKER_URL, json=task_payload, timeout=15, headers={ "Content-Type": "application/json", "X-Agent-System": "fintech-multi-agent" }, ) response.raise_for_status() return response.json() - •
Wire Anthropic classification to Worker orchestration
This is the core integration: classify with Anthropic, then pass the result to Workers. In production, your Worker can call downstream APIs via service bindings or fetch requests.
def handle_fintech_request(user_text: str) -> dict: classification = classify_request(user_text) payload = { "request_text": user_text, "task": classification["task"], "confidence": classification["confidence"], "reason": classification["reason"], } worker_result = dispatch_to_worker(payload) return { "classification": classification, "orchestration": worker_result, } - •
Add a simple Worker-side contract for multi-agent routing
Even if your Worker is written in JavaScript, define the payload shape from Python first so every agent agrees on the contract. For example, a fraud agent might get only transaction metadata, while a KYC agent gets identity fields.
from typing import TypedDict, Literal class AgentTask(TypedDict): task: Literal["fraud_check", "kyc_lookup", "dispute_summary", "payment_status"] request_text: str confidence: float reason: str def build_agent_task(text: str) -> AgentTask: c = classify_request(text) return { "task": c["task"], "request_text": text, "confidence": float(c["confidence"]), "reason": c["reason"], }
Testing the Integration
Run a local test that simulates a real support request and checks whether Anthropic classifies it and Cloudflare Workers receives it.
if __name__ == "__main__":
sample = "Customer says their card was charged twice for the same subscription."
result = handle_fintech_request(sample)
print(result)
Expected output:
{
"classification": {
"task": "dispute_summary",
"confidence": 0.94,
"reason": "The request describes an unauthorized duplicate charge."
},
"orchestration": {
"status": "ok",
"routed_to": "dispute-agent",
"next_action": "fetch_transaction_history"
}
}
If you get a 4xx from the Worker, check:
- •the Worker URL is correct
- •CORS/auth headers match your deployment
- •your JSON payload matches the contract expected by the Worker
If Anthropic returns malformed JSON, tighten the prompt and keep temperature=0.
Real-World Use Cases
- •
Fraud triage at the edge
- •Anthropic classifies suspicious customer messages.
- •Cloudflare Workers routes high-risk cases to a fraud scoring service before escalating to an analyst.
- •
KYC / onboarding assistant
- •One agent extracts missing identity fields.
- •Another checks document completeness.
- •Workers coordinates both without sending every request back to your origin server.
- •
Dispute resolution workflow
- •Anthropic summarizes chargeback narratives.
- •Workers fans out to ledger lookup, merchant lookup, and policy retrieval agents.
- •The final response is assembled at the edge with lower latency.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit