{"id":47805712,"url":"https://github.com/steipete/tokentally","last_synced_at":"2026-04-03T17:35:22.021Z","repository":{"id":329420022,"uuid":"1119512472","full_name":"steipete/tokentally","owner":"steipete","description":"One tiny lib for LLM token + cost math","archived":false,"fork":false,"pushed_at":"2026-03-27T07:08:54.000Z","size":79,"stargazers_count":53,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-03-30T05:39:00.855Z","etag":null,"topics":["cost","token","typescript"],"latest_commit_sha":null,"homepage":"https://tokentally.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steipete.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-12-19T11:43:00.000Z","updated_at":"2026-03-24T03:52:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/steipete/tokentally","commit_stats":null,"previous_names":["steipete/tokentally"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/steipete/tokentally","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steipete%2Ftokentally","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steipete%2Ftokentally/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steipete%2Ftokentally/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steipete%2Ftokentally/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steipete","download_url":"https://codeload.github.com/steipete/tokentally/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steipete%2Ftokentally/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31366366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:13:05.644Z","status":"ssl_error","status_checked_at":"2026-04-03T17:13:04.413Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cost","token","typescript"],"created_at":"2026-04-03T17:35:21.395Z","updated_at":"2026-04-03T17:35:22.011Z","avatar_url":"https://github.com/steipete.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧮 tokentally — One tiny lib for LLM token + cost math\n\nToken usage in, dollar totals out.\n\nSmall TypeScript library for:\n- Normalizing token usage across providers\n- Resolving per-token pricing (static maps, LiteLLM catalog, OpenRouter catalog)\n- Estimating and aggregating USD cost\n\n## Install\n\n```bash\npnpm add tokentally\n```\n\n## Core usage (browser-safe)\n\n```ts\nimport { estimateUsdCost, normalizeTokenUsage, pricingFromUsdPerMillion } from 'tokentally';\n\nconst usage = normalizeTokenUsage({ prompt_tokens: 1000, completion_tokens: 250 });\nconst pricing = pricingFromUsdPerMillion({ inputUsdPerMillion: 1.75, outputUsdPerMillion: 14 });\n\nconst cost = estimateUsdCost({ usage, pricing });\n// { inputUsd: ..., outputUsd: ..., totalUsd: ... }\n```\n\n## Node helpers (catalog sources)\n\n### LiteLLM pricing + limits\n\n```ts\nimport { loadLiteLlmCatalog, resolveLiteLlmPricing, resolveLiteLlmMaxOutputTokens } from 'tokentally/node';\n\nconst { catalog } = await loadLiteLlmCatalog({ env: process.env, fetchImpl: fetch });\nconst pricing = catalog ? resolveLiteLlmPricing(catalog, 'openai/gpt-5.2') : null;\nconst maxOut = catalog ? resolveLiteLlmMaxOutputTokens(catalog, 'openai/gpt-5.2') : null;\n```\n\n### OpenRouter pricing (optional)\n\n```ts\nimport { fetchOpenRouterPricingMap, resolvePricingFromMap } from 'tokentally/node';\n\nconst map = await fetchOpenRouterPricingMap({ apiKey: process.env.OPENROUTER_API_KEY!, fetchImpl: fetch });\nconst pricing = resolvePricingFromMap(map, 'openai/gpt-5.2');\n```\n\n## API\n\n- `normalizeTokenUsage(raw)` → `{ inputTokens, outputTokens, reasoningTokens, totalTokens } | null`\n- `pricingFromUsdPerMillion({ inputUsdPerMillion, outputUsdPerMillion })`\n- `estimateUsdCost({ usage, pricing })`\n- `tallyCosts(calls)` → totals + per-model breakdown\n\n## Non-goals\n\n- Perfect accounting. This is a **best-effort estimate** based on the pricing source you provide.\n- Provider-specific invoice reconciliation.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteipete%2Ftokentally","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteipete%2Ftokentally","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteipete%2Ftokentally/lists"}