The budget estimate counts the part of the bill every request pays - #27
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.