Skip to content

[Bug]: usage cost no longer included in response? #81

@jaimeiniesta

Description

@jaimeiniesta

Bug Description

In 1.0.0-rc.4 I could do this to get the usage cost for a Google Gemini request:

defp parse_response(response) do
  text = ReqLLM.Response.text(response)
  usage = ReqLLM.Response.usage(response)

  {:ok,
     %{
       text: text,
       total_tokens: usage.total_tokens,
       total_cost: usage.total_cost,
       model: response.model
     }}
end

but in 1.0.0-rc.5 I get this error:

** (KeyError) key :total_cost not found in: %{
       output_tokens: 1,
       input_tokens: 17,
       reasoning_tokens: 0,
       cached_tokens: 0,
       total_tokens: 18
     }. Did you mean:

           * :total_tokens

I don't see any reference in the changelog for this, has this been removed?

Steps to Reproduce

  1. Get the usage from ReqLLM.Response.usage(response)
  2. Try to get total_cost from it.

Expected Behavior

Return the total cost.

Actual Behavior

It doesn't include any costs.

Environment

  • Package version: 1.0.0-rc.5
  • Elixir 1.18.4
  • Erlang/OTP 28

Additional Context

Previously (RC4) this worked without needing to run mix req_llm.model_sync. But this fails in RC5 even if I run that mix task.

I'm not sure then why is that mix task doing...

Metadata

Metadata

Assignees

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