cost

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cost computes actual and list-price equivalent USD costs for request log rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Providers func(ctx context.Context) ([]store.Provider, error)
	Billings  func(ctx context.Context) ([]store.Billing, error)
	Overrides func(ctx context.Context) ([]store.PriceOverride, error)
	Catalog   func() *prices.Catalog
	Since     time.Time
}

Deps supplies the read dependencies of a Pricer.

type EquivalentSource added in v0.10.0

type EquivalentSource interface {
	Equivalent(provider, model string) (prices.Price, bool)
}

EquivalentSource supplies a provider model's equivalent list price. ok=false falls back to the catalogue.

type Mode

type Mode string

Mode is a provider's billing mode.

const (
	ModeMetered      Mode = "metered"
	ModeSubscription Mode = "subscription"
	ModeFree         Mode = "free"
	ModeSurplus      Mode = "surplus"
)

Billing modes.

type Pricer

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

Pricer turns engine log rows into store.RequestCost records without locks or I/O on the hot path.

func New

func New(d Deps) *Pricer

New constructs a Pricer with an empty cached state until Refresh is called.

func (*Pricer) Equivalent

func (p *Pricer) Equivalent(provider, model string) (prices.Price, bool)

Equivalent resolves the list-price rates for a public provider and model, applying overrides, mode equivalent sources, and builtin type lookup.

func (*Pricer) Mode

func (p *Pricer) Mode(provider string) (Mode, *float64)

Mode returns the effective billing mode and optional monthly fee for provider.

func (*Pricer) Price

func (p *Pricer) Price(row bifrost.Log) store.RequestCost

Price computes the actual and equivalent USD costs and states for a terminal engine log row.

func (*Pricer) Refresh

func (p *Pricer) Refresh(ctx context.Context) error

Refresh reloads providers, billings, and price overrides and swaps them in atomically.

func (*Pricer) SetEquivalentSource added in v0.10.0

func (p *Pricer) SetEquivalentSource(m Mode, s EquivalentSource)

SetEquivalentSource registers or clears (when s is nil) a custom EquivalentSource for billing mode m.

func (*Pricer) SetSource

func (p *Pricer) SetSource(m Mode, s Source)

SetSource registers or clears (when s is nil) a custom actual-cost Source for billing mode m.

type Source

type Source interface {
	Actual(row bifrost.Log) (usd float64, ok bool)
}

Source reads a provider's real charge for one row. ok=false means the charge is not known (yet): the row stays unpriced.

type State

type State string

State describes how a request's cost was determined.

const (
	StateExact     State = "exact"
	StateEstimated State = "estimated"
	StateUnpriced  State = "unpriced"
)

Cost states.

Jump to

Keyboard shortcuts

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