pricing

package
v0.0.0-...-dc958b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OriginEmbedded = "embedded"
	OriginLiteLLM  = "litellm"
	OriginBolt     = "bbolt"
)
View Source
const LiteLLMURL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"

Variables

This section is empty.

Functions

func BillingKey

func BillingKey(model, tier string) string

Types

type CompactPrice

type CompactPrice struct {
	InputCost             float64 `json:"input_cost_per_token,omitempty"`
	InputCostPriority     float64 `json:"input_cost_per_token_priority,omitempty"`
	InputCostFlex         float64 `json:"input_cost_per_token_flex,omitempty"`
	OutputCost            float64 `json:"output_cost_per_token,omitempty"`
	OutputCostPriority    float64 `json:"output_cost_per_token_priority,omitempty"`
	OutputCostFlex        float64 `json:"output_cost_per_token_flex,omitempty"`
	CacheReadCost         float64 `json:"cache_read_input_token_cost,omitempty"`
	CacheReadCostPriority float64 `json:"cache_read_input_token_cost_priority,omitempty"`
	CacheReadCostFlex     float64 `json:"cache_read_input_token_cost_flex,omitempty"`
}

func (CompactPrice) HasPricing

func (p CompactPrice) HasPricing() bool

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

func NewFetcher

func NewFetcher(source *Source, cfg FetcherConfig) *Fetcher

func (*Fetcher) Refresh

func (f *Fetcher) Refresh(ctx context.Context) error

func (*Fetcher) Run

func (f *Fetcher) Run(ctx context.Context)

func (*Fetcher) Status

func (f *Fetcher) Status() fetcherStatus

type FetcherConfig

type FetcherConfig struct {
	URL             string
	HTTPClient      *http.Client
	RefreshInterval time.Duration
	StartupDelay    time.Duration
	FetchTimeout    time.Duration
	Logger          *slog.Logger
}

type Service

type Service struct {
	Source  *Source
	Fetcher *Fetcher
}

func (*Service) CalculateTokens

func (s *Service) CalculateTokens(input, cached, output int64, model, tier string) (float64, bool)

func (*Service) Misses

func (s *Service) Misses() map[string]int64

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context) error

func (*Service) Status

func (s *Service) Status() StatusReport

type Snapshot

type Snapshot struct {
	Models    map[string]CompactPrice
	FetchedAt time.Time
	Origin    string
}

func LoadEmbedded

func LoadEmbedded() (*Snapshot, error)

type Source

type Source struct {
	// contains filtered or unexported fields
}

func NewSource

func NewSource(initial *Snapshot) *Source

func (*Source) Calculate

func (s *Source) Calculate(t Tokens, model, tier string) (cost float64, priced bool)

func (*Source) CalculateTokens

func (s *Source) CalculateTokens(input, cached, output int64, model, tier string) (cost float64, priced bool)

func (*Source) Lookup

func (s *Source) Lookup(model string) (CompactPrice, bool)

func (*Source) Misses

func (s *Source) Misses() map[string]int64

func (*Source) RecordMiss

func (s *Source) RecordMiss(billingKey string)

func (*Source) Replace

func (s *Source) Replace(snap *Snapshot)

func (*Source) Snapshot

func (s *Source) Snapshot() *Snapshot

type StatusReport

type StatusReport struct {
	Origin      string    `json:"origin"`
	ModelsCount int       `json:"models_count"`
	FetchedAt   time.Time `json:"fetched_at,omitzero"`
	URL         string    `json:"url,omitempty"`
	LastAttempt time.Time `json:"last_attempt_at,omitzero"`
	LastSuccess time.Time `json:"last_success_at,omitzero"`
	LastError   string    `json:"last_error,omitempty"`
}

type Tokens

type Tokens struct {
	Input  int64
	Cached int64
	Output int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL