Skip to main content
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.

Adding a custom cost

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

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

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

You can calculate costs for a project by using our calls_query and adding include_costs=True with a little bit of setup.

Setting up a custom model with custom costs

Try our cookbook for Setting up costs with a custom model.

Try in Colab