| llm_cost | R Documentation |
The cost in US dollars of the conversation held by an ellmer chat object, as used by agents. When a price was registered for the chat's model with [set_prices()], the cost is computed from the token usage of each assistant turn with that price. Otherwise it is ellmer's own estimate (the cost ellmer records on each assistant turn), which is 'NA' for models ellmer has no price for. Turns without a recorded cost, such as turns rebuilt from an agent's edited history, count as zero, so the cost is 'NA' only when no turn has a known cost.
An agent's own cost ('$cost', '$get_usage_stats()') also keeps what was spent on turns that were later removed from its history.
llm_cost(llm_object, include = c("all", "last"))
llm_object |
An ellmer chat object (eg. an agent's '$llm_object'). |
include |
'"all"' (default) for the whole conversation, or '"last"' for the last assistant turn only. |
A number: the cost in USD, or 'NA' if it is unknown.
## Not run:
chat <- ellmer::chat("openai/gpt-5.6", echo = "none")
chat$chat("Hello")
llm_cost(chat) # NA: ellmer has no price for this model
set_prices("gpt-5.6", input = 1.25, output = 10)
llm_cost(chat)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.