Skip to content

Input token count and output token count are swapped for google_genai #222

@MalikS-343

Description

@MalikS-343

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions