Pricing
Token prices, for providers that report tokens but not cost (Codex). No prices are built in: they change, and subscription plans don’t bill per token anyway, so the caller supplies the rates it wants to budget by.
Since v0.1.0
Models
Section titled “Models”ModelPrice (interface)
Section titled “ModelPrice (interface)”USD per million tokens.
Signature
export interface ModelPrice { readonly input: number /** Defaults to `input` when omitted. */ readonly cachedInput?: number readonly output: number /** * Defaults to `output` when omitted; only used if the provider reports reasoning * separately from output. */ readonly reasoning?: number}Since v0.1.0
PriceTable (type alias)
Section titled “PriceTable (type alias)”Keyed by model id; "*" is the fallback.
Signature
type PriceTable = Readonly<Record<string, ModelPrice>>Since v0.1.0
costOf
Section titled “costOf”Cost in USD. inputTokens includes cached tokens (as both providers report
it), so cached tokens are billed at the cached rate and the rest at input.
Example
import { Pricing } from "@jpowersdev/effect-agent"import assert from "node:assert"
// USD per million tokensconst price: Pricing.ModelPrice = { input: 3, cachedInput: 0.25, output: 15,}
const cost = Pricing.costOf(price, { inputTokens: 1_000_000, // half of them cached cachedInputTokens: 500_000, outputTokens: 100_000, reasoningTokens: null,})assert.strictEqual(cost, 3.125)Signature
declare const costOf: (price: ModelPrice, usage: TokenUsage) => numberSince v0.1.0
priceFor
Section titled “priceFor”The price for model, falling back to the "*" entry.
Signature
declare const priceFor: ( table: PriceTable, model: string | null,) => ModelPrice | undefinedSince v0.1.0