Skip to main content

estimate_request_tokens

Function estimate_request_tokens 

Source
pub fn estimate_request_tokens(
    messages: &[ChatMessage],
    tools: &[ToolSchema],
) -> u64
Expand description

PARITY-18 D1 — the full wire-request token estimate: every message in messages (including the system prompt at index 0) plus the serialized tools schema array, which is a real part of the provider request but — before PARITY-18’s re-fix — was never counted by the preflight guard at all. A session whose messages alone fit comfortably could still carry a fat builtin/MCP tool-schema array that blows the real wire request; this is the fix.