Token usage tracking for LLM API calls.
# Source: https://github.com/amruth-sn/kong | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Token usage tracking for LLM API calls."""
from __future__ import annotations
from dataclasses import dataclass, field
from kong.config import LLMProvider
@dataclass(frozen=True)
class PricingTier:
"""Per-model pricing in USD per 1M tokens.
Rates sourced from published Anthropic/OpenAI API pricing pages.
"""
input_rate: float
output_rate: float
cache_write_rate: float = 0.0
cache_read_rate: float = 0.0
_DEFAULT_PRICING = PricingTier(input_rate=3.0, output_rate=15.0)
PRICING_REGISTRY: dict[str, PricingTier] = {
# Anthropic: cache_write = input * 1.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key