> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure custom model costs for estimation

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = undefined

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

If you don't log `metrics.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

Navigate to Configuration > AI providers > Custom providers and add your model with pricing information.

### Step 2: Set pricing information

Configure the following costs for your custom model:

* 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 include `metadata.model` matching the exact registered model name.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
braintrust.log(
    metadata={"model": "your-custom-model-name"},
    # other span data
)

```

### Step 4: Query costs across projects

Use SQL to aggregate costs across multiple projects:

```sql theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
SELECT
    metadata.model,
    day(created) AS date,
    avg(estimated_cost()) AS avg_cost,
    sum(estimated_cost()) AS total_cost
FROM project_logs('project-id-1', 'project-id-2')
WHERE created > now() - interval 7 day
  AND span_attributes.type = 'llm'
GROUP BY metadata.model, date
```

Save this query as a custom view for reuse across your organization.

For more granular breakdowns — for example, separating cached prompt cost from uncached prompt cost — use `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](/reference/sql#sql-functions) for the available component names.
