Token usage

From Lingtai-AI/lingtai · View interactive version

Token usage is an AI agent skill from the GitHub repository Lingtai-AI/lingtai. Nested swiss-knife reference for token usage, cost, cache, and tool-call/API-call reports. Use for model cost reports, cache rates, budget/burn analysis, and tools-per-API-call trends across LingTai logs.

How to use this skill

Skill file

Token Usage, Cost, and Agentic-Intensity Reports v2

Network-wide token cost analysis powered by litellm's model pricing database (2700+ models), plus runtime-event trend analysis for tool calls per API call.

Quick Usage

Run the bundled cost script:

~/.lingtai-tui/runtime/venv/bin/python3 ~/.lingtai-tui/utilities/swiss-knife/reference/token-usage/scripts/cost_report.py /path/to/.lingtai

Cost-report optional flags:

Tool-call/API-call trend

Use this when the human asks for “tool calls per API call”, “tools per API call”, “agentic intensity”, or how tool-heavy the local LingTai network has been over time. The script reads LingTai logs/events.jsonl files, not token_ledger.jsonl, because it needs runtime event IDs.

~/.lingtai-tui/runtime/venv/bin/python3 ~/.lingtai-tui/utilities/swiss-knife/reference/token-usage/scripts/tool_calls_per_api_call_trend.py \
  /path/to/project/.lingtai \
  --days 5 \
  --timezone America/Los_Angeles \
  --model gpt-5.5

Optional flags:

Metric definitions:

Treat the metric as behavioral intensity, not token volume: a higher value means each model API call is asking the runtime to do more tool work on average.

How It Works

cost_report.py scans every logs/token_ledger.jsonl under .lingtai/, prices

each entry via litellm model_cost → OpenRouter → custom-pricing fallback (see

below), and reports per-agent/grand-total cost plus cache-hit and burn rates.

tool_calls_per_api_call_trend.py instead scans logs/events.jsonl, counts

llm_response / tool_call_received events, and writes Markdown/JSON/CSV daily

trend artifacts.

Pricing Sources

Primary: litellm's model_cost dictionary — covers OpenAI, Anthropic, Google, Meta, Mistral, Xiaomi, and 100+ other providers.

Secondary: OpenRouter API — real-time pricing for 368 models, more up-to-date than litellm for some providers.

Fallback: Custom pricing in scripts/custom_pricing.json — for models not yet in litellm or OpenRouter (e.g., MiMo v2.5 Pro direct API).

Override: Pass --custom-pricing FILE to add project-specific pricing.

Custom Pricing Format

{
  "mimo-v2.5-pro": {
    "input_cost_per_token": 0.000001,
    "output_cost_per_token": 0.000003,
    "cache_read_input_token_cost": 0.0000002
  }
}

Ledger Format

Each agent's logs/token_ledger.jsonl has one JSON object per LLM call:

{
  "source": "main",
  "ts": "2026-05-06T19:31:40Z",
  "input": 53295,
  "output": 277,
  "thinking": 172,
  "cached": 12288,
  "model": "mimo-v2.5-pro",
  "endpoint": "https://api.xiaomimimo.com/v1"
}

Dependencies

> token-usage needs litellm (~5MB) for model pricing. Install it? (pip install litellm)

Install only after they say yes.

Tips


Found a bug or issue? If you encounter any problems with this skill, load the lingtai-issue-report skill and follow its instructions to report it.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.