How to Integrate Anthropic for healthcare with Cloudflare Workers for multi-agent systems

By Cyprian AaronsUpdated 2026-04-21
anthropic-for-healthcarecloudflare-workersmulti-agent-systems

Combining Anthropic for healthcare with Cloudflare Workers gives you a practical way to run regulated, low-latency agent workflows at the edge. The pattern is simple: keep orchestration and routing close to users with Workers, and push clinical reasoning, summarization, and triage into Anthropic-backed agents that can be governed centrally.

This setup is useful when you need multiple agents to coordinate on patient intake, prior authorization, claims review, or care navigation without dragging every request through a central app server.

Prerequisites

  • Python 3.10+
  • pip installed
  • An Anthropic API key with access to the healthcare-capable model you plan to use
  • A Cloudflare account
  • A Cloudflare Worker created in your dashboard
  • wrangler installed and authenticated:
    • npm install -g wrangler
    • wrangler login
  • Environment variables ready:
    • ANTHROPIC_API_KEY
    • CLOUDFLARE_ACCOUNT_ID
    • CLOUDFLARE_API_TOKEN
    • WORKER_NAME

Integration Steps

  1. Install the Python SDKs and set up your environment

    Use the official Anthropic Python SDK for model calls and requests for invoking Cloudflare’s Workers API from your control plane or agent orchestrator.

    import os
    import requests
    from anthropic import Anthropic
    
    ANTHROPIC_API_KEY = os.environ["ANTHROPIC_API_KEY"]
    CLOUDFLARE_ACCOUNT_ID = os.environ["CLOUDFLARE_ACCOUNT_ID"]
    CLOUDFLARE_API_TOKEN = os.environ["CLOUDFLARE_API_TOKEN"]
    WORKER_NAME = os.environ["WORKER_NAME"]
    
    client = Anthropic(api_key=ANTHROPIC_API_KEY)
    
  2. Create a Worker that acts as the multi-agent router

    In practice, the Worker is your edge entry point. It can route requests to specialist agents like intake, coding, benefits verification, or escalation.

    import requests
    
    def deploy_worker_script(script: str):
        url = f"https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/workers/scripts/{WORKER_NAME}"
        headers = {
            "Authorization": f"Bearer {CLOUDFLARE_API_TOKEN}",
            "Content-Type": "application/javascript",
        }
        resp = requests.put(url, headers=headers, data=script.encode("utf-8"), timeout=30)
        resp.raise_for_status()
        return resp.json()
    
    worker_js = """
    export default {
      async fetch(request, env) {
        const body = await request.json();
        return Response.json({
          route: body.route,
          patient_id: body.patient_id,
          status: "routed"
        });
      }
    };
    """
    
    result = deploy_worker_script(worker_js)
    print(result["success"])
    
  3. Call Anthropic from Python for healthcare-specific reasoning

    Use Anthropic’s Messages API to summarize clinical notes or classify the next action for a given agent. Keep prompts narrow and structured so downstream agents can consume deterministic output.

    from anthropic import Anthropic
    
    client = Anthropic(api_key=ANTHROPIC_API_KEY)
    
    response = client.messages.create(
        model="claude-3-5-sonnet-latest",
        max_tokens=300,
        temperature=0,
        system="You are a healthcare triage agent. Return concise JSON only.",
        messages=[
            {
                "role": "user",
                "content": """
                Review this intake note and decide the next agent:
                Note: Patient reports chest tightness after exertion, history of hypertension.
                Return JSON with keys: route, urgency, rationale.
                """
            }
        ],
    )
    
    print(response.content[0].text)
    
  4. Orchestrate multiple agents through Cloudflare Workers

    The Worker can receive the classification result from Anthropic and forward it to specialist services. In production, each route might call a different internal API or queue.

     import json
     import requests
    
     def invoke_worker(route_payload: dict):
         url = f"https://{WORKER_NAME}.workers.dev"
         resp = requests.post(url, json=route_payload, timeout=30)
         resp.raise_for_status()
         return resp.json()
    
     triage_result = client.messages.create(
         model="claude-3-5-sonnet-latest",
         max_tokens=200,
         temperature=0,
         system="Return JSON only.",
         messages=[{"role": "user", "content": "Route this case for multi-agent handling: diabetic patient requesting medication refill."}],
     )
    
     payload_text = triage_result.content[0].text
     payload = json.loads(payload_text)
    
     worker_response = invoke_worker({
         "patient_id": "pt_12345",
         "route": payload["route"],
         "triage": payload,
     })
    
     print(worker_response)
    
  5. Add guardrails for PHI handling and structured outputs

    Keep PHI out of logs where possible. Have Anthropic return only the minimum fields needed for routing, then let Workers handle request fan-out with short-lived context.

    import json
    
    def safe_clinical_summary(note: str):
        response = client.messages.create(
            model="claude-3-5-sonnet-latest",
            max_tokens=250,
            temperature=0,
            system="You are a healthcare workflow agent. Do not include identifiers.",
            messages=[{
                "role": "user",
                "content": f"""
                Summarize this note into JSON:
                {note}
                Keys: summary, risk_level, next_agent.
                """
            }],
        )
        return json.loads(response.content[0].text)
    
    summary = safe_clinical_summary(
        "Patient reports worsening shortness of breath over 48 hours; no known drug allergies."
    )
    print(summary)
    

Testing the Integration

Run a simple end-to-end check:

import json
import requests
from anthropic import Anthropic

client = Anthropic(api_key=ANTHROPIC_API_KEY)

triage = client.messages.create(
    model="claude-3-5-sonnet-latest",
    max_tokens=150,
    temperature=0,
    system="Return JSON only.",
    messages=[{
        "role": "user",
        "content": "Classify this case: post-op patient asking about wound redness."
    }],
)

payload = json.loads(triage.content[0].text)

resp = requests.post(
    f"https://{WORKER_NAME}.workers.dev",
    json={"patient_id": "demo_001", **payload},
    timeout=30,
)

print(resp.status_code)
print(resp.json())

Expected output:

200
{
  "route": "clinical_review",
  "patient_id": "demo_001",
  "status": "routed"
}

Real-World Use Cases

  • Patient intake routing

    • Anthropic classifies symptoms and intent.
    • Cloudflare Workers sends the request to scheduling, nurse triage, or escalation agents.
  • Prior authorization assistant

    • One agent extracts clinical facts from notes.
    • Another agent checks payer rules.
    • Workers coordinates retries and downstream API calls at the edge.
  • Claims exception handling

    • Anthropic summarizes claim narratives.
    • Workers fans out tasks to fraud review, coding validation, and customer support agents based on severity.

Keep learning

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

Related Guides