cost calculation
OpenAIWrapper
from autogen
tracks token counts and costs of your
API calls. Use the create()
method to initiate requests and
print_usage_summary()
to retrieve a detailed usage report, including
total cost and token usage for both cached and actual requests.
mode=["actual", "total"]
(default): print usage summary for
non-caching completions and all completions (including cache).mode='actual'
: only print non-cached usage.mode='total'
: only print all usage (including cache).clear_usage_summary()
when
needed.
Agent.print_usage_summary()
to print the cost summary for the agent.
You can retrieve usage summary in a dict using
Agent.get_actual_usage()
and Agent.get_total_usage()
. Note that
Agent.reset()
will also reset the usage summary.
To gather usage data for a list of agents, we provide an utility
function autogen.gather_usage_summary(agents)
where you pass in a list
of agents and gather the usage summary.
price
field in config_list
if the token price is not listed or
up-to-date. Please creating an issue or pull request to help us keep the
token prices up-to-date!
Note: in json files, the price should be a list of two floats.
Example Usage:
Python>=3.9
:
config_list_from_json
function loads a list of configurations from an environment variable or
a json file.
print_usage_summary()
to
checkout your usage summary. To clear up, use clear_usage_summary()
.
Agent.print_usage_summary()
will print the cost summary for the
agent.Agent.get_actual_usage()
and Agent.get_total_usage()
will return
the usage summary in a dict. When an agent doesn’t use LLM, they
will return None.Agent.reset()
will reset the usage summary.autogen.gather_usage_summary
will gather the usage summary for a
list of agents.