usageTokensLogPattern top-level property

RegExp usageTokensLogPattern
final

The pinned one-line shape (AC7): every field documented in gh-1241, compact JSON, fixed key order. source is the segment's marker (I3). gh-1460 adds the OPTIONAL "model" key — the segment's last-seen model id, emitted once per segment-close line so every token row is attributable (and priceable) downstream; it is omitted when the fold never saw a model (legacy chains), which keeps old lines parsing and lets this regex keep matching them (the group is optional, and the builder only writes the key when a model exists).

Implementation

final RegExp usageTokensLogPattern = RegExp(
  r'^fa-tokens: \{"sessionId":"[^"]*","segment":[0-9]+(?:,"model":"[^"]*")?'
  r',"input":[0-9]+,"output":[0-9]+,"cacheRead":[0-9]+,'
  r'"requests":[0-9]+,"source":"(reported|estimated|mixed)"\}$',
);