| set_prices | R Documentation |
Registers the price of one or more models, in US dollars per million tokens. Agents use these prices to compute their cost ('$cost', '$get_usage_stats()') and to enforce their budget.
ellmer only knows the prices of the models in its built-in table, and returns a cost of 'NA' for any other model (for instance a model released after your ellmer version). Use 'set_prices()' to fill in these models, or to override a price that is out of date: prices set here take precedence over ellmer's.
Prices are kept for the R session and apply to every agent, including agents created before the price was set.
set_prices(model, input, output, cached_input = NA, provider = NULL)
get_prices()
clear_prices(model = NULL, provider = NULL)
model |
'[character]' Model name(s), as given to ellmer (eg. '"gpt-5.6"'). For 'clear_prices()': the model(s) whose prices to remove, or 'NULL' (default) to remove all prices. |
input |
'[numeric]' Price in USD per million input tokens. |
output |
'[numeric]' Price in USD per million output tokens. |
cached_input |
'[numeric]' Price in USD per million cached input tokens. When 'NA' (default), cached tokens are charged at the 'input' price. |
provider |
'[character | NULL]' Provider name(s) as reported by ellmer (eg. '"OpenAI"', matched case-insensitively). 'NULL' (default) matches the model whatever the provider. A price set for a specific provider takes precedence over one set for any provider. For 'clear_prices()': only remove the prices set for these providers. All arguments are recycled to the length of 'model'. Setting the price of a model that already has one replaces it. |
'set_prices()' and 'clear_prices()' invisibly return, and 'get_prices()' returns, the table of registered prices: a data frame with columns 'provider', 'model', 'input', 'output' and 'cached_input'.
set_prices("gpt-5.6", input = 1.25, output = 10)
set_prices(
c("my-model-small", "my-model-large"),
input = c(0.1, 1), output = c(0.4, 4), provider = "OpenAI"
)
get_prices()
clear_prices("my-model-small")
clear_prices()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.