Skip to content

fix(cost): reserve reasoning against an explicit total completion cap #557

Description

@drewstone

Problem

Paid-call admission currently receives ChatRequest.maxTokens and can treat it as the maximum billable completion. That assumption is false for providers where max_tokens limits visible output while hidden reasoning is billed separately.

Direct provider proof on 2026-08-10, without a coding harness:

  • model: glm-5.2
  • request: max_tokens: 8
  • response: 3 visible tokens, 135 completion tokens, 132 reasoning tokens
  • request with max_completion_tokens: 256: 119 completion tokens, including 116 reasoning

This is distinct from CLI harness prompt overhead tracked in #544.

Completion criteria

  • Give cost reservation an explicit maximum total billed completion-token value.
  • Keep any visible-output and reasoning limits separate in request/evidence types.
  • Include the total cap in maximum-charge calculation before dispatch.
  • Reject capped paid execution when the caller/runtime cannot prove an enforceable total cap.
  • Compare reported completion plus reasoning semantics against the admitted limit without double counting.
  • Preserve separate visible, reasoning, cached, and total token evidence.
  • Keep execution transport in agent-runtime as required by refactor(execution): remove Eval-owned paid model transports #539.
  • Add a regression where visible output is below maxTokens but billed reasoning exceeds it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions