Estimate the USD cost of a set of calls
Value
A single numeric USD figure, or NA_real_ when the model has no
pricing in the registry. Pricing is seeded from the registry's as_of
snapshot. Treat it as an estimate, and use gr_register_model() to
correct it.
See also
gr_model_info(), gr_register_model(), gr_trace_summary()
Other cost and token functions:
gr_budget(),
gr_count_tokens(),
gr_model_info(),
gr_model_limits(),
gr_models(),
gr_register_model(),
gr_set_tokenizer(),
gr_tokenizer(),
gr_truncate_tokens()
Examples
gr_estimate_cost("gpt-4o", input_tokens = 120000, output_tokens = 4000)
#> [1] 0.34
gr_estimate_cost("a-model-with-no-pricing", 1000, 100)
#> Warning: Model 'a-model-with-no-pricing' is not in the registry. Falling back to a conservative 128000-token context with a 4096-token output reserve. Register the real limits with gr_register_model('a-model-with-no-pricing', context_window = ..., max_output = ...) so budgets and cost estimates are correct.
#> [1] NA