@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
31 lines (30 loc) • 1.66 kB
TypeScript
/**
* Reads token usage out of Codex's own rollout transcripts.
*
* Layout: `~/.codex/sessions/<yyyy>/<mm>/<dd>/rollout-<iso>-<sessionId>.jsonl`.
* Each line is one of `session_meta`, `turn_context`, `response_item` or
* `event_msg`; usage lives on `event_msg` records whose `payload.type` is
* `token_count`.
*
* The counter semantics are the whole story here, and they are the opposite of
* the Claude Code reader's. Every `token_count` event carries BOTH a
* cumulative `total_token_usage` for the session and a per-turn
* `last_token_usage`. Summing the per-turn values is the obvious move and it is
* wrong: measured across all 108 sessions on a real machine, summing yields
* 9,191,613,238 tokens against a true 5,653,217,442 — an overstatement of
* 62.6%, and 195% on the worst single session. The per-turn value repeats
* across events within a turn, so it double-counts.
*
* The cumulative counter is authoritative and was monotonic in all 108
* sessions — it never resets mid-file — so the last one in the file is the
* session's true total. `Math.max` is still used rather than "last seen",
* because a counter that is only monotonic in every case observed is not the
* same as one that is guaranteed to be, and the max costs nothing.
*
* Cost is deliberately not computed. Codex is a ChatGPT subscription — the
* rollouts carry `rate_limits.plan_type` — so a per-token dollar figure would
* be an invention, not a measurement. The tokens are real; the cost is
* `unavailable`.
*/
import type { LocalUsageReader } from "../types/index.js";
export declare function createCodexReader(): Promise<LocalUsageReader>;