File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,11 +99,19 @@ export async function measurePayloadShape(
9999 ] ) ;
100100 const tokenize_ms = Math . round ( ( performance . now ( ) - start ) * 1000 ) / 1000 ;
101101
102+ // A `0` from countTokensSafe on empty text is a trivial short-circuit, not
103+ // a real tokenization — only a non-null result on non-empty text proves the
104+ // encoder ran. If neither payload was actually tokenized, zero out
105+ // tokenize_ms to preserve the documented "skipped/failed" signal.
106+ const tokenizerRan =
107+ ( requestText !== "" && tIn !== null ) ||
108+ ( responseText !== "" && tOut !== null ) ;
109+
102110 return {
103111 bytes_in,
104112 bytes_out,
105113 tokens_in : tIn ?? 0 ,
106114 tokens_out : tOut ?? 0 ,
107- tokenize_ms : tIn === null && tOut === null ? 0 : tokenize_ms ,
115+ tokenize_ms : tokenizerRan ? tokenize_ms : 0 ,
108116 } ;
109117}
You can’t perform that action at this time.
0 commit comments