Skip to content

The budget estimate counts the part of the bill every request pays - #27

Merged
AboveColin merged 1 commit into
feature/1.16from
budget-estimate
Sep 24, 2026
Merged

AboveColin merged 1 commit into
feature/1.16from
budget-estimate

Conversation

@AboveColin

Copy link
Copy Markdown
Owner

The daily budget check estimated a request from its size in bytes over one ratio, with no fixed part, and the ratio came from the last call alone. Measured on a development instance: a 138 byte action was estimated at 70 tokens and billed 278. After that small call, a 6 KB request was estimated at 14,327 tokens, while the same request was billed 3,277 one call earlier, so it was refused on every try.

The estimate is now 250 tokens plus the body over the ratio, times the margin. Only a call whose body was billed at least 250 tokens updates the ratio.

Live receipts after the change: small action, estimate 348 against a bill of 271. A 6 KB request, estimate 3,018 against 2,642. A synthetic worst case of 6,000 repeated bytes, estimate 2,927 against 3,274, which is 11% under.

Tests: test_the_cold_start_estimate_is_above_what_was_billed, test_one_measured_call_sets_the_estimate_for_the_next, test_a_small_call_leaves_the_ratio_alone.

Local gate: ruff, ruff format, mypy --strict, pytest (412 passed), config_flow 100%, mkdocs --strict, hassfest. EXIT 0.

A 138 byte action was estimated at 70 tokens and billed 278. The estimate
was bytes over a ratio, with no fixed part, and the ratio came from the
last call alone. After that small call, a 6 KB request was estimated at
14,327 tokens, billed 3,277 one call earlier, and refused on every try.

The estimate is now 250 tokens plus the body over the ratio, and only a
call whose body was billed at least 250 tokens updates the ratio.
@AboveColin
AboveColin merged commit f3b8ad0 into feature/1.16 Sep 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant