Description
Hi,
In ecologits/ecologits/tracers/google_genai_tracer.py, the input token count and output token count are defined as:
input_tokens = response.usage_metadata.candidates_token_count
output_tokens = response.usage_metadata.total_token_count - input_tokens
However, response.usage_metadata.candidates_token_count represents the number of generated tokens in the response. This value is assigned to input_tokens instead of output_tokens. Therefore, the input token count and output token count are swapped.
I could be wrong, but I was very surprised when I saw that the Gemini emissions were much higher than the estimated values from the online Ecologits Calculator. I changed the lines of code above locally to this:
output_tokens = response.usage_metadata.candidates_token_count
input_tokens = response.usage_metadata.total_token_count - output_tokens
and I got more plausible results.
Example Code
Description
Hi,
In
ecologits/ecologits/tracers/google_genai_tracer.py, the input token count and output token count are defined as:However,
response.usage_metadata.candidates_token_countrepresents the number of generated tokens in the response. This value is assigned toinput_tokensinstead ofoutput_tokens. Therefore, the input token count and output token count are swapped.I could be wrong, but I was very surprised when I saw that the Gemini emissions were much higher than the estimated values from the online Ecologits Calculator. I changed the lines of code above locally to this:
and I got more plausible results.
Example Code