Skip to content

accounting: legacy completions (/v1/completions) get no record at all #2076

Not planned

Description

@boazdavid

What

wire.FormatOf deliberately returns (0, false) for legacy completions
(/v1/completions, /v1/engines/<id>/completions): their body has no
messages array and never carries cache_control, so the wire/facts
packages have no cache positions to read either way (see the doc comment on
FormatOf, core/accounting/wire/parse.go).

But Cortex's request parser does accept and forward these paths
(inference.dialectFor's completionsSuffix matches /completions with no
/v1/chat requirement), and the provider bills them. Once this accounting
layer is wired into the proxy (#2055 and later), a legacy-completions
request gets no accounting record at all — not even an input-only spend
op — because Host.end has nothing to parse when FormatOf says not-ok.
"No record" is indistinguishable from "no traffic" in the reports, which
understates real spend for any caller still using the legacy endpoint.

Suggested fix

The request body does carry model and prompt, so an input-only
accountant.KindSpend op should be derivable without any of wire's
position parsing — a separate, narrower path for this one endpoint shape,
not a wire.Format for a body this package can't otherwise read.

Context

Raised in review on #2054: #2054 (comment)
(core/accounting/wire/parse.go:47 — FormatOf's doc comment now states the
gap explicitly; this issue tracks closing it before the accounting layer
goes live.)

Activity

  1. self-assigned this
    on Nov 26, 2026
  2. boazdavid commented on Nov 29, 2026

    @boazdavid
    ContributorAuthor

    This issue is fixed

    PR #2152 (merged 2026-11-26) closes the "no record at all" gap this issue raised.

    What changed

    • Host.bill (core/accounting/host.go:681) now books Tier 1 metrics for any request Compute gives no Result. This covers a path wire.FormatOf cannot read, legacy completions included.
    • bill reads the usage straight from pctx.Extensions.Inference (the response). It needs no accounting record, so it does not depend on wire.Parse or a new accountant.KindSpend op.
    • It books llm.inference.tokens, cost_usd, estimated_cost_usd, and llm.cache.misses / miss_cost_usd.
    • docs/laptop-service.md:874-878 names /v1/completions by name as one of the paths now covered.

    What is still true, by design

    • wire.FormatOf still returns (0, false) for legacy completions. The doc comment at core/accounting/wire/parse.go:43-49 is unchanged.
    • There is still no accountant.KindSpend op and no llm.savings.* entry for these requests. This issue's suggested fix (an input-only KindSpend op from model and prompt) was not built. It is not needed: legacy completions carry no cache_control, so they have no saving to compute either way.

    Net effect

    A legacy-completions request now shows up in llm.inference.tokens / cost_usd reporting. It no longer reads as "no traffic." Closing this issue in favor of #2152.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions