Skip to main content

rendered_token_cost

Function rendered_token_cost 

Source
pub fn rendered_token_cost(provider_id: &str, frame: &ContextFrame) -> u32
Expand description

What composing a frame actually costs: the canonical token count of the whole block it renders as, chrome included.

This is the quantity compose_for_prompt budgets against, and it is deliberately not ContextFrame::expected_inline_token_cost. That one is the §B3 canonical cost of content — the right rule for auditing a provider’s declared token_cost, because content is the one field whose exact bytes both sides observe. It is the wrong rule for packing a prompt: §F2 and §F3 oblige the host to render a title and a citation_label, both provider-controlled and neither counted by §B3, so a frame with empty content is honestly worth token_cost: 0 and can still contribute an unbounded number of real tokens. §7.2 already assigns the chrome to the host (“the host’s rendering chrome is the host’s cost to budget”); this is the host paying it.

Public because a host that packs frames itself needs the same number the reference packer uses — deriving it independently is how two hosts end up disagreeing about whether a frame fits.