def handle_generation(self, response: pydantic.BaseModel) -> None:
        """Get the usage information from litellm response's usage field."""

        response_dict = response.model_dump()

        usage = response_dict.get("usage")

        self.endpoint: LiteLLMEndpoint
        if self.endpoint.litellm_provider not in ["openai", "azure", "bedrock"]:
            # We are already tracking costs from the openai or bedrock endpoint so we
            # should not double count here.

            # Increment number of requests.
            super().handle_generation(response_dict)

            # Assume a response that had usage field was successful. Otherwise
            # litellm does not provide success counts unlike openai.
            self.cost.n_successful_requests += 1

            for cost_field, litellm_field in [
                ("n_tokens", "total_tokens"),
                ("n_prompt_tokens", "prompt_tokens"),
                ("n_completion_tokens", "completion_tokens"),
            ]:
                setattr(
                    self.cost,
                    cost_field,
                    getattr(self.cost, cost_field, 0)
                    + usage.get(litellm_field, 0),
                )

        if self.endpoint.litellm_provider not in ["openai"]:
            # The total cost does not seem to be properly tracked except by
            # openai so we can use litellm costs for this.
            try:
                cost_value = completion_cost(response)
            except Exception as e:
                logger.exception("Failed to compute cost: %s", e)
                cost_value = None
            setattr(self.cost, "cost", cost_value)
Get the usage information from litellm response's usage field.
src/providers/litellm/trulens/providers/litellm/endpoint.py