cost

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package cost holds the per-model token-pricing table used to annotate generation outputs with `_tokens` / `_model` / `_cost_usd`.

It lives in its own leaf package so that both `model/` (claw backend) and `delegate/` (claude_code, codex backends) can call `Annotate` without creating an import cycle (`model/` already depends on `delegate/`).

Pricing resolution order (first match wins):

  1. claw-code-go's live registry cache (refreshed async every 24h from OpenRouter). Picks up new models without iterion-side updates — the long-term path that eliminates the static-table maintenance burden.
  2. The static modelPriceTable below. Acts as the offline fallback for cold starts (no cache file yet) and as a last-known-good for models the live source has not yet published.

Operators can opt out of step 1 with CLAW_DISABLE_LIVE_REGISTRY=1 (typically in air-gapped environments); the static table then serves every lookup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotate

func Annotate(output map[string]interface{}, model string, inputTokens, outputTokens int) (totalTokens int)

Annotate writes the conventional `_tokens` / `_model` / `_cost_usd` keys onto a generation output. Cost is omitted when the model is unknown to the price table, so observers can distinguish "no cost data" from "$0". A nil output map is a no-op (returns 0).

func EstimateUSD

func EstimateUSD(model string, inputTokens, outputTokens int) float64

EstimateUSD returns a rough cost estimate for the given token usage on the named model. Returns 0 when the model is not in the price table — callers should treat 0 as "unknown" and skip emission.

The model parameter accepts both bare IDs ("claude-sonnet-4-6") and fully qualified specs ("anthropic/claude-sonnet-4-6"); only the trailing path component is consulted. This means a region- or tenant-prefixed spec like "anthropic/eu/claude-sonnet-4-6" still resolves to "claude-sonnet-4-6" — intentional, since pricing is the same across regions for the providers we track.

Types

This section is empty.

Jump to

Keyboard shortcuts

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