# Catalog review and price archive

**Last updated:** 2026-11-23T10:59:54-03:00 (UTC-3)

With `catalog_review`, nothing the gateway reads from a public catalog or a provider's model list takes effect by itself. You import a catalog as a **draft**, review the diff (new, changed and removed models and prices) and approve it, whole or entry by entry. Only approved prices value usage and feed cost routing, and only approved models are served through a [wildcard alias](/docs/features/access-control/). Approved prices go to an **append-only archive** with an effective date: a new price never edits the old one, and the old one is archived automatically with its effective window.

## How to turn it on

```yaml
features:
  external_model_catalog: true
  automatic_price_catalog: true
  price_source_modelsdev: true   # or price_source_cost_map, for those sources
  catalog_review: true           # off by default; requires PostgreSQL
```

`catalog_review` requires `automatic_price_catalog` and a database (migration 183). It is an operator flag and can be switched in the console under **Settings & sources**.

What changes when it is on:

- [Automatic pricing](/docs/features/automatic-pricing/) no longer applies the catalogs' vote. A target with an approved price shows `source: catalog_review`, `confidence: approved` and its `effective_from`; without one it is `unknown` with `reason: price_not_approved`. Unknown is never zero.
- The [manual price book](/docs/features/pricing/) wins over an approved rate, as over any automatic price, and prices a target without one; a provider whose own documentation says it is free keeps that price (it is compiled data, not an import) unless a manual entry names the model.
- Drafts carry text rates (USD per million input and output tokens). Media unit prices from catalogs are not imported, so a media alias is priced by the manual price book while the flag is on.
- A model reached through a wildcard alias such as `groq/*` is served, and listed by `GET /v1/models`, only when that exact model is approved for its connection. Declared aliases need no approval: you wrote them.

With the flag off, the archive and drafts stay in the database and nothing reads them.

## Review a draft in the console

**Settings & sources → Catalog review**:

1. Choose a source: models.dev, the community cost map, OpenRouter, DeepInfra, or **Model list of** a connection.
2. **Import as draft**. The draft shows every change against the latest approved row: the previous and new USD per million input/output tokens, `removed` (the price becomes unpriced, or the model stops being routable) and `new`.
3. Select entries and **Approve selected** or **Reject selected**, or decide all at once. Leave **Effective from** empty to apply now, or choose a later date to schedule the price.
4. **Price archive** lists every approved row, newest first, with its window and state: `current`, `scheduled` or `archived`.

A viewer (`prices:read`) can read drafts and the archive; only a global admin (`prices:manage`) imports and decides. Catalog approval is gateway-wide: an organization admin cannot import or approve.

## API

| Endpoint | What it does |
| --- | --- |
| `POST /api/v1/admin/catalog/drafts` | `{"source": "modelsdev"}`, `cost_map`, `openrouter`, `deepinfra` or `provider:<connection id>`. Reads the source now and stores the diff. `201` with the draft; a draft with nothing to change is closed at once |
| `GET /api/v1/admin/catalog/drafts` | Drafts, newest first (`limit` 1 to 100, `before` a draft ID) |
| `GET /api/v1/admin/catalog/drafts/{id}` | One draft with every entry and its decision |
| `POST /api/v1/admin/catalog/drafts/{id}/decisions` | `{"approve": [1, 3], "reject": [2], "effective_from": "2026-12-01T00:00:00Z"}`, or `{"approve_all": true}` / `{"reject_all": true}` |
| `GET /api/v1/admin/catalog/archive` | The archive, newest first, with `effective_to` and `state` (`provider_id`, `model_id`, `before`, `limit` 1 to 200) |

Writes need a same-origin session and CSRF. A decision is atomic: if one entry fails, nothing applies.

| Answer | Meaning |
| --- | --- |
| `409 draft_closed` | The draft is closed, or a newer import of the same source superseded it |
| `409 entry_decided` | The entry was already approved, rejected or superseded |
| `409 entry_stale` | The archive row the diff was compared against has changed since; import again |
| `422 invalid_effective_from` | The date is in the past (more than one minute), or before a scheduled row of the same target |
| `422 source_not_used` | No connection reads that catalog; turn on its price source first |
| `422 draft_too_large` | More than 5,000 changes in one import |

A draft entry looks like this:

```json
{
  "entry": 1, "kind": "price", "change": "changed",
  "provider_id": "openai", "model_id": "gpt-4.1-mini",
  "previous_input_per_million": "0.4", "previous_output_per_million": "1.6",
  "input_per_million": "0.6", "output_per_million": "2.4",
  "decision": "pending"
}
```

## What a draft contains

- **A catalog source** compares its text rates for every exact target that reads it (the connection's [price sources](/docs/features/automatic-pricing/#where-the-price-comes-from)), plus the models approved behind a wildcard on that connection. `new` is a target without an approved price, `changed` a different rate (compared exactly as decimals), `removed` a target whose approved price came from this source and that the source no longer prices.
- **A connection's model list** (`provider:<id>`) compares the active models the provider lists with the models approved for that connection. Identifiers must be valid wildcard suffixes; no pattern is ever approved, only exact models.

Importing a source again while one of its drafts is open supersedes the older draft: its pending entries can no longer be approved, so an old diff never lands over a newer one.

## The archive

- Rows are append-only. A database trigger refuses `UPDATE` and `DELETE` on `gateway_catalog_archive`; there is no API to edit or delete a row.
- A row is in effect from its `effective_from` until the next row of the same connection and model, which archives it with that window. Retiring a price appends a `price_retired` row: the target is unpriced from then on, never free.
- No backdating: an approval takes effect now or later, so a past event keeps the rate it was valued at. Every usage event already freezes the rate it used.
- Approvals move the configuration version, so every replica reloads the archive. A row the database clock had reached when a replica read the archive is in effect there at once, even if that replica's clock is behind. A scheduled row takes effect on each replica by that replica's clock, without another reload; keep replica and database clocks synchronized (NTP), since a clock that is off by a few seconds applies a scheduled row that much early or late.
- Every import, supersession, approval and rejection is recorded in the control audit (`catalog_draft.create`, `catalog_draft.supersede`, `catalog_draft.approve`, `catalog_draft.reject`) with the actor and the request ID.

## Limits and upgrade notes

- One import reads the source once, through the same 15-minute catalog cache as automatic pricing; a failed read imports nothing.
- An older binary ignores the archive and applies the catalogs' vote again: turn the flag off before rolling back.
- The archive is not tamper-proof storage: a database owner can still change it.

## Admin API routes

Every route below needs a console session or an admin Bearer token, the role's permission and, for writes, the `X-CSRF-Token` header; the full contract is in the [API reference](/docs/api/).

| Route | What it does |
| --- | --- |
| `POST /api/v1/admin/catalog/drafts/{id}/decisions` | Approves or rejects the pending entries of a draft, all or by number, in one audited change |

## See also

- [Automatic pricing](/docs/features/automatic-pricing/) · [Manual price book](/docs/features/pricing/) · [Price book management](/docs/features/price-book-management/) · [Usage valuation](/docs/features/usage-valuation/)
