How to Integrate CrewAI for insurance with FastAPI for production AI

By Cyprian AaronsUpdated 2026-04-22
crewai-for-insurancefastapiproduction-ai

Combining CrewAI for insurance with FastAPI gives you a clean production path for turning multi-agent insurance workflows into HTTP services. That means you can expose claim triage, underwriting support, policy Q&A, or fraud review behind an API your internal systems and client apps can call.

The useful part is not “AI chat.” It’s orchestrated work: one agent gathers context, another validates against policy rules, and FastAPI wraps the whole thing in a predictable service boundary.

Prerequisites

  • Python 3.10+
  • fastapi
  • uvicorn
  • crewai
  • Access to an LLM provider configured for CrewAI
  • A basic understanding of:
    • FastAPI routes
    • Pydantic models
    • async vs sync request handling
  • Optional but recommended:
    • Docker
    • Redis or a queue if you plan to offload long-running insurance tasks

Install the packages:

pip install fastapi uvicorn crewai pydantic

Integration Steps

  1. Define your insurance agents and task flow

CrewAI works best when you separate responsibilities. For insurance, a common pattern is:

  • intake agent: extracts claim details
  • policy agent: checks coverage rules
  • summary agent: prepares a structured decision note
from crewai import Agent, Task, Crew, Process

intake_agent = Agent(
    role="Insurance Intake Specialist",
    goal="Extract claim facts from customer input",
    backstory="You normalize claim reports into structured fields.",
    verbose=True,
)

policy_agent = Agent(
    role="Policy Analyst",
    goal="Check whether the reported event appears covered",
    backstory="You compare claim details against policy constraints.",
    verbose=True,
)

summary_agent = Agent(
    role="Claims Summary Writer",
    goal="Produce a concise decision summary for downstream systems",
    backstory="You write clear operational summaries for adjusters.",
    verbose=True,
)
  1. Build the CrewAI task chain

Use tasks to define what each agent should output. In production, keep outputs structured so FastAPI can return them without extra parsing.

claim_input = """
Policy type: Auto
Event: Rear-end collision at low speed
Damage: Rear bumper and trunk lid
Injuries: None
Location: Parking lot
"""

intake_task = Task(
    description=f"Extract key claim fields from this report:\n{claim_input}",
    expected_output="JSON with claimant facts, incident type, damage summary, and missing fields",
    agent=intake_agent,
)

policy_task = Task(
    description="Assess whether this looks like a covered first-party auto claim based on extracted facts.",
    expected_output="Coverage assessment with rationale and any exclusions or follow-up questions",
    agent=policy_agent,
)

summary_task = Task(
    description="Summarize the claim assessment for an adjuster in plain English.",
    expected_output="Short operational summary with next action",
    agent=summary_agent,
)

crew = Crew(
    agents=[intake_agent, policy_agent, summary_agent],
    tasks=[intake_task, policy_task, summary_task],
    process=Process.sequential,
)
  1. Wrap the CrewAI workflow in a FastAPI endpoint

This is the production boundary. The API receives request data, sends it into the crew workflow, then returns the result.

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Insurance AI Orchestrator")

class ClaimRequest(BaseModel):
    policy_type: str
    event_description: str
    damage_description: str
    injuries: str | None = None
    location: str | None = None

@app.post("/claims/analyze")
def analyze_claim(payload: ClaimRequest):
    prompt = f"""
Policy type: {payload.policy_type}
Event: {payload.event_description}
Damage: {payload.damage_description}
Injuries: {payload.injuries or "None"}
Location: {payload.location or "Unknown"}
"""

    # Rebuild tasks with real request data in production.
    intake_task.description = f"Extract key claim fields from this report:\n{prompt}"
    
    result = crew.kickoff()
    return {"result": str(result)}
  1. Make the endpoint production-safe

For real systems, add validation and timeouts around long-running work. If your claims workflow can take longer than a few seconds, move execution to a background worker instead of blocking the request thread.

from fastapi import BackgroundTasks

def run_claim_workflow(claim_text: str):
    intake_task.description = f"Extract key claim fields from this report:\n{claim_text}"
    return crew.kickoff()

@app.post("/claims/analyze-background")
def analyze_claim_background(payload: ClaimRequest, background_tasks: BackgroundTasks):
    prompt = f"""
Policy type: {payload.policy_type}
Event: {payload.event_description}
Damage: {payload.damage_description}
Injuries: {payload.injuries or "None"}
Location: {payload.location or "Unknown"}
"""
    background_tasks.add_task(run_claim_workflow, prompt)
    return {"status": "queued"}
  1. Run FastAPI and connect it to your internal consumers

Use Uvicorn locally first. In production, put this behind a gateway and add auth before exposing it to anything outside your network.

uvicorn main:app --reload --host 0.0.0.0 --port 8000

If you need structured responses for downstream systems like claims platforms or CRMs, convert CrewAI output into a schema before returning it.

Testing the Integration

Send a request to your API and verify that the crew runs end-to-end.

import requests

payload = {
    "policy_type": "Auto",
    "event_description": "Rear-end collision in parking lot",
    "damage_description": "Rear bumper dented and trunk misaligned",
    "injuries": "None",
    "location": "Mall parking lot"
}

response = requests.post("http://localhost:8000/claims/analyze", json=payload)
print(response.status_code)
print(response.json())

Expected output:

200
{
  "result": "...coverage assessment and claim summary..."
}

If you used the background endpoint:

200
{"status": "queued"}

Real-World Use Cases

  • Claims triage API
    • Classify incoming FNOL submissions and route low-risk claims automatically.
  • Underwriting assistant
    • Analyze applicant data against underwriting guidelines before human review.
  • Policy servicing bot
    • Answer coverage questions using controlled agent workflows exposed through FastAPI endpoints.

The pattern here is simple. CrewAI handles orchestration across specialized insurance agents, and FastAPI gives you the service layer needed for authentication, routing, observability, and deployment.


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