# Run the crew
result = my_crew.kickoff()

print(result)
```

Each run will now be logged to the Opik platform, including all agent activities and LLM calls.

## Logging CrewAI Flows

Opik also supports the CrewAI Flows API. When you enable tracking with `track_crewai`, Opik automatically:

* Tracks `Flow.kickoff()` and `Flow.kickoff_async()` as the root span/trace with inputs and outputs
* Tracks flow step methods decorated with `@start` and `@listen` as nested spans
* Captures any LLM calls (via LiteLLM) within those steps with token usage
* Flow methods are compatible with other Opik integrations (e.g., OpenAI, Anthropic, LangChain) and the `@opik.track` decorator. Any spans created inside flow steps are correctly attached to the flow's span tree.

Example:

```python
import litellm
from crewai.flow.flow import Flow, start, listen
from opik.integrations.crewai import track_crewai

track_crewai(project_name="crewai-integration-demo")

class ExampleFlow(Flow):
    model = "gpt-4o-mini"

    @start()
    def generate_city(self):
        response = litellm.completion(
            model=self.model,
            messages=[{"role": "user", "content": "Return the name of a random city."}],
        )
        return response["choices"][0]["message"]["content"]

    @listen(generate_city)
    def generate_fun_fact(self, random_city):
        response = litellm.completion(
            model=self.model,
            messages=[{"role": "user", "content": f"Tell me a fun fact about {random_city}"}],
        )
        return response["choices"][0]["message"]["content"]

flow = ExampleFlow()
result = flow.kickoff()
```

## Cost Tracking

The `track_crewai` integration automatically tracks token usage and cost for all supported LLM models used during CrewAI agent execution.

Cost information is automatically captured and displayed in the Opik UI, including:

* Token usage details
* Cost per request based on model pricing
* Total trace cost

<Tip>
  View the complete list of supported models and providers on the [Supported Models](/tracing/supported_models) page.
</Tip>

## Grouping traces into conversational threads using `thread_id`

Threads in Opik are collections of traces that are grouped together using a unique `thread_id`.

The `thread_id` can be passed to the CrewAI crew as a parameter, which will be used to group all traces into a single thread.

```python
from crewai import Agent, Crew, Task, Process
from opik.integrations.crewai import track_crewai