estimate_prompt_tokens

Function estimate_prompt_tokens 

Source
pub fn estimate_prompt_tokens(req: &ChatRequest) -> u64
Expand description

Estimate the prompt token count for a canonical ChatRequest (PERF-01). The estimate is CONSERVATIVE (rounds up, adds per-message overhead) so the budget pre-check errs on the side of rejecting rather than undercounting. The actual spend is still provider- reported (crate::ai::budget records the provider’s usage.total_tokens after the call).

The estimate covers message content, tool calls, tool definitions, and structural overhead. It does NOT include max_tokens (the requested output cap); the caller adds that for the total-request pre-check.