accounting

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package accounting contains pure usage and cost accounting helpers.

Package accounting Usage accounting price catalog and cost estimation.

Index

Constants

View Source
const (
	CostSourceProviderReported = "provider_reported"
	CostSourceEstimated        = "estimated"
	CostSourceUnavailable      = "unavailable"
)

Variables

This section is empty.

Functions

func SubMoneyChecked

func SubMoneyChecked(a, b int64) (int64, bool)

SubMoneyChecked subtracts non-negative money (nano) amounts without underflow. Also used for non-negative token residuals in DeriveTokenBreakdown.

Types

type CostInput

type CostInput struct {
	Backend      string
	Model        string
	Usage        TokenUsage
	ProviderCost ProviderCost
}

type CostResult

type CostResult struct {
	NanoUnits      int64
	Currency       string
	Source         string
	CatalogVersion string
	Unavailable    bool
}

func EstimateCost

func EstimateCost(in CostInput, catalog PriceCatalog) CostResult

type ModelPrice

type ModelPrice struct {
	InputPer1M           int64
	CachedInputPer1M     OptionalNanoRate
	CacheWriteInputPer1M OptionalNanoRate
	OutputPer1M          int64
	ReasoningOutputPer1M OptionalNanoRate
}

type ModelPriceConfig

type ModelPriceConfig struct {
	Backend              string
	Model                string
	InputPer1M           string
	CachedInputPer1M     string
	CacheWriteInputPer1M string
	OutputPer1M          string
	ReasoningOutputPer1M string
}

type OptionalNanoRate

type OptionalNanoRate = economics.NanoRate

OptionalNanoRate is a catalog rate that may be unspecified (absent) or explicitly present, including an authoritative zero. It aliases the public economics NanoRate contract so OSS catalog and injected raters share one shape.

type PriceCatalog

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

func NewPriceCatalog

func NewPriceCatalog(cfg PriceCatalogConfig) (PriceCatalog, error)

type PriceCatalogConfig

type PriceCatalogConfig struct {
	Version  string
	Currency string
	Models   []ModelPriceConfig
}

type ProviderCost

type ProviderCost struct {
	NanoUnits int64
	Currency  string
	Source    string
	Present   bool
}

ProviderCost is an optional authoritative provider-reported cost. Present distinguishes authoritative zero from an absent cost.

type TokenBreakdown

type TokenBreakdown struct {
	TokenUsage
	NonCachedInputTokens     int64
	NonReasoningOutputTokens int64
}

func DeriveTokenBreakdown

func DeriveTokenBreakdown(usage TokenUsage) TokenBreakdown

type TokenUsage

type TokenUsage struct {
	InputTokens      int64
	OutputTokens     int64
	CacheReadTokens  int64
	CacheWriteTokens int64
	ReasoningTokens  int64
}

Jump to

Keyboard shortcuts

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