# Financial reconciliation

**Last updated:** 2026-11-27T13:41:51-03:00 (UTC-3)

[Budgets](/docs/features/budgets-and-tpm/) reserve up front and settle afterwards, with what the provider reports. Sometimes the settlement does not happen: a timeout, a crash, a truncated response. The reservation stays held, for safety. Financial reconciliation resolves this with proofs, and compares what the gateway estimated with what the provider actually charged. Flag: `quota_finance`, which requires `quota_management`, `durable_usage` and PostgreSQL.

In the console: **Budget & TPM → Finance & reconciliation**.

## Three different facts

| Fact | Where it comes from | What it proves |
| --- | --- | --- |
| **Reservation** | Admission, with the approved rate | The maximum the call could cost |
| **Measurement** | The provider's response, validated by the [profile](/docs/features/quota-protocols/) | The tokens or units consumed |
| **Imported charge** | A billing export you send | What the provider says it charged |

The gateway never confuses one with another. An analytics log, the client's `X-Request-Id`, a timeout or the end of a window do not replace a measurement. Importing a charge does not change balances on its own.

## Importing charges

`POST /api/v1/admin/quota-finance/imports` receives a **statement** with:

- the import ID, source, an HTTPS link to the original (no credentials or query) and the file's SHA-256;
- the external account, a UTC interval of up to 366 days, USD currency and coverage (`partial` or `complete_export`);
- from 1 to 1,000 lines (up to 512 KiB), each with an external ID, the exact connection and model, a category (`charge`, `credit`, `tax` or `adjustment`) and a decimal amount with up to 12 decimal places;
- optionally, the internal inference ID and the provider's native request ID.

Rules:
- **Immutable.** The same import with the same content is idempotent. Different content with the same ID, the same file with another ID, or lines repeated across overlapping exports produce a conflict. A correction is a new adjustment or credit line.
- **No double counting.** Aggregate reports from the same source and account cannot have overlapping periods.
- **Linking.** A line becomes `matched` only when the internal ID, the native ID the gateway saw in the provider's response, the connection, the model and the interval all match. Without a link, it is `aggregate`; with an unproven link, `unmatched`. Gemini does not provide a native ID, and the gateway does not invent one.
- `complete_export` means you sent the whole declared export, not that the invoice is complete. The gateway validates structure and amounts; it does not authenticate the provider's signature.

To convert the official OpenAI and Anthropic exports into this format, use the [native billing imports](/docs/features/native-billing-imports/).

## Report

`GET /api/v1/admin/quota-finance/report` sums all selected lines, with charges, credits, taxes, adjustments, net and estimates shown separately. `import_id` limits it to one import.

- Each linked inference counts once in the estimate, even with several external lines.
- `linked_estimate_lines` and `linked_unestimated_lines` tell how many linked charges do or do not have an estimate.
- `invoice_coverage: not_verified` is deliberate: the report covers what was imported, not the external invoice or a tax audit.
- A zero subtotal with missing coverage does not prove zero cost.

## Releasing a reservation with a measurement

When the settlement failed but the measurement was recorded:

1. `GET /api/v1/admin/quota-finance/evidence?reservation_id=...` shows the evidence.
2. `POST /api/v1/admin/quota-finance/reconcile`, with the operation ID, reservation ID, `measurement_fingerprint` and version.

The gateway checks the checksum, connection, model, unit and rate of the reservation, and adjusts the counters **in the original windows**. Repeating the same operation is idempotent; divergent or generic evidence is rejected without touching the balance. Without a valid measurement, the reservation stays held.

## Releasing USD with a charge

`POST /api/v1/admin/quota-finance/reconcile-charge`, with the operation ID, import and line, the file's SHA-256, version and the confirmation `ATTEST_PROVIDER_CHARGE_USD_ONLY`.

- Only a **positive**, unique charge, `matched` by native ID, replaces the reserved USD amount, and only on a reservation that is still unknown and has an approved rate.
- Aggregate, ambiguous and zero lines, credits and taxes release nothing. The absence of a line does not prove there was no charge.
- **TPM stays reserved:** a dollar charge does not prove tokens. A later token settlement preserves the USD already reconciled. `budget_basis` and `reconciled_charge_usd` in the evidence show where the balance came from.

## Releasing an unknown reservation by hand

Some unknown reservations can never be reconciled: the provider gives no native request ID to match a charge line against (Gemini on Vertex), or you have no billing export for that account. Their hold lasts until each window rolls over, and forever on a lifetime budget. A manual release is the one explicit way out.

**What it is, and what it is not.** An administrator gives back the holds of an unknown reservation and writes down why. The gateway never does this by itself: no timer, window end, import or restart releases an unknown reservation. The release proves nothing about the provider. **The provider may still have charged for the call**; every answer and every record says so. Use it when you have decided, outside the gateway, how that cost is accounted for.

**Turn it on.** Flag `quota_manual_release`, off by default; it requires `quota_finance`. It is an operator flag, changed in the YAML or under **Settings & sources**:

```yaml
features:
  quota_finance: true
  quota_manual_release: true
```

**Who can.** The permission `quota_reservations:release`. The global admin holds it for every organization. With [organization admins](/docs/features/organization-admins/) on, an organization admin holds it for reservations of its own organization's teams. Nobody else does, and a custom role cannot receive it.

**In the console.** **Budget & TPM → Finance & reconciliation → Unknown reservations** for the global admin; **My organization → Unknown reservations** for an organization admin. Filter the list (the global admin also by organization), tick the reservations, write the reason in one line, confirm that the provider may still have charged, and release. A refused release says why and changes nothing. **Manual releases**, below it, shows the trail. The screen appears only with both flags on and the permission in your session.

**Steps (API):**

1. `GET /api/v1/admin/quota-finance/unknown-reservations` lists the held unknown reservations, oldest first. Filter with `team_id`, `key_id`, `provider_id`, `model`, `organization_id`, `created_after` and `created_before`. Each item shows what it holds (`windows`: every subject, dimension, window and amount) and whether it is `releasable`. The answer carries the finance `version` to send back. Page it with `limit` (1 to 100, default 50) and `offset`.
2. `POST /api/v1/admin/quota-finance/release-unknown` releases them:

```json
{
  "id": "release-vertex-2026-11",
  "version": 12,
  "reason": "Vertex stream cut before the fix; no native ID to reconcile",
  "confirmation": "RELEASE_UNKNOWN_PROVIDER_MAY_HAVE_CHARGED",
  "reservation_ids": ["0f3a...32 hex...", "9b1c...32 hex..."]
}
```

| Field | Rule |
| --- | --- |
| `id` | Operation ID, 2 to 64 characters (`a-z`, digits, `_`, `-`, starting with a letter). The same ID with the same content is idempotent; with other content it is a conflict |
| `version` | The finance version from the list; a stale one answers `409` |
| `reason` | Required, one line of 10 to 500 characters. It is kept in the finance trail |
| `confirmation` | Exactly `RELEASE_UNKNOWN_PROVIDER_MAY_HAVE_CHARGED` |
| `reservation_ids` | 1 to 100 reservation IDs; **or** |
| `filter` + `expected_count` | The same filter members as the list, at least one, with the number of reservations you reviewed (1 to 100). If the filter selects another number the release is refused with `release_count_mismatch` |

All the named reservations are released in one transaction, or none is.

**What a release does.** For each reservation it subtracts the reserved amounts from the counters of the **original windows**, moves the reservation to `released`, and writes two records:

- a **finance-trail row** (`GET /api/v1/admin/quota-finance/manual-releases`): who, when, the reason, the reserved USD and tokens, and each window given back, with `open: true` when that window was still the current one (an ended window changes no current balance; a lifetime window is always open). Rows are written once and never changed. The trail is read newest first, paged with `limit` (1 to 100, default 50) and `offset`, and narrowed to one organization with `organization_id`.
- an **audit row** with the action `quota.reservation.release_unknown`, the actor, the request ID and the reservation's organization.

Afterwards the [evidence](#releasing-a-reservation-with-a-measurement) of that reservation shows `budget_basis: manual_release_unproven`, and cost reports treat its budget charge as unknown, never as zero. The daily [reconciliation](/docs/features/billing-connectors/) keeps counting a released reservation among the day's unknown ones until a provider charge is attested for it.

**When the provider's charge arrives afterwards.** A release is not the last word. If you later import a charge line for that call and it is `matched` by the provider's native request ID, attest it with `POST /api/v1/admin/quota-finance/reconcile-charge` as for any [charge](#releasing-usd-with-a-charge) (global admin, `quotas:manage`). For a released reservation the charge goes **back into the budget**:

- the charged amount is added to every money window the release gave back that is **still the current one**: day, week, month, quarter, year and lifetime, for each subject. A charge smaller than the released hold adds only the charge;
- a window that has rolled over since takes nothing, and the record lists it with `skipped: window_rolled_over`;
- a **zero** charge is accepted for a released reservation: it adds nothing and is recorded (`skipped: zero_charge`), so the call is settled as not charged;
- token windows (TPM, TPD) are never held again: a dollar charge proves no tokens;
- it is applied once per reservation and per charge line. Repeating the same operation changes nothing; another operation on the same line or reservation answers `409`.
- as for any charge, the call must have exactly one matched charge line: with two, neither is applied (`422`), and you correct the import first.

The answer has `state: released_charge_reapplied` and a `released_charge` object with each window and what was added. The same object appears as `charge` on the release in the trail (and in the console's **Manual releases**), an audit row `quota.reservation.release_charge_reapplied` is written with the reservation's organization, and the evidence of the reservation moves from `manual_release_unproven` to `budget_basis: manual_release_charge_attested`, with `reconciled_charge_usd`. Cost reports then show that charge as the call's budget charge. An organization admin sees it on its own releases; attesting a charge stays with the global admin. It needs `quota_finance` only, so a charge still goes back if `quota_manual_release` was turned off after the release.

**What is refused**, with nothing released:

| Answer | Why |
| --- | --- |
| `409 reservation_not_unknown` | A reservation is not held as unknown, or does not exist in your scope |
| `409 measurement_available` | A validated measurement exists: use `POST .../reconcile`, which settles the real amount |
| `409 charge_reconciled` | An attested provider charge already owns its budget |
| `409 release_count_mismatch` | The filter no longer selects `expected_count` reservations |
| `403 organization_forbidden` | An organization admin named a reservation of another organization, or one that also holds a ceiling set above its organization |
| `404 feature_disabled` | `quota_finance` or `quota_manual_release` is off |

**Organization admins.** An organization admin lists and releases only reservations of its organization's teams, and reads only its own trail and audit rows. A release returns every hold of a reservation, so it cannot release one that also holds a ceiling set from above: a tenant ceiling of its organization, a global or provider budget that is in force, an attribution group, a subject list or a hierarchy account. Those appear in its list with `blocked: outside_organization`, and the global admin releases them.

## Archiving the ledger

1. `GET /api/v1/admin/quota-finance/retention?retain_days=90&limit=500` shows what would be archived.
2. `POST /api/v1/admin/quota-finance/retention`, with the preview unchanged, version, fingerprint and the confirmation `ARCHIVE_TERMINAL_LEDGER`. The preview is valid for 15 minutes.

- Only closed reservations (`settled` or `released`) older than 32 days are archived, up to 1,000 per batch.
- The full record and its SHA-256 remain queryable at `GET .../archive` and in the console.
- **Nothing is deleted:** unknown reservations, counters, proofs, imports, reconciliations, manual-release records and audit records stay.
- A late charge can still be linked to an archived reservation (`archived: true`), but it does not reopen the balance.

Calendar-budget upgrade uses these retained originals to preserve current week, quarter and year consumption, without reopening or rewriting terminal/archive records. Lifetime upgrade adds the permanent view from all retained protected history, including unresolved reservations from prior years. Financial reports count the original reservation once; calendar/lifetime shadow counters are not separate provider charges. See the [coordinated upgrade procedure](/docs/features/budgets-and-tpm/#upgrade-from-a-version-before-calendar-budgets).

Archiving is not a backup, WORM or regulatory retention.

## Who can

Read with global `quotas:read`; write only by a global admin, with `quotas:manage`, CSRF and audit. Team roles do not see financial data. The [manual release](#releasing-an-unknown-reservation-by-hand) has its own permission, `quota_reservations:release`. All responses are `no-store`. Billing credentials are never the inference credentials and do not appear in the console.

## Measured performance

On a local PostgreSQL, 100 synthetic inferences with 12 concurrent workers (reservation, measurement and settlement) took 999 ms: p50 of 99.6 ms, p95 of 298.8 ms and p99 of 342.8 ms. The number includes database latency and contention over the same subjects; it does not measure the network, the provider or Kubernetes.

## 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 |
| --- | --- |
| `GET /api/v1/admin/quota-finance/archive` | Lists the archived imports, metadata only |
| `GET /api/v1/admin/quota-finance/unknown-reservations` | Lists the held unknown reservations and whether each is releasable |
| `POST /api/v1/admin/quota-finance/release-unknown` | Releases unknown reservations by hand, with a written reason |
| `GET /api/v1/admin/quota-finance/manual-releases` | Reads the finance trail of manual releases |
| `POST /api/v1/admin/quota-finance/connectors/{id}/sync` | Reads the provider's cost report for a date range now and imports what changed since the last read |

## See also

- [Budgets and TPM](/docs/features/budgets-and-tpm/).
- [Native billing imports](/docs/features/native-billing-imports/).
- Official sources: [OpenAI Costs API](https://developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/costs), [Anthropic Usage and Cost API](https://platform.claude.com/docs/en/manage-claude/usage-cost-api), [Google Cloud Billing export to BigQuery](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery).
