Skip to content
FluxMeter
中文

Writing

After the gateway timeout: where the attribution chain breaks next

After a gateway timeout, attribution can still break. HTTP 202 is custody, not settlement; UNKNOWN is not zero. Not a billing suite; no zero-overspend promise.

2026-11-24 · Architecture · 9 min read

The first architecture post was about the receipt gap: the provider may have finished a request while the gateway had already timed out. A timeout tells the gateway it stopped waiting. It does not say whether processing occurred, what usage accrued, or whether a retry is safe. Its conclusion was deliberately narrow: durable delivery cannot substitute for durable knowledge of execution, and a missing receipt is not zero usage.

This post moves downstream. For a usage event to become "this customer, this period, this many tokens, this cost," which links must it pass through—and after a timeout, which link can still break next?

Two semantics: request success vs usage settlement

Timeout discussions tend to merge two different kinds of "success."

Request-success semantics. What the gateway returned to the caller: success, an error, or a timeout. The caller may retry on that basis. The HTTP status describes how this wait ended, not how much upstream work was done.

Usage-settlement (attribution) semantics. Did a usage event enter custody, get aggregated, and get attributed to a customer and priced, so that it becomes a queryable customer usage line? The question is not "what did the caller receive" but "how far along the chain did the evidence get."

Each can succeed or fail independently. A request can time out after the provider executed it. A usage event can be reliably received and still not be a customer line yet. In one sentence: the request's HTTP status answers "did we finish waiting"; the usage chain answers "which link has the evidence reached." HTTP 202 means custody (reliably received), not settlement.

The chain: from event to customer usage line

FluxMeter's single supported path, as published on Architecture, is:

SDK / Gateway → HTTP Custody → Kafka → Flink → Redis → Usage API (export to a billing system is optional and not covered here; see export usage to Lago, Stripe, Orb, or Metronome).

As the Architecture page describes it (published facts):

SDK / Gateway: produces usage events with fields such as `customerId`, `modelId`, `inputTokens`, and `outputTokens`. Gateway orchestration is estimate → gate → reserve → upstream → Custody, with a Redis outbox for durable handoff.

HTTP Custody: returns 202 only after Kafka acknowledgement; when Kafka is unavailable, it returns a retryable 503.

Flink: the usage aggregation engine. It aggregates token events per customer and attributes cost using the pricing catalog. It is not a billing engine.

Redis: holds query state for the Usage API.

Usage API: returns customer usage lines shaped like `customer_id`, `period`, `tokens`, and `cost_usd`.

ClickHouse (optional): an audit cold store, not the metering or billing source of truth.

The authoritative order is Ingest → Price → Attribute → Control (optional) → Export (optional). Identity mapping, pricing catalog maintenance, and billing product choice stay with the operator.

Where the chain can break after a timeout

What follows is an analysis in chain order—not an incident review, and not new experimental data.

Link 0: no receipt, no event. This is the first post's territory. The provider's result never reached the gateway, so the chain has no starting point. No downstream link should invent an event here—least of all a 0/0 "zero usage" event. The first post calls this UNKNOWN is not ZERO; a full Hybrid UNKNOWN lifecycle remains a candidate design, not a shipped capability.

Link 1: an event exists but has not entered custody. The gateway has usage and submits it to Custody, which returns 503 because Kafka has not acknowledged. That is a delivery problem, not an execution problem: retry delivery of the same event with a stable event identifier rather than calling the provider again. The gateway's request timeout and Custody's 503 are different events and should not share one "retry" switch.

Link 2: in custody (202) but not yet a customer line. A 202 only says the event was reliably received. It still has to be aggregated, attributed to a customer, priced, and reflected in Usage API query state. Between "received" and "visible in a customer line" there is a gap; treating 202 as "booked" makes reconciliation wrong inside that gap.

Link 3: a customer field exists, but the customer identity is wrong. Attribution is keyed on the customer identifier in the event. If the gateway knows only an API key or an upstream project and never maps it to the real customer or tenant, the event can flow cleanly through aggregation and still land on the wrong line or in a catch-all bucket. Identity mapping is operator-owned, and when this link breaks the system looks healthy (see multi-tenant AI usage: tokens by customer, not API key).

Link 4: tokens are right, but the pricing basis is not. Cost is attributed from the pricing catalog. If the catalog is missing, stale, or diverges from how the provider actually charges, token counts can be correct while `cost_usd` still fails to reconcile with the upstream invoice. That is a pricing-input problem, not an aggregation problem, and catalog maintenance is also operator-owned (see upstream invoice vs customer-level usage).

Link 5: aggregated usage is not billing truth. Flink produces aggregated customer usage and cost attribution; it is not a billing engine for invoicing, rating, or collection. ClickHouse, if enabled, is an audit cold store for look-back, not billing truth. Invoices and payments belong to your billing system.

Side branch: releasing a hold is not settlement. If you use the optional pre-request budget (check / reserve), a hold that expires after a timeout restores budget visibility. It does not prove the provider consumed nothing, and it does not create a customer usage line. Optional pre-request budget checks and blocking can limit new spend, but they do not guarantee zero overspend (see check/reserve for token budgets).

Last link: feeding unknown or unattributed input to a billing suite is not settlement. Export sends attributed customer lines into your billing stack. If the input mixes unknown executions, missing customer identifiers, or wrong prices, the billing suite will faithfully turn them into invoice numbers—which only moves the problem one step downstream.

Facts vs inference

Facts (from the live Architecture page and the first post): the supported path and each link's role; 202 only after Kafka acknowledgement, retryable 503 when Kafka is unavailable; Flink is the usage aggregation engine; ClickHouse is an audit cold store; identity mapping and the pricing catalog are operator-owned; the first post's experiment used a local mock, called no commercial provider, and establishes no actual provider charge; Hybrid UNKNOWN is not shipped.

Inference (this post's analysis): the break points at links 2–5 and the last link are checkpoints derived from the chain's structure, not observed incidents, and no frequency is claimed.

Where FluxMeter fits

FluxMeter is open-source, self-hosted LLM token metering software for AI gateways and multi-tenant products: customer-level tokens and cost, without a full billing suite. It can optionally export usage lines into your billing stack (for example Lago, Stripe, Orb, or Metronome) and does not replace them. The optional pre-request budget (check / reserve / hard gate) limits new spend and does not guarantee zero overspend. FluxMeter here means LLM token metering software, not a physical fluxmeter instrument.

Closing

After a timeout, the chain's job is not to fill in a number quickly. It is to preserve uncertainty until evidence supports an attributed customer line: do not write a missing receipt as zero, do not call custody "billed," and do not treat aggregated usage as an invoice.

Where the receipt gap starts: When the LLM Provider Finishes but Your Gateway Times Out

Published chain facts: Architecture

Run it locally: `make demo` (see Docs)

Pool total vs customer grain: Upstream invoice vs customer-level usage

Customer identity: Multi-tenant AI usage: tokens by customer, not API key

Budgets and their limit: Check/reserve for token budgets: no zero-overspend guarantee

Export after attribution: Export usage to Lago, Stripe, Orb, or Metronome

After a timeout, the chain's job is not to fill in a number quickly. It is to preserve uncertainty until evidence supports an attributed customer line: do not write a missing receipt as zero, do not call custody "billed," and do not treat aggregated usage as an invoice.