Skip to content

Provider cost connectors

Last updated: 2026-11-22T07:30:00-03:00 (UTC-3)

A cost connector reads a provider’s organization cost report directly, with an administrative credential you supply, and imports it into the financial reconciliation ledger. A daily reconciliation then shows, side by side, what the provider charged and what the gateway recorded for the same provider, with an explicit state for every day. Flag: billing_connectors (default false).

Two sources are implemented:

Source Report Credential
anthropic_cost_report Anthropic Cost Report, GET https://api.anthropic.com/v1/organizations/cost_report, daily buckets grouped by description An Anthropic Admin API key (sk-ant-admin...), sent as x-api-key with anthropic-version: 2023-06-01
openai_costs OpenAI organization costs, GET https://api.openai.com/v1/organization/costs, daily buckets grouped by line item An OpenAI Admin key with read access to usage (api.usage.read), sent as Authorization: Bearer

The origin is fixed per source; it cannot be configured, redirects are not followed and no other host is called. The credential is read from its environment variable (or your secret manager) at each synchronization. It is never an inference key, never stored, never logged and never shown: the API and the console only say whether it is set.

A connector is different from pasting an export with native billing imports: the paste is operator-attested, the connector fetches the report itself, pages through it completely and imports only what changed since its last read. For the same report and account you use one or the other; the gateway refuses overlapping periods between the two.

features:
quota_management: true # syncing is a finance write
durable_usage: true
quota_finance: true
billing_connectors: true
billing_connectors:
- id: anthropic-org # ^[a-z][a-z0-9_-]{1,31}$
source: anthropic_cost_report # or openai_costs
admin_key_env: ANTHROPIC_ADMIN_KEY
provider_id: anthropic # a configured provider; its connection fingerprint labels the lines
account_id: main-org # your label for the provider organization
finalization_hours: 48 # optional, 1-720; default 48
max_days: 31 # optional, 1-92; default 31
Field Default Meaning
id required Unique connector ID.
source required anthropic_cost_report or openai_costs.
admin_key_env required Name of the environment variable holding the administrative key. A value that is not a variable name is refused at boot.
provider_id required The configured provider the charges belong to, with a canonical ID (^[a-z][a-z0-9_-]{1,63}$). Lines carry its exact connection fingerprint.
account_id required Your label for the provider organization, up to 128 characters. Source and account identify the ledger, so the label must not change once synchronized (a new label would import every row again), and a manual paste of the same report must use the same label to be recognized as overlapping.
finalization_hours 48 Days that ended less than this ago are imported as provisional: the import’s coverage is partial, and the reconciliation shows those days as provisional. Providers revise recent days.
max_days 31 Longest period one synchronization may read.

Connectors are boot configuration: changing the list requires a restart. Up to 16 connectors, at most one per provider (the daily reconciliation compares one provider’s report with its gateway traffic) and at most one per source and admin_key_env. A connector re-pointed to another provider_id after it synchronized is refused (409). The flag is an operator control; it requires quota_finance.

Terminal window
curl -b "$COOKIE_FILE" -H "X-CSRF-Token: $CSRF" -X POST \
-H 'Content-Type: application/json' \
-d '{"version": 12, "from": "2026-10-15", "to": "2026-11-15"}' \
http://localhost:8080/api/v1/admin/quota-finance/connectors/anthropic-org/sync
  • version is the current finance version (GET /api/v1/admin/quota-finance/report?limit=1); a concurrent import answers 409.
  • from and to are UTC dates, to exclusive, at most max_days apart and ending no later than tomorrow.
  • The gateway reads every page (at most 32, each at most 512 KiB), checks the cursors, the buckets (inside the period) and the currency (USD), and converts amounts exactly: Anthropic reports decimal cents, OpenAI decimal dollars; a value that is not exact at 1e-12 USD is refused, never rounded.
  • A row identity that repeats within one fetch, or a bucket re-sent on a later page, refuses the whole synchronization (502 connector_invalid_report): it is never summed.
  • Each report row has an identity made of its bucket and every descriptive field the provider returned (model, description, token type, tier, line item, project and so on), without its amount and quantity.

What one synchronization imports, as one immutable import (source anthropic_cost_connector or openai_cost_connector):

Row Import line
New, non-zero charge (or credit if negative)
Same identity, different amount adjustment of the difference
Previously reported, now absent from the complete report adjustment back to zero (“withdrawn by provider”)
Unchanged nothing

If nothing changed, the run is recorded as no_change and no import is created. The run keeps the SHA-256 of the fetched pages; the import’s source_sha256 binds that digest to the run, so a provider that reverts a revision still produces a distinct, traceable import. The connector’s line ledger and the import commit in one transaction, so the net of all imports always equals the latest report, and no row is counted twice. A period that would change more than 1,000 lines is refused; sync a shorter period.

Responses: 200 with the run (state, import_id, new_lines, corrected_lines, withdrawn_lines, pages, rows, final_through, source_sha256). Errors: 503 connector_credential_missing, 502 connector_credential_rejected (the provider refused the key; it needs read access to the cost report), 503 connector_rate_limited (with the provider’s Retry-After), 502 connector_unavailable, 502 connector_invalid_report (the report did not match its published format), 422 connector_report_too_large, 409 version or overlap conflict. The provider’s response body is never echoed.

GET /api/v1/admin/quota-finance/connectors lists the connectors as billing_connectors (the YAML names: id, source, provider_id, account_id, finalization_hours, max_days; without secrets: credential_configured only) and their last five runs.

GET /api/v1/admin/quota-finance/reconciliation?provider_id=anthropic&from=2026-10-15&to=2026-11-15 (at most 92 days) returns one row per UTC day:

Field Meaning
provider_charged_usd Net of connector lines whose bucket starts that day; null when nothing was imported
gateway_requests, gateway_estimated_usd Usage events of that provider and day, and the sum of their known valuations: an estimate priced from the price book, with discounts and margins, frozen in each request
gateway_not_fully_valued Events whose valuation is partial, unknown or missing: their cost is not in the estimate
ledger_settled_usd, ledger_unknown_reservations Budget reservations of that provider and day: settled amounts at the approved rates captured at admission (the budget charge) and reservations still unknown
state See below
difference_usd Provider minus gateway estimate, only on comparable days

States, decided in this order:

State Meaning
not_imported No connector run covered the day
provisional Covered, but the day is inside finalization_hours: the provider may still revise it
incomplete Some gateway request of the day has no known cost, or a reservation is still unknown
provider_only The provider charged, the gateway recorded nothing: traffic outside this gateway (another application, a coding tool, the provider console)
gateway_only The gateway recorded traffic, the provider charged nothing: a different account, a free tier or a report gap
no_activity Neither side has anything
comparable Both sides complete; difference_usd is shown

coverage counts days per state. A comparable difference is evidence to investigate, not a correction: imports never change budget balances (see releasing USD with a charge for the explicit, per-request path).

Budget & TPM → Finance & reconciliation → Provider cost connectors lists the connectors and their runs, synchronizes a chosen period (global administrator) and shows the daily reconciliation with its coverage.

Reading needs global quotas:read; synchronizing needs a global administrator with quotas:manage, quota_management, CSRF and same origin, and is audited (quota.billing.import when lines are imported, quota.billing.connector_sync otherwise). Team roles see nothing.

  • The reports are aggregates: no line names a gateway inference, so connector lines never release a held reservation.
  • Amounts are what the provider’s report says, not an invoice: credits, taxes and invoice adjustments may differ.
  • Anthropic usage billed through other products (for example a subscription plan) may not appear in the API organization’s report.
  • Other sources are added as new fixed sources with their own parser, never as a configurable URL. Further provider cost reports and coding-tool usage feeds are designed for and not implemented here.
  • Upgrade. Migration 148 creates the connector line ledger and run history. Upgrade every replica before enabling the flag.

m7gtw[email protected]