pricing

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package pricing provides a pricing manager for the framework.

Index

Constants

View Source
const (
	DefaultPricingSyncInterval = 24 * time.Hour
	LastPricingSyncKey         = "LastModelPricingSync"
	DefaultPricingURL          = "https://getbifrost.ai/datasheet"
	TokenTierAbove128K         = 128000
)

Default sync interval and config key

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.1.8

type Config struct {
	PricingURL          *string        `json:"pricing_url,omitempty"`
	PricingSyncInterval *time.Duration `json:"pricing_sync_interval,omitempty"`
}

Config is the pricing manager configuration.

type PricingData

type PricingData map[string]PricingEntry

PricingData represents the structure of the pricing.json file

type PricingEntry

type PricingEntry struct {
	// Basic pricing
	InputCostPerToken  float64 `json:"input_cost_per_token"`
	OutputCostPerToken float64 `json:"output_cost_per_token"`
	Provider           string  `json:"provider"`
	Mode               string  `json:"mode"`

	// Additional pricing for media
	InputCostPerImage          *float64 `json:"input_cost_per_image,omitempty"`
	InputCostPerVideoPerSecond *float64 `json:"input_cost_per_video_per_second,omitempty"`
	InputCostPerAudioPerSecond *float64 `json:"input_cost_per_audio_per_second,omitempty"`

	// Character-based pricing
	InputCostPerCharacter  *float64 `json:"input_cost_per_character,omitempty"`
	OutputCostPerCharacter *float64 `json:"output_cost_per_character,omitempty"`

	// Pricing above 128k tokens
	InputCostPerTokenAbove128kTokens          *float64 `json:"input_cost_per_token_above_128k_tokens,omitempty"`
	InputCostPerCharacterAbove128kTokens      *float64 `json:"input_cost_per_character_above_128k_tokens,omitempty"`
	InputCostPerImageAbove128kTokens          *float64 `json:"input_cost_per_image_above_128k_tokens,omitempty"`
	InputCostPerVideoPerSecondAbove128kTokens *float64 `json:"input_cost_per_video_per_second_above_128k_tokens,omitempty"`
	InputCostPerAudioPerSecondAbove128kTokens *float64 `json:"input_cost_per_audio_per_second_above_128k_tokens,omitempty"`
	OutputCostPerTokenAbove128kTokens         *float64 `json:"output_cost_per_token_above_128k_tokens,omitempty"`
	OutputCostPerCharacterAbove128kTokens     *float64 `json:"output_cost_per_character_above_128k_tokens,omitempty"`

	// Cache and batch pricing
	CacheReadInputTokenCost   *float64 `json:"cache_read_input_token_cost,omitempty"`
	InputCostPerTokenBatches  *float64 `json:"input_cost_per_token_batches,omitempty"`
	OutputCostPerTokenBatches *float64 `json:"output_cost_per_token_batches,omitempty"`
}

PricingEntry represents a single model's pricing information

type PricingManager

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

PricingManager is the pricing manager for the framework.

func Init

func Init(ctx context.Context, config *Config, configStore configstore.ConfigStore, logger schemas.Logger) (*PricingManager, error)

Init initializes the pricing manager

func (*PricingManager) CalculateCost

func (pm *PricingManager) CalculateCost(result *schemas.BifrostResponse) float64

CalculateCost calculates the cost of a Bifrost response

func (*PricingManager) CalculateCostFromUsage

func (pm *PricingManager) CalculateCostFromUsage(provider string, model string, usage *schemas.BifrostLLMUsage, requestType schemas.RequestType, isCacheRead bool, isBatch bool, audioSeconds *int, audioTokenDetails *schemas.TranscriptionUsageInputTokenDetails) float64

CalculateCostFromUsage calculates cost in dollars using pricing manager and usage data with conditional pricing

func (*PricingManager) CalculateCostWithCacheDebug added in v1.0.11

func (pm *PricingManager) CalculateCostWithCacheDebug(result *schemas.BifrostResponse) float64

CalculateCostWithCacheDebug calculates the cost of a Bifrost response with cache debug information

func (*PricingManager) Cleanup

func (pm *PricingManager) Cleanup() error

func (*PricingManager) GetModelsForProvider added in v1.1.0

func (pm *PricingManager) GetModelsForProvider(provider schemas.ModelProvider) []string

GetModelsForProvider returns all available models for a given provider (thread-safe)

func (*PricingManager) GetProvidersForModel added in v1.1.0

func (pm *PricingManager) GetProvidersForModel(model string) []schemas.ModelProvider

GetProvidersForModel returns all providers for a given model (thread-safe)

func (*PricingManager) Reload added in v1.1.8

func (pm *PricingManager) Reload(ctx context.Context, config *Config) error

Reload reloads the pricing manager from config

Jump to

Keyboard shortcuts

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