# Managing Model Pricing

Set per-million-token costs for the models you serve through the Barndoor LLM Gateway so spending budgets, cost reports, and usage telemetry are accurate.

## Overview

**Model Pricing** is where you control how much each model costs per million input and output tokens. Those prices drive every cost-aware feature on the platform:

* **spending budgets** in [LLM Controls](/how-tos/use-llm-controls#token-budgets)
* per-request **`estimated_cost`** values on every audit event (input cost, output cost, total)
* **per-team / per-user / per-model cost attribution** in the Reporting area

Model Pricing lives in the Barndoor portal under **LLM Management → Model Pricing**.

Barndoor ships a curated default catalog of market-rate prices for every common model — OpenAI, Anthropic, AWS Bedrock, Google Vertex, Azure OpenAI, and many more. **You get accurate cost data on those models out of the box, with no setup.** Importing defaults or writing your own rules is only required when you want to override Barndoor's prices or price a model Barndoor doesn't ship in its catalog.

## Before You Begin

* A Barndoor account with **admin** privileges.
* An LLM Gateway with at least one provider and one model already configured — see [Using the LLM Gateway](/how-tos/use-llm-gateway).

## Quickstart: Import Default Prices

Barndoor ships a curated catalog of market-rate prices for the most popular providers and applies it automatically — so you only need this step if you want to take ownership of specific prices. Importing copies the defaults you choose into your org as editable rules you can then adjust, pin, or keep in sync.

### Steps

1. **Open LLM Management → Model Pricing → Barndoor defaults**: The Barndoor defaults tab lists every model Barndoor knows about, with an Imported / Not imported badge per row.  
2. **Select rows**: Tick rows individually, or filter by Catalog and tick the header checkbox to select all visible rows.  
3. **Pick a Sync behavior and click Import**: Choose how Barndoor should handle future changes — *Prompt me on updates*, *I'll manage it*, or *Auto-sync to Barndoor* — and click **Import**.

## How Pricing Resolves

When a request flows through the gateway, Barndoor finds the right price by checking your rules in this order. The first match wins.

```mermaid
theme={null}
flowchart TB
    Request["Request to compute<br/>cost for"]
    Specific["1. Provider-specific rule<br/>(this exact provider connection)"]
    Catalog["2. Catalog rule<br/>(this vendor line — e.g. OpenAI, Bedrock)"]
    Org["3. Organization-wide rule<br/>(any provider, any catalog)"]
    Defaults["4. Platform default catalog<br/>(Barndoor's curated prices)"]
    Found["Found → use price to record cost"]
    Zero["No match → record cost as $0"]

Request --> Specific --> Catalog --> Org --> Defaults --> Found
    Defaults -.->|none match| Zero
```

| Tier                     | Use when                                                                                                                                        |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| **1. Provider-specific** | You've negotiated a custom rate with one specific provider connection (for example one of your Azure deployments).                              |
| **2. Catalog**           | The price applies to a whole vendor line — every OpenAI provider, every Bedrock provider, etc. — but you don't want it to apply across vendors. |
| **3. Organization-wide** | The price applies wherever the model name matches, regardless of which provider serves it. The simplest and most common scope.                  |
| **4. Platform defaults** | Barndoor's curated catalog of market-rate prices. Kicks in as a safety net even if you've never imported anything.                              |

Stick to **organization-wide rules** for everyday pricing. Use **catalog** or **provider-specific** overrides only when you genuinely have a different price for the same model on different vendors or connections (negotiated discount, fine-tuned model variant, etc.). Fewer rules mean fewer surprises.

## Creating a Pricing Rule Manually

### Steps

1. **Click Add Pricing Rule**: The Create dialog opens.
2. **Model pattern**: Either pick an enabled model from the dropdown or type a custom pattern. Patterns can be:
    * **Exact** — `gpt-4o-mini` matches only that exact model.
    * **Prefix wildcard** — `gpt-4o*` matches `gpt-4o`, `gpt-4o-mini`, etc.
3. **Catalog (optional)**: Restrict this rule to one vendor line (OpenAI, Bedrock, etc.).
4. **Provider (optional)**: Restrict this rule to a single configured provider connection.
5. **Input + output cost per million tokens**: Two dollar amounts, both required. Use the same per-million-token prices the provider publishes on their pricing page.
6. **When this takes effect**: Choose **Take effect immediately** for normal price changes, or **Schedule for later** to pick a date and time for the new price.
7. **Save**: Immediate rules take effect on the next request through the gateway.

Avoid overlapping rules at the same scope. If both `gpt-4o` (exact) and `gpt-4o*` (wildcard) exist at the catalog level, you'll get inconsistent results.

## Editing and Scheduling Price Changes

Click the pencil icon on any row to edit. Every save creates a **new version** of the rule with an `effective_from` timestamp — Barndoor never overwrites an existing price in place. That gives you three things at once:

* **Past and active versions are an audit trail.** They can't be deleted or modified.
* **Scheduled future versions can be canceled or edited** from the listing.
* **Changes are forward-looking.** They apply only to requests served after the new version becomes active.

### Editing an active price

1. Click the pencil icon on the row.
2. Adjust the input or output cost.
3. Choose **Take effect immediately** or **Schedule for later**.
4. Optionally fill in **Change reason**.
5. Save.

### Reset to Default

If you've drifted from Barndoor's curated default for a model, the row shows a **Custom** badge and a **Reset to default** action appears next to it. Clicking it creates a new version of the rule whose input and output costs match the current default.

## Pricing History

Each row in the listing has a **clock icon** that opens its **Pricing History** dialog — a timeline of every version of that rule, newest first. Each entry shows:

* The input and output costs at that version.
* The `effective_from` timestamp.
* Who made the change.
* How the change was made.
* The optional **Change reason** you entered.

## Keeping Prices in Sync with Barndoor's Catalog

Barndoor refreshes its default catalog as upstream provider prices change. Each pricing row's **Sync behavior** decides what happens when one of those refreshes affects a model you've imported.

| Sync behavior                           | What it does                                                                   |
| --------------------------------------- | ------------------------------------------------------------------------------ |
| **Tracking** — *Prompt me on updates*   | Imports the default at the moment of import.
| **Pinned** — *I'll manage it*           | A fixed price you maintain manually.                                            |
| **Auto-sync** — *Auto-sync to Barndoor* | Barndoor's defaults flow through automatically.                               |

### Reviewing updates

When at least one of your **tracking** rows is out of sync, a blue **Review updates** banner appears. Clicking it opens a dialog listing every affected row with the old vs new default price.

## Badges in the Pricing Listing

Each row carries one or more badges that summarize its state at a glance.

| Badge                              | Meaning                                                                                |
| ---------------------------------- | -------------------------------------------------------------------------------------- |
| **Default**                        | A Barndoor default exists for this pattern.                                          |
| **Custom**                         | A Barndoor default exists, but you've changed the costs or pinned the row.          |
| **Manual**                         | No Barndoor default exists for this pattern.                                          |
| **Update available**               | A *Prompt me on updates* row whose Barndoor default has changed since you imported it. |
| **Auto-sync**                      | The row's sync behavior is *Auto-sync to Barndoor*.                                 |
| **Scheduled** (or **N scheduled**) | The row has at least one future-dated version waiting to activate.                   |

## Require Pricing for Model Routes

The toggle at the top of the Model Pricing tab — **Require pricing for Model Routes** — is a safety net for organizations that want every routed model to have an **explicit org-level pricing rule**.

When **on**:

* The **Models** tab in **LLM Management** shows an **Unpriced** badge next to any enabled model that has no org-level rule.
* You can't add a new route, or re-enable a disabled one, that points at such a model.

When **off** (default): routes can include models that have only a Barndoor default.

## How Pricing Plugs into the Rest of the Platform

| Feature                                                                        | How it uses pricing                                                                                                                                                     |
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Token budgets** ([LLM Controls](/how-tos/use-llm-controls#token-budgets))    | **Doesn't use pricing.** Caps total tokens; independent of pricing.                                                                                                   |
| **Spending budgets** ([LLM Controls](/how-tos/use-llm-controls#token-budgets)) | **Uses pricing.** Each successful request debits `(prompt_tokens × input_rate) + (completion_tokens × output_rate)` using whichever rule wins.                        |
| **Per-request audit events**                                                   | **Uses pricing.** `estimated_cost`, `input_cost`, and `output_cost` fields are populated on the audit event for every successful LLM request.                          |
| **Reporting → LLM Usage Dashboard**                                            | **Uses pricing.** Aggregates the per-request `estimated_cost` recorded on audit events.                                                                                 |

Cost is **computed after a successful upstream response**, using the actual prompt + completion token counts reported by the provider.

## Troubleshooting

### Spending budget is always $0 used

No pricing rule is matching the requests — including Barndoor's default catalog.

#### `estimated_cost` is missing or zero on a recent audit event
Same root cause as the spending-budget accordion above — no pricing rule matched the request.

#### I changed a price but old reports / spend numbers haven't moved
Price changes are **forward-looking** — they affect any request that happens after the new version becomes active; they don't retroactively re-cost historical audit events.

## Frequently Asked Questions

### Does importing defaults stay in sync with provider price changes?
That's your choice — set the **Sync behavior** on each imported row:

* **Prompt me on updates** *(default)* — Barndoor flags catalog changes and you apply or pin per row.
* **I'll manage it** — Barndoor never changes your prices.
* **Auto-sync to Barndoor** — Barndoor's defaults flow through automatically.

### What currency is supported?
Currently **USD** only. All input and output costs are entered and recorded in US dollars.

### Can I set different prices for different request types?
Not directly — pricing is keyed on model name + scope, not request type.

### What if my provider lists prices per 1,000 tokens?
Multiply by 1,000. Barndoor stores costs as USD per million tokens; if your provider quotes prices per 1K input tokens, enter the corresponding amount as the input cost per million.

### Do I need a pricing rule for embedding models too?
Only if the embedding model isn't already in Barndoor's curated default catalog.
