Crew AI Token Usage

Hi team.

I have created a sample project with using this command

crewai create crew <project_name>

This is how the run function looks like in main.py

def run():
    """
    Run the crew.
    """
    inputs = {
        'topic': 'AI LLMs',
        'current_year': str(datetime.now().year)
    }
    
    try:
        Manju().crew().kickoff(inputs=inputs)
    except Exception as e:
        raise Exception(f"An error occurred while running the crew: {e}")

How do I determine the total tokens utilised during execution?

Thanks in advance!

1 Like
def run():
    """
    Run the crew.
    """
    inputs = {
        'topic': 'AI LLMs',
        'current_year': str(datetime.now().year)
    }
    
    try:
        result = Manju().crew().kickoff(inputs=inputs)
    except Exception as e:
        raise Exception(f"An error occurred while running the crew: {e}")
    
    print(f"\nCrew Output:\n{result.raw}\n")
    print(f"\nToken Usage:\n{result.token_usage}\n")