tokenecon

Python library that costs and tracks LLM agent runs across models and frameworks, reporting tokens, dollars, and cost per solved task, with LiteLLM and LangChain/LangGraph integrations. MIT licensed.

View on GitHub Unknown

A dependency-free Python library that models, forecasts, and tracks LLM agent spend per task, with tiered routing and budget guardrails.

What it is

tokenecon is a Python library for understanding what LLM agent runs actually cost. A single model call has a predictable price, but an agent that loops through tool calls, retries, and retrieved documents can multiply that cost in ways that often only show up on a cloud bill. tokenecon aims to surface this earlier. It breaks per-task spend into prompt, completion, tool-call, and retrieval tokens, priced per model tier, so teams can forecast and budget before deployment. It also includes a tiered router that classifies each request by difficulty, sends it to the cheapest tier likely to handle it, escalates on low confidence, and enforces per-task budgets. Each run produces a receipt listing the tier, tokens, cost, and confidence for every step. The library is MIT licensed, has no dependencies, and targets Python 3.9 and later.

Key features

  • Per-task cost receipts showing tier, tokens, dollars, and confidence for each step
  • Tiered routing that selects the cheapest tier clearing a difficulty threshold, with escalation on low confidence
  • Per-task budget guardrails that serve cached answers or keep current results instead of failing
  • Cost tracking hooks for Strands agents, LiteLLM, and LangChain or LangGraph, priced from provider-reported token counts
  • A command-line interface for demo runs, cost forecasting from a request list, and custom tier definitions

Use cases

  • Forecasting spend for a planned agent workload before it goes live
  • Comparing the cost of routing requests across tiers against an always-strongest-model baseline
  • Attaching cost-per-correct metrics to agent evaluation runs
  • Setting per-task spending caps so runaway loops degrade gracefully

Who it's for

Engineers building LLM agents who need to budget and monitor token spend across models or frameworks. It also suits teams who want a simple, inspectable baseline for cost modeling before adopting heavier tooling.

Getting started

tokenecon is installed from PyPI, and the README also describes installing from a source checkout. Its quickstart shows creating a TieredRouter with default tiers and a per-task budget, then running a request to produce a printed receipt. Default tier prices are placeholders, so replace them with your provider's current price list before relying on the numbers.

Alternatives

The directory lists related observability and evaluation projects, including OpenLIT, Helicone, Agenta, and Portkey Gateway. Their feature sets differ, and this entry does not claim how tokenecon compares to them.

Drafted with AI from the project's public documentation; verify against the source. Written 3 Nov 2026.

Nearby on the map

Related projects