Skip to content

API Reference parrot.observability.cost

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.observability.cost

View source

parrot.observability.cost — USD cost calculation for LLM calls.

Namespace package. Concrete calculator lives in:

  • calculator — CostCalculator (TASK-1232)
  • pricing/ — bundled JSON pricing tables (TASK-1232)

Alias AfterClientCallEvent

Re-exported from parrot.core.events.lifecycle.events.AfterClientCallEvent.

Alias CostCalculator

Re-exported from parrot.observability.cost.calculator.CostCalculator.

Function backfill_estimated_cost

Copy the last call's cost into message.usage.estimated_cost when that is still None.

Never raises: telemetry must not break the response path.

backfill_estimated_cost(message: Any) -> None

Parameter Type Default Description
message Any

Function ensure_shared_cost_calculator

Return the shared calculator, building one from PARROT_PRICING_PATH if none is installed.

ensure_shared_cost_calculator() -> 'CostCalculator'

Returns: 'CostCalculator'

Function get_shared_cost_calculator

Return the process-wide CostCalculator installed by observability bootstrap, or None.

get_shared_cost_calculator() -> 'Optional[CostCalculator]'

Returns: 'Optional[CostCalculator]'

Attribute last_call_cost

Type: ContextVar[Optional[float]]

Attribute logger

Function resolve_event_cost

Return the call's USD cost, computing it only when the origin did not.

event.cost_usd wins when not None. Otherwise compute with the shared calculator, else fallback (emitters that bypass AbstractClient, or tests that inject a calculator). Never raises.

resolve_event_cost(event: 'AfterClientCallEvent', fallback: 'Optional[CostCalculator]') -> Optional[float]

Parameter Type Default Description
event 'AfterClientCallEvent'
fallback 'Optional[CostCalculator]'

Returns: Optional[float]

Function set_shared_cost_calculator

Install (or clear with None) the process-wide CostCalculator.

set_shared_cost_calculator(calc: 'Optional[CostCalculator]') -> None

Parameter Type Default Description
calc 'Optional[CostCalculator]'

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally