How to Integrate CrewAI for insurance with FastAPI for startups

By Cyprian AaronsUpdated 2026-04-22
crewai-for-insurancefastapistartups

Combining CrewAI for insurance with FastAPI gives you a clean way to expose multi-agent workflows as production APIs. For startups, that means you can turn claims triage, policy Q&A, or underwriting support into a simple HTTP service your frontend, CRM, or internal tools can call.

Prerequisites

  • Python 3.10+
  • A virtual environment set up
  • fastapi, uvicorn, and crewai installed
  • An OpenAI-compatible LLM key configured in your environment
  • Basic familiarity with FastAPI routing and Pydantic models
  • A CrewAI insurance workflow already defined, or at least a clear agent/task structure

Install the dependencies:

pip install fastapi uvicorn crewai pydantic

Set your API key:

export OPENAI_API_KEY="your-key-here"

Integration Steps

  1. Define your insurance agents and tasks

Start by creating the agent roles you want CrewAI to manage. For insurance, keep them narrow: one agent for intake, one for policy analysis, one for claims review.

from crewai import Agent, Task, Crew, Process

claims_intake_agent = Agent(
    role="Claims Intake Specialist",
    goal="Extract structured claim details from customer input",
    backstory="You work in an insurance operations team and normalize claim reports.",
    verbose=True,
)

policy_review_agent = Agent(
    role="Policy Review Analyst",
    goal="Check whether the claim appears covered under the policy summary",
    backstory="You understand policy language and identify exclusions.",
    verbose=True,
)

intake_task = Task(
    description="Read the customer claim summary and extract incident date, loss type, and severity.",
    expected_output="A structured JSON-like summary of the claim.",
    agent=claims_intake_agent,
)

review_task = Task(
    description="Review the extracted claim against the policy summary and flag coverage risks.",
    expected_output="A short coverage assessment with risk flags.",
    agent=policy_review_agent,
)
  1. Wrap the CrewAI workflow in a reusable service function

This keeps your FastAPI layer thin. Your API should not know about prompts or task orchestration; it should just call a service function.

from typing import Dict

def run_claim_workflow(customer_input: str, policy_summary: str) -> Dict[str, str]:
    crew = Crew(
        agents=[claims_intake_agent, policy_review_agent],
        tasks=[intake_task, review_task],
        process=Process.sequential,
        verbose=True,
    )

    result = crew.kickoff(inputs={
        "customer_input": customer_input,
        "policy_summary": policy_summary,
    })

    return {"result": str(result)}

A practical note: use Process.sequential when the second task depends on the first. For claims workflows, that dependency is common.

  1. Expose the workflow through FastAPI

Now create an endpoint that accepts request data and returns the crew output. Use Pydantic models so your contract is explicit.

from fastapi import FastAPI
from pydantic import BaseModel

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

class ClaimRequest(BaseModel):
    customer_input: str
    policy_summary: str

class ClaimResponse(BaseModel):
    result: str

@app.post("/claims/analyze", response_model=ClaimResponse)
def analyze_claim(payload: ClaimRequest):
    output = run_claim_workflow(
        customer_input=payload.customer_input,
        policy_summary=payload.policy_summary,
    )
    return ClaimResponse(**output)

If you need async handling later, keep the same contract and move execution into a background worker. Don’t block your API thread if crews take long to run.

  1. Run FastAPI locally and verify the route

Use Uvicorn to start the app.

# save this as main.py
# then run:
# uvicorn main:app --reload

Once it’s running, hit /docs to confirm FastAPI generated OpenAPI docs correctly. That’s useful for startup teams because product and ops can test workflows without writing client code.

  1. Add structured outputs for downstream systems

For real insurance systems, returning raw text is not enough. Convert CrewAI output into fields your downstream services can consume.

import json

def parse_crew_output(raw_output: str) -> dict:
    try:
        return json.loads(raw_output)
    except json.JSONDecodeError:
        return {
            "summary": raw_output,
            "status": "needs_manual_review"
        }

Then plug that parser into your endpoint before returning data to clients. This is how you make the integration usable for claims queues, ticketing systems, or underwriting dashboards.

Testing the Integration

Use FastAPI’s TestClient to verify the endpoint responds correctly.

from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_claim_analysis():
    response = client.post(
        "/claims/analyze",
        json={
            "customer_input": "Customer reported water damage in kitchen on 2026-04-01.",
            "policy_summary": "Homeowners policy covers sudden accidental water damage excluding wear and tear."
        },
    )

    assert response.status_code == 200
    print(response.json())

test_claim_analysis()

Expected output:

{
  "result": "..."
}

If you wired everything correctly, you should see a non-empty result string from CrewAI. In production tests, assert on specific fields like coverage_risk, incident_date, or manual_review_required once you enforce structured output.

Real-World Use Cases

  • Claims triage API: accept FNOL payloads from a web app and have CrewAI extract facts, assess severity, and route cases to adjusters.
  • Policy Q&A assistant: expose a FastAPI endpoint that answers coverage questions using insurance-specific agents instead of a generic chatbot.
  • Underwriting support service: let one agent summarize applicant details while another flags missing documents or risk indicators before human review.

The pattern is simple: CrewAI handles orchestration and reasoning across specialized agents, while FastAPI gives you a stable interface for your product stack. For startups building insurance automation, that split keeps your AI logic testable and your API easy to ship.


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