Skip to content

16.6 Costing — stored before API before AI

The planner chooses the plan whose steps’ costs sum least, so a step’s cost is what separates two plans that reach the same goal. It is judged from what the step reaches, read off its body like everything else:

  • a stored read — labels whose producers read what the deployment holds, or no producer at all;
  • an API — a label or relationship whose producer calls an outside source (§5.3);
  • a model — ai.fromText, an ai.* function or {ai: …} directive (§7), a model reduction such as relevant (§7.7), or a label whose producer is model-backed (generative, agentic-rag, extract, aggregate).

The ordering is the contract: stored < API < model, and one model step outweighs several API steps. A stored read is milliseconds and free; an API is a round trip, a rate limit and a source that can be down, but answers the same way twice; a model call is seconds, billed per token, and a judgement that can differ between runs. So a model step is in a plan only when the goal needs what only a model makes. Presence counts, not number: how many calls a run makes is the quote’s business (§9), not the planner’s.

  • Pluggable. The cost function is a deployment’s to replace. Costs are in 0..1, and a value outside that range is refused, not clamped — a clamped cost would tie plans the function meant to separate. The reference host’s default prices a stored read at 0.05, adds 0.2 for an API and 0.7 for a model (informative; the ordering is what is promised).
  • reaches is stated beside cost. A step’s reaches — api, model, both, or empty — is read off the step; its cost is the installed function’s number. A surface labelling a step “AI” reads reaches, never the number.
  • Equal cost is a tie, reported and never broken (§16.5).
  • The quote is not the cost. Each planned answer carries the engine’s quote for the compiled statement (modelCalls, apiCalls, wouldRefuse), made by reading the graph only. The quote does not price ai.fromText: each step it leaves out is listed under unpriced, and those calls are priced when the plan runs, and refused there over the limit (§7.8, “Cached and priced”).