AGENTS.md
Guidance for coding agents working on Codex Token Pricing Tier in the codexTokencount project.
Project overview
This guide covers src/pricing.ts. The pricing module maps Codex model ids to repository snapshot prices, supports user overrides, computes standard and long-context rates, and separates input, cached input, output, and reasoning output cost.
Primary source files
- src/pricing.ts owns PRICING_AS_OF, BUILTIN_PRICES, setPricingOverride, resolvePrice, isLongContext, computeCostForTier, and computeCost.
- src/types.ts defines ModelPrice, TokenCounts, and CostBreakdown.
- src/parser.ts keeps standardTokens and longTokens buckets so tier decisions remain per token_count event.
- src/parser.test.ts verifies long-context pricing is decided per event rather than by hourly bucket total.
Setup commands
npm install npm test npm run compile npm run check-types npm run package npx esbuild src/selftest.ts --bundle --platform=node --format=cjs --outfile=out/selftest.js node out/selftest.js <sessions-dir>
Change rules
- Treat PRICING_AS_OF as a repository snapshot date, not a claim about current prices.
- Keep overrides before built-ins and sort match patterns by descending length.
- Do not invent pricing for models intentionally unresolved by resolvePrice.
- Apply long-context tier decisions per token_count event before bucket aggregation.
- Price reasoning output with the output rate because it is part of output token usage.
Testing
Cover exact model matches, no-price models, overrides, cached input, reasoning output, standard tier, long-context tier, and mixed standard plus long events in one hourly bucket.
PR checklist
- Pricing changes update tests and README claims together.
- Unpriced models still count tokens and produce warnings.
- npm test, npm run compile, and npm run check-types pass.