pricing

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pricing applies Anthropic's published per-million-token rates to parsed usage events and returns costs in USD. Rates are snapshots of https://platform.claude.com/docs/en/about-claude/pricing as of 2026-04.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cost

func Cost(model string, u Usage) float64

Cost returns USD for a given model + usage. Unknown models return 0.

func Known

func Known(model string) bool

Known reports whether a model is priced in the table.

Types

type Bucket added in v0.8.2

type Bucket struct {
	Kind   string // "input" | "cache_write_5m" | "cache_write_1h" | "cache_read" | "output"
	Tokens int
	Rate   float64 // USD per 1M tokens
	Cost   float64 // USD
}

Bucket is one row of the 5-bucket cost breakdown.

func Breakdown added in v0.8.2

func Breakdown(model string, u Usage) []Bucket

Breakdown returns the 5-bucket cost split for a model+usage. If the model is unknown, it returns buckets with zero rate/cost but real token counts so the caller can still render volume information.

type Rate

type Rate struct {
	Input        float64
	CacheWrite5m float64
	CacheWrite1h float64
	CacheRead    float64
	Output       float64
}

Rate holds USD per 1M tokens for a model, across all billing categories.

func RateFor

func RateFor(model string) (Rate, bool)

RateFor resolves a model ID to its Rate, tolerating dated variants such as "claude-haiku-4-5-20251001" by stripping a trailing -YYYYMMDD suffix.

type Usage

type Usage struct {
	InputTokens           int
	CacheCreation5mTokens int
	CacheCreation1hTokens int
	CacheReadTokens       int
	OutputTokens          int
}

Usage is the per-request token breakdown used to compute cost.

Jump to

Keyboard shortcuts

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