# Crewai result.token\_usage not matching with LLMs token Usage count

**URL:** <https://community.crewai.com/t/crewai-result-token-usage-not-matching-with-llms-token-usage-count/3467>\
**Category:** CrewAI Community Support\
**Created:** [February 3, 2025, 12:01am UTC](https://community.crewai.com/t/crewai-result-token-usage-not-matching-with-llms-token-usage-count/3467 "2025-02-03T00:01:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkay](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/vkay/32/1399_2.png) [@vkay](https://community.crewai.com/u/vkay)\
**Post date:** [February 3, 2025, 12:01am UTC](https://community.crewai.com/t/crewai-result-token-usage-not-matching-with-llms-token-usage-count/3467/1 "2025-02-03T00:01:57Z")

</div>

Hello,

My crew consists of two agents. I have written function to calculate cost per execution of crew. For every execution, I capture prompt\_tokens and completion\_tokens and pass it to function to calculate cost of that execution. I want to pass that cost to end user who initiated crew. Problem is Token count via crewai’s usage\_token api doesn’t match with the one on LLM Side. I am using “claude-3-5-sonnet-20241022” model and when I check on Anthropic’s api console I see more tokens for same request. So I am not able to pass exact cost to user. Can you please suggest what is the best way to get exact cost per crew execution ?

```
        mycrew = mycrewclass().crew()
        result = mycrew.kickoff(inputs=inputs)
        costs = calculate_cost(mycrew.usage_metrics.prompt_tokens,mycrew.usage_metrics.completion_tokens)

```

Code of calculate\_cost looks like below

def calculate\_cost(input\_tokens, output\_tokens) → float:  
“”“Calculate total cost based on current Claude 3.5 Sonnet pricing”“”  
input\_price\_per\_1k = os.environ.get(‘INPUT\_PRICE\_PER\_1K’) or ‘you-will-never-guess’  
output\_price\_per\_1k = os.environ.get(‘OUTPUT\_PRICE\_PER\_1K’) or ‘you-will-never-guess’  
input\_cost = (input\_tokens/1000) \* float(input\_price\_per\_1k)  
output\_cost = (output\_tokens/1000) \* float(output\_price\_per\_1k)  
return input\_cost + output\_cost
