Documentation
¶
Index ¶
- type ModelPrice
- type Registry
- func (r *Registry) Cost(model string, input, output, cachedInput int, providerCost float64) (float64, string)
- func (r *Registry) Lookup(model string) (ModelPrice, bool)
- func (r *Registry) Register(model string, price ModelPrice)
- func (r *Registry) RegisterPrefix(prefix string, price ModelPrice)
- func (r *Registry) SetFallbackRate(ratePerKTokens float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ModelPrice ¶
type ModelPrice struct {
InputPerMTok float64 // cost per million input tokens
OutputPerMTok float64 // cost per million output tokens
CachedInputPerMTok float64 // cost per million cached input tokens; 0 means same as InputPerMTok
}
ModelPrice holds per-million-token pricing for a model.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps model names/prefixes to their pricing.
func (*Registry) Cost ¶
func (r *Registry) Cost(model string, input, output, cachedInput int, providerCost float64) (float64, string)
Cost calculates the USD cost for a given model and token usage. Returns the cost and a source string: "provider" if providerCost > 0, "registry" if the model was found, "fallback" if the default rate was used, or "unknown" if no pricing is available.
func (*Registry) Lookup ¶
func (r *Registry) Lookup(model string) (ModelPrice, bool)
Lookup returns the pricing for a model. Exact match is tried first, then longest prefix match.
func (*Registry) Register ¶
func (r *Registry) Register(model string, price ModelPrice)
Register adds an exact-match model price.
func (*Registry) RegisterPrefix ¶
func (r *Registry) RegisterPrefix(prefix string, price ModelPrice)
RegisterPrefix adds a prefix-match model price. Longer prefixes take priority. Duplicate prefixes are overwritten.
func (*Registry) SetFallbackRate ¶
SetFallbackRate sets the default rate per 1K tokens used when no model match is found. Set to 0 to disable the fallback (cost will be 0).