OpsViz
DocsPlatformsCrewAI

CrewAI Integration Guide

Instrument CrewAI agents and tasks to report execution data to OpsViz via the webhook API.

How it works in 30 seconds

  1. 1.Create an agent in OpsViz → get your webhook URL (10 seconds)
  2. 2.Add one step to your CrewAI workflow → paste the URL (2 minutes)
  3. 3.See costs, tokens, and alerts in real time (instantly)
Privacy note: OpsViz receives only operational metadata — event type, token counts, model name, cost, and duration. Your prompts, responses, user data, and AI provider credentials are never sent to OpsViz.

Set up with AI — copy and paste

The fastest way to add OpsViz monitoring is to paste this prompt into your AI coding assistant. It sets everything up automatically.

Using Claude Code or ChatGPT

Paste this prompt into Claude Code or ChatGPT with your CrewAI code attached:

I have a CrewAI setup and want to add OpsViz monitoring. Add a step_callback to my crew that fires after each agent task completes. The callback should POST to [WEBHOOK_URL] with the task name as agent_name, event_type as "task.completed", and any token/cost data available from the task output. Make it non-blocking. Show me the complete implementation.

Prerequisites

  • CrewAI installed in your Python environment
  • An OpsViz account with an agent created
  • Your OpsViz webhook URL
1

Install the requests library

pip install requests
2

Create an OpsViz reporter utility

import requests
import time

OPSVIZ_WEBHOOK = "[WEBHOOK_URL]"

def report_event(event_type, agent_name=None, model=None,
                 tokens_in=None, tokens_out=None,
                 cost_usd=None, duration_ms=None,
                 status="success", metadata=None):
    payload = {"event_type": event_type, "status": status}
    if agent_name: payload["agent_name"] = agent_name
    if model: payload["model"] = model
    if tokens_in: payload["tokens_in"] = tokens_in
    if tokens_out: payload["tokens_out"] = tokens_out
    if cost_usd: payload["cost_usd"] = cost_usd
    if duration_ms: payload["duration_ms"] = duration_ms
    if metadata: payload["metadata"] = metadata

    try:
        requests.post(OPSVIZ_WEBHOOK, json=payload, timeout=5)
    except Exception:
        pass  # Don't let monitoring block your agent
3

Wrap your task execution

from crewai import Task, Agent

def execute_with_tracking(task: Task, agent: Agent):
    start = time.time()
    try:
        result = agent.execute_task(task)
        duration = int((time.time() - start) * 1000)
        report_event("task.completed",
                     agent_name=agent.role,
                     duration_ms=duration,
                     status="success",
                     metadata={"task": task.description[:100]})
        return result
    except Exception as e:
        report_event("task.failed",
                     agent_name=agent.role,
                     status="error",
                     metadata={"error": str(e)})
        raise

That's it!

Events will appear on your OpsViz dashboard as they arrive. Check the webhook reference for full payload options.