Skip to content

API Reference parrot.clients.budget

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

parrot.clients.budget

View source

Question token budget ledger and public feature entry point (FEAT-550, spec §2.2/§2.3/§3 M1).

Attribute AttemptStatus

Alias BudgetAccountingError

Re-exported from parrot.core.exceptions.BudgetAccountingError.

Alias BudgetError

Re-exported from parrot.core.exceptions.BudgetError.

Alias BudgetExhausted

Re-exported from parrot.core.exceptions.BudgetExhausted.

Alias BudgetMode

Re-exported from parrot.models.token_budget.BudgetMode.

Alias BudgetRegistryFull

Re-exported from parrot.core.exceptions.BudgetRegistryFull.

Alias BudgetReport

Re-exported from parrot.models.token_budget.BudgetReport.

Alias BudgetReservation

Re-exported from parrot.models.token_budget.BudgetReservation.

Alias BudgetResumeConflict

Re-exported from parrot.core.exceptions.BudgetResumeConflict.

Alias BudgetScopeConflict

Re-exported from parrot.core.exceptions.BudgetScopeConflict.

Alias BudgetSnapshot

Re-exported from parrot.models.token_budget.BudgetSnapshot.

Alias BudgetSnapshotInvalid

Re-exported from parrot.core.exceptions.BudgetSnapshotInvalid.

Alias BudgetStateMissing

Re-exported from parrot.core.exceptions.BudgetStateMissing.

Alias BudgetUnsupported

Re-exported from parrot.core.exceptions.BudgetUnsupported.

Alias BudgetUsage

Re-exported from parrot.models.token_budget.BudgetUsage.

Alias EstimateQuality

Re-exported from parrot.models.token_budget.EstimateQuality.

Alias OperationState

Re-exported from parrot.models.token_budget.OperationState.

Class QuestionBudget

Mutable ledger for one question on one event loop.

Parameter Type Default Description
policy TokenBudgetPolicy
operation_id str

Attributes:

Attribute Type Description
operation_id str
policy TokenBudgetPolicy
state OperationState
revision int
attempt_count int Total attempts recorded on this ledger, including a restored floor.
round_count int Distinct rounds observed on this ledger, including a restored floor.

Method QuestionBudget.reserve

Reserve I+O or raise typed denial; final requires the owner claim.

reserve(estimate: TokenEstimate, *, max_output_tokens: int, min_output_tokens: int, call_id: str, round_number: int, attempt_number: int, phase: ReservationPhase) -> BudgetReservation

Parameter Type Default Description
estimate TokenEstimate
max_output_tokens int
min_output_tokens int
call_id str
round_number int
attempt_number int
phase ReservationPhase

Returns: BudgetReservation

Method QuestionBudget.settle

Reconcile actual usage once; identical duplicate settlement is inert.

settle(reservation_id: str, usage: BudgetUsage) -> None

Parameter Type Default Description
reservation_id str
usage BudgetUsage

Method QuestionBudget.mark_uncertain

Retain the entire admitted debit when actual usage is unknown.

mark_uncertain(reservation_id: str, reason: str) -> None

Parameter Type Default Description
reservation_id str
reason str

Method QuestionBudget.release_unspent

Release only a request proven not to have been dispatched/consumed.

release_unspent(reservation_id: str) -> None

Parameter Type Default Description
reservation_id str

Method QuestionBudget.claim_finalization

Claim the one final attempt after draining; false if already claimed.

Spec §2.1: "Zero disables finalization" — a zero final_answer_reserve must refuse the claim outright, not merely rely on the remaining balance also happening to be zero (an ordinary round that underspends could otherwise still leave room for a closing attempt, contradicting the documented "zero disables" guarantee — code-reviewer finding, FEAT-550 wrap-up).

claim_finalization(owner_call_id: str) -> bool

Parameter Type Default Description
owner_call_id str

Returns: bool

Method QuestionBudget.report

Return an immutable consistent snapshot of current accounting.

report() -> BudgetReport

Returns: BudgetReport

Method QuestionBudget.close

Mark the operation closed (idempotent); late descendants can no longer spend.

close(*, terminal_reason: Optional[str] = None) -> None

Parameter Type Default Description
terminal_reason Optional[str] None

Method QuestionBudget.set_answer_complete

Record whether the terminal answer is complete (provider cutoff, parse failure, final tool call → False).

set_answer_complete(value: bool) -> None

Parameter Type Default Description
value bool

Method QuestionBudget.restore_settled

Seed a fresh ledger from a trusted snapshot (registry-only; spec §2.6).

restore_settled(*, input_tokens: int, output_tokens: int, revision: int, attempt_count: int, round_count: int) -> None

Parameter Type Default Description
input_tokens int
output_tokens int
revision int
attempt_count int
round_count int

Alias ReservationPhase

Re-exported from parrot.models.token_budget.ReservationPhase.

Alias TokenBudgetPolicy

Re-exported from parrot.models.token_budget.TokenBudgetPolicy.

Alias TokenEstimate

Re-exported from parrot.models.token_budget.TokenEstimate.

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