How to Integrate Anthropic for wealth management with Cloudflare Workers for startups
Combining Anthropic for wealth management with Cloudflare Workers gives you a practical pattern for building low-latency AI agents that can sit close to users and still call a strong reasoning model for portfolio analysis, client Q&A, and compliance-aware summaries. The Worker handles the edge-facing orchestration, while Anthropic handles the language and reasoning layer for tasks like explaining risk exposure, summarizing account activity, or drafting advisor responses.
Prerequisites
- •Python 3.10+
- •An Anthropic API key
- •A Cloudflare account with:
- •Workers enabled
- •Wrangler installed and authenticated
- •A deployed Worker route or local dev setup
- •
pipaccess to install SDKs:- •
anthropic - •
requests - •
cloudflare
- •
- •Basic familiarity with:
- •HTTP APIs
- •JSON payloads
- •environment variables
Integration Steps
- •Install the Python dependencies.
import os
import json
import requests
from anthropic import Anthropic
# Install separately:
# pip install anthropic requests cloudflare
Start by keeping the integration thin. In this pattern, Python acts as your orchestration layer for local development, backend jobs, or internal tooling that talks to both Anthropic and Cloudflare Workers.
- •Call Anthropic from Python for the wealth-management reasoning step.
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
prompt = """
You are a wealth management assistant.
Summarize this portfolio in plain English for a client:
- 45% US equities
- 25% investment-grade bonds
- 15% international equities
- 10% cash
- 5% alternatives
Focus on risk profile, diversification, and one concise recommendation.
"""
response = client.messages.create(
model="claude-3-5-sonnet-latest",
max_tokens=300,
messages=[
{"role": "user", "content": prompt}
]
)
summary_text = response.content[0].text
print(summary_text)
This is the core model call. For startups, keep prompts deterministic and domain-specific so you can safely wrap them in policy checks before exposing them to advisors or clients.
- •Expose a Cloudflare Worker endpoint that your Python service can call.
import os
import requests
worker_url = os.environ["CLOUDFLARE_WORKER_URL"]
payload = {
"client_id": "acct_10291",
"request_type": "portfolio_summary",
"model_output": summary_text,
}
resp = requests.post(
worker_url,
headers={
"Content-Type": "application/json",
"X-Service-Key": os.environ["WORKER_SERVICE_KEY"],
},
json=payload,
timeout=20,
)
print(resp.status_code)
print(resp.text)
The Worker becomes your edge gateway. Typical responsibilities here are auth enforcement, rate limiting, request normalization, logging, and routing to downstream services.
- •Use the Cloudflare Workers API from Python to manage deployment metadata or secrets workflows.
import os
from cloudflare import Cloudflare
cf = Cloudflare(api_token=os.environ["CLOUDFLARE_API_TOKEN"])
# Example: inspect workers scripts or manage related resources through the API.
# Exact endpoints depend on your account setup and deployment flow.
account_id = os.environ["CLOUDFLARE_ACCOUNT_ID"]
scripts = cf.workers.scripts.list(account_id=account_id)
print(scripts)
For production systems, don’t hardcode Worker URLs everywhere. Keep deployment metadata in one place so your agent system can discover the right edge endpoint per environment: dev, staging, or prod.
- •Wrap the full flow into one reusable integration function.
import os
import requests
from anthropic import Anthropic
anthropic_client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
worker_url = os.environ["CLOUDFLARE_WORKER_URL"]
def generate_and_send_portfolio_summary(client_id: str, holdings: list[dict]) -> dict:
holdings_text = "\n".join(
f"- {h['asset_class']}: {h['weight']}%"
for h in holdings
)
prompt = f"""
You are a wealth management assistant.
Write a short client-facing summary of this portfolio:
{holdings_text}
Return:
1) risk profile
2) diversification note
3) one recommendation
Keep it under 120 words.
"""
ai_response = anthropic_client.messages.create(
model="claude-3-5-sonnet-latest",
max_tokens=250,
messages=[{"role": "user", "content": prompt}],
)
summary = ai_response.content[0].text
worker_response = requests.post(
worker_url,
headers={"Content-Type": "application/json"},
json={
"client_id": client_id,
"summary": summary,
"source": "anthropic",
},
timeout=20,
)
return {
"summary": summary,
"worker_status": worker_response.status_code,
"worker_body": worker_response.json() if worker_response.headers.get("content-type", "").startswith("application/json") else worker_response.text,
}
That function is what you want in an agent system: one entry point, one predictable output shape, and no hidden state. You can call it from an internal dashboard, a scheduled job, or an advisor copilot backend.
Testing the Integration
Use a minimal test payload first. You want to validate three things: Anthropic returns usable text, the Worker accepts it, and your auth headers are correct.
result = generate_and_send_portfolio_summary(
client_id="acct_10291",
holdings=[
{"asset_class": "US equities", "weight": 45},
{"asset_class": "investment-grade bonds", "weight": 25},
{"asset_class": "international equities", "weight": 15},
{"asset_class": "cash", "weight": 10},
{"asset_class": "alternatives", "weight": 5},
],
)
print(result)
Expected output:
{
"summary": "This portfolio has moderate risk with meaningful equity exposure balanced by bonds and cash...",
"worker_status": 200,
"worker_body": {
"ok": true,
"client_id": "acct_10291"
}
}
If you get a non-200 response from the Worker, check these first:
- •
CLOUDFLARE_WORKER_URLis correct - •
X-Service-Keymatches what the Worker expects - •Your Worker is parsing JSON correctly
- •Anthropic output is being passed as plain text, not raw objects
Real-World Use Cases
- •
Advisor copilot
- •Summarize portfolios before advisor calls.
- •Generate client-ready explanations of allocation changes.
- •Push those summaries through a Worker for logging and policy checks.
- •
Client self-service assistant
- •Answer basic wealth-management questions at the edge.
- •Use Workers for fast auth and request routing.
- •Use Anthropic for natural-language responses grounded in account data.
- •
Compliance review pipeline
- •Have Anthropic draft communication summaries.
- •Send them through Workers to attach metadata, redact sensitive fields, or forward to review queues.
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