class RubyLLM::Cost

A Cost prices token usage in US dollars using pricing from the model registry. Message#cost returns the cost of a single response, and Model#cost_for prices any token usage against a specific model.

response = chat.ask "Summarize Ruby's object model."
response.cost.total

cost = model.cost_for(response.tokens)
cost.input
cost.output

The components are RubyLLM’s normalized token buckets: input, output, cache_read, cache_write, and thinking. When the registry lacks pricing for tokens that were used, the affected component and total return nil instead of a false zero.