Token Pricing
Token pricing is the most natural fit for LLM-backed endpoints where the true cost scales with prompt size or model usage.
The tiktoken package is an optional peer dependency — only loaded when createTokenPricing() or countTokens() is called. Install it with npm install tiktoken if you use this feature.
OpenAI Example
All TokenPricing methods (calculate, validateQuote, countTokens) are async because tiktoken is lazy-loaded via dynamic import. This keeps the 5MB+ WASM binary out of your bundle if you don't use token pricing.
Custom Model Example
When This Is Better Than Generic Dynamic Pricing
Use token pricing when:
- the endpoint wraps an LLM
- model cost is the dominant pricing factor
- buyers benefit from seeing model and token context in the quote
Use Dynamic Pricing when the cost model is not really about tokens.