W&B Weave automatically calculates the cost of each LLM call by tracking token usage and applying the pricing for the model used, allowing you to monitor and analyze application spend directly in your traces and evaluations. You can also track custom costs when you need different pricing, internal cost models, or costs for operations that Weave does not price automatically.Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-update-training-api-26.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Adding a custom cost
- Python
- TypeScript
You can add a custom cost by using the
add_cost method.
The three required fields are llm_id, prompt_token_cost, and completion_token_cost.
llm_id is the name of the LLM (e.g. gpt-4o). prompt_token_cost and completion_token_cost are cost per token for the LLM (if the LLM prices were specified inper million tokens, make sure to convert the value).
You can also set effective_date to a datetime, to make the cost effective at a specific date, this defaults to the current date.Querying for costs
- Python
- TypeScript
You can query for costs by using the
query_costs method.
There are a few ways to query for costs, you can pass in a singular cost id, or a list of LLM model names.Purging a custom cost
- Python
- TypeScript
You can purge a custom cost by using the
purge_costs method. You pass in a list of cost ids, and the costs with those ids are purged.Calculating costs for a Project
- Python
- TypeScript
You can calculate costs for a project by using our
calls_query and adding include_costs=True with a little bit of setup.