# How to Configure Custom Model Pricing for Cost Tracking in Agentsview

> Learn how to configure custom model pricing in Agentsview to accurately track costs. Override defaults in your config for precise cost calculations.

- Repository: [Kenn Software/agentsview](https://github.com/kenn-io/agentsview)
- Tags: how-to-guide
- Published: 2026-06-15

---

**Agentsview allows you to override default model pricing by adding a `custom_model_pricing` section to your configuration file, which is then merged into the `model_pricing` table and used for all cost calculations.**

Agentsview is an open-source observability tool for AI agents that tracks session costs by multiplying token counts by per-model rates. While the system includes fallback pricing and LiteLLM integration, you can **configure custom model pricing** to accurately track costs for proprietary, self-hosted, or fine-tuned models. This configuration completely overrides the default rates stored in the `model_pricing` table.

## Understanding the Pricing Hierarchy

Agentsview resolves model pricing through three distinct sources, applied in order of precedence:

1. **Hard-coded fallback pricing** – defined in [`internal/pricing/fallback.go`](https://github.com/kenn-io/agentsview/blob/main/internal/pricing/fallback.go) and used only when no other source exists.
2. **LiteLLM pricing** – downloaded at runtime by `pricing.FetchLiteLLMPricing` and stored in the `model_pricing` table.
3. **User-supplied custom pricing** – read from your configuration file and written into the same `model_pricing` table, overriding any previous entries.

Only the third source allows you to specify exact costs for any model identifier, including those not covered by the public LiteLLM database.

## Configuring Custom Model Pricing

### Configuration Structure

The configuration system defines the `CustomModelPricing` field in [`internal/config/config.go`](https://github.com/kenn-io/agentsview/blob/main/internal/config/config.go) as a map of model patterns to rate structures:

```go
type Config struct {
    // ... other fields ...
    CustomModelPricing map[string]CustomModelRate `json:"custom_model_pricing,omitempty" toml:"custom_model_pricing"`
}

```

The `CustomModelRate` struct (also in [`config.go`](https://github.com/kenn-io/agentsview/blob/main/config.go)) supports four distinct rate fields:

```go
type CustomModelRate struct {
    Input         float64 `json:"input" toml:"input"`
    Output        float64 `json:"output" toml:"output"`
    CacheCreation float64 `json:"cache_creation,omitempty" toml:"cache_creation"`
    CacheRead     float64 `json:"cache_read,omitempty" toml:"cache_read"`
}

```

All values represent **cost per million tokens**, consistent with the pricing conventions used throughout Agentsview.

### File Location and Format

The configuration file resides in your data directory, which defaults to `~/.agentsview` (controlled by the `$AGENTSVIEW_DATA_DIR` environment variable). When the configuration loads (`Config.loadFile` at lines 563-564 of [`internal/config/config.go`](https://github.com/kenn-io/agentsview/blob/main/internal/config/config.go)), it parses the `custom_model_pricing` block directly into the struct.

Create or edit [`config.toml`](https://github.com/kenn-io/agentsview/blob/main/config.toml) to add your custom rates:

```toml

# ~/.agentsview/config.toml

custom_model_pricing = {
  "gpt-4o-mini" = { input = 0.15, output = 0.60 },
  "claude-3-5-sonnet-20240620" = {
    input = 0.30,
    output = 1.50,
    cache_creation = 0.020,
    cache_read = 0.010
  },
  "anthropic/claude-*" = { input = 0.12, output = 0.40 }
}

```

The **model pattern** key supports glob-style wildcards (e.g., `anthropic/claude-*`) to apply rates to entire model families. Leading underscores are reserved for internal entries and ignored during matching.

## How Custom Rates Are Applied

After parsing the configuration, Agentsview commands invoke `database.SetCustomPricing` to persist your custom rates. This function, implemented in [`internal/db/pricing.go`](https://github.com/kenn-io/agentsview/blob/main/internal/db/pricing.go), writes each entry into the `model_pricing` table, overriding any existing rows for the same `model_pattern`.

The injection occurs in three primary command paths:

- **CLI usage command** ([`cmd/agentsview/usage.go`](https://github.com/kenn-io/agentsview/blob/main/cmd/agentsview/usage.go), lines 147-150)
- **PostgreSQL push** ([`cmd/agentsview/pg.go`](https://github.com/kenn-io/agentsview/blob/main/cmd/agentsview/pg.go), lines 234-235)
- **DuckDB sync** ([`cmd/agentsview/duckdb.go`](https://github.com/kenn-io/agentsview/blob/main/cmd/agentsview/duckdb.go), lines 211-212)

Once stored, the Postgres-specific implementation in [`internal/postgres/pricing.go`](https://github.com/kenn-io/agentsview/blob/main/internal/postgres/pricing.go) loads the combined pricing map via `store.loadPricingMap` and applies your custom overrides through `store.applyCustomPricing` during cost calculations.

## Verifying Your Configuration

To confirm that your custom pricing is active, query the `model_pricing` table directly:

```sql
SELECT model_pattern, input_per_mtok, output_per_mtok,
       cache_creation_per_mtok, cache_read_per_mtok
FROM model_pricing;

```

Rows matching your configured patterns should display the exact values you specified in [`config.toml`](https://github.com/kenn-io/agentsview/blob/main/config.toml). If you synchronized to PostgreSQL, you can also verify the rates in the replica database.

## Summary

- Agentsview supports **three pricing sources** with user-defined custom rates taking highest precedence.
- Define rates in `~/.agentsview/config.toml` using the `custom_model_pricing` map with **cost per million tokens**.
- Use **glob patterns** in model identifiers to apply rates to entire model families.
- Rates are persisted via `database.SetCustomPricing` and override the `model_pricing` table entries used by the usage, PostgreSQL push, and DuckDB sync commands.
- Restart Agentsview after modifying configuration to trigger the reload at `Config.loadFile` (lines 563-564).

## Frequently Asked Questions

### What is the priority of custom pricing versus LiteLLM pricing?

Custom pricing always takes precedence. When `database.SetCustomPricing` executes, it writes your configuration values into the `model_pricing` table, overwriting any existing rows for matching `model_pattern` entries—including those downloaded from LiteLLM via `pricing.FetchLiteLLMPricing`.

### Can I use wildcards for model patterns?

Yes. The model pattern key supports glob-style wildcards (e.g., `anthropic/claude-*` or `gpt-4*`). This allows you to apply uniform pricing to entire model families without listing each variant individually. Note that patterns beginning with an underscore are reserved for internal use and ignored.

### What units should I use for pricing rates?

All rate fields (`input`, `output`, `cache_creation`, `cache_read`) expect values in **USD per million tokens**. This aligns with standard API pricing conventions and ensures consistency with the fallback pricing defined in [`internal/pricing/fallback.go`](https://github.com/kenn-io/agentsview/blob/main/internal/pricing/fallback.go).

### Do I need to restart Agentsview after changing pricing?

Yes. The configuration file is read during startup via `Config.loadFile` in [`internal/config/config.go`](https://github.com/kenn-io/agentsview/blob/main/internal/config/config.go). After saving changes to [`config.toml`](https://github.com/kenn-io/agentsview/blob/main/config.toml), restart the Agentsview server or re-run your CLI command (usage, pg push, or duckdb sync) to trigger `database.SetCustomPricing` and update the `model_pricing` table.