Applies to:
- Plan - Any
- Deployment - Any
Summary
If you don’t logmetrics.estimated_cost directly on a span, Braintrust falls back to the model registry to estimate cost from token metrics and registered pricing. Custom LLM models need to be registered in Braintrust’s model registry with pricing information for this fallback to produce a cost. Spans that log metrics.estimated_cost explicitly use that value as-is in the trace viewer and in the estimated_cost() SQL function.
Configuration Steps
Step 1: Register your custom model
Register custom model pricing on an organization-level provider. The pricing lookup used byestimated_cost() does not include project-level providers.
Go to Settings > Models. Click Organization provider, then choose Custom providers > New. On Setup, configure the provider, then under Models, click Custom model and enter the model identifier recorded in your traces. See Custom providers.
Step 2: Set pricing information
Click the settings icon beside the custom model to open Model options, then configure:- Input cost per million tokens
- Output cost per million tokens
- Cache read/write costs (if using prompt caching)
Step 3: Update span metadata
Ensure your logged spans includemetadata.model matching the exact registered model name.
Step 4: Query costs across projects
Use SQL to aggregate costs across multiple projects:estimated_cost_component(name) to extract a single cost component, or estimated_cost_breakdown() to return all components as a JSON object. See SQL functions for the available component names.
Log a discounted cost
If your provider applies a discount or batch pricing that Braintrust’s model prices do not reflect, calculate the discounted cost (using the provider’s applicable rates, including cached-token pricing where relevant) and log it in USD asmetrics.estimated_cost on the corresponding LLM span. Supply the final cost, not the discount percentage. This overrides automatic estimation without requiring a custom model.
For example, a request costing $0.003548 at standard rates costs $0.001774 with a 50% discount. Log 0.001774 as metrics.estimated_cost. Use the provider’s applicable rates, including cached-token pricing where relevant.
For existing spans, see Update spans. You need the LLM span’s id and must ensure the original span is flushed before updating it.