Skip to main content
The SDK ships with a token economy module designed to estimate cost and expose telemetry for MCP operations.

Estimators

The SDK includes a built-in, zero-runtime-dependency o200k_base Byte-Pair Encoding (BPE) tokenizer, the industry standard encoding scheme for modern OpenAI models (GPT-4o, o1, o3-mini) and an accurate baseline across major LLM providers (Anthropic Claude 3.5/3.7, Google Gemini 2.0). Through build-time inlining and AST tree-shaking via tsup, the o200k_base vocabulary is bundled directly into the compiled distribution. This removes 25.95 MB of external legacy tokenizer dependencies, reducing the installed node_modules footprint from 100.95 MB to 84.43 MB (-17.1% net reduction). Both createTokenEstimator() (async factory) and createSyncTokenEstimator() (synchronous factory) provide immediate, synchronous access to RealTokenEstimator out-of-the-box:
HeuristicTokenEstimator (calculating Math.ceil(chars / 4)) remains available as a lightweight algorithmic fallback class if explicit heuristic modeling is desired.

TokenTelemetryEngine

TokenTelemetryEngine is a singleton collector for operation-level metrics:
  • Input/output token estimates
  • Operation type (tools_list, tool_call, resource_read, etc.)
  • Duration metadata
  • Session-level aggregates

LiopOTelBridge

LiopOTelBridge maps token telemetry into OpenTelemetry gen_ai.* semantics so external observability backends can ingest LIOP token data directly. The bridge automatically binds to your global MeterProvider and emits the following metrics:
  • gen_ai.client.token.usage (Histogram)
  • gen_ai.client.operation.duration (Histogram)
Use this module when you need production cost visibility across local and mesh-routed MCP workloads.

LiopMeshStatus Integration

The LIOP Agent exposes a local diagnostic tool called LiopMeshStatus that consumes the TokenTelemetryEngine internally to produce a structured operational status report via formatStatusBlock(). When an LLM calls this tool, it receives a structured report containing:
  • Session ID and uptime
  • Estimator model (o200k_base or heuristic)
  • Operation breakdown (each MCP method called, with input/output token estimates)
  • Cumulative totals (total tokens consumed across the session)
  • Cost projection (estimated cost based on configurable per-token pricing)
The token economy telemetry is intentionally visible in the LiopMeshStatus output. This transparency enables B2B clients to audit consumption patterns and allows AI agents to autonomously manage their context window budgets without requiring external monitoring infrastructure.

Deterministic AST Fuel Metering

In addition to token estimation, the SDK provides deterministic computational fuel measurement via calculateAstInstructionFuel:

Side-Channel Timing Invariance (NIST SP 800-53)

To ensure zero timing leakage across varying private inputs, calculateAstInstructionFuel enforces 100-unit bucket quantization: Fuel=⌈RawASTScore100⌉×100\text{Fuel} = \lceil \frac{\text{RawASTScore}}{100} \rceil \times 100 Across extensive automated profiling (50 consecutive executions on synthetic transaction batches), payloads with identical AST topology evaluating divergent secret inputs yield a standard deviation of strictly zero (stddev = 0).

Context & Token Economy vs Traditional MCP (Context-Pulling)

Traditional MCP requires pulling entire raw datasets across the network into the LLM context window before filtering or analysis can occur. LIOP executes sandboxed logic directly on the origin node, returning only aggregated proofs.

Empirical Efficiency Comparison


Playground Session Telemetry API

The LIOP Web Playground exposes an HTTP REST endpoint at GET /api/telemetry for live monitoring of session economy:

Sample Telemetry Response