Repository navigation
fix: book $0 for paid calls the gateway served without settling - #94
Merged
Merged
Conversation
The gateways now answer some paid requests without settling and say so on the 200: X-Settlement-Skipped (empty-result on an empty sol pm result, unexecuted on an unexecuted sol rpc call, free-fallback on a chat free fallback) or X-Payment-Waived (sol and base pm routes). The SDK ignored both and booked the full quote, so get_spending(), the max_session_cost budget, _last_call_cost, the cost log and the tx log overstated spend. Add tx_log.settlement_skipped(headers) (case-insensitive) and booked_cost_usd(headers, cost), and route every booking site through them: EVM sync/async chat, chat stream, raw POST and raw GET; Solana sync/async chat, chat stream, raw POST, raw GET, inline image, settle-at-submit image and video completion poll. X-Payment-Settled: false alone still books the quote: settlement had not landed yet, the call is still owed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
VickyXAI
added a commit
that referenced
this pull request
Oct 27, 2026
A paid call the gateway served without settling (X-Settlement-Skipped, X-Payment-Waived) now books $0 (#94). Co-authored-by: 1bcMax <viewitter@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
The gateways now serve some paid requests without settling them and say so on the 200:
/api/v1/pm/markets/searchempty result:X-Payment-Waived: empty-result,X-Payment-Settled: false,X-Settlement-Skipped: empty-result, noPAYMENT-RESPONSE./api/v1/rpc/*unexecuted JSON-RPC:X-Payment-Settled: false,X-Settlement-Skipped: unexecuted.X-Settlement-Skipped: free-fallback.X-Payment-Waived: empty-result.The SDK recognised none of these. Every paid retry booked the full quote, so
get_spending(), themax_session_costbudget,_last_call_cost, the cost log (save_to_cache) and the tx log overstated spend for calls that moved no money. A skipped call could even push a later real call over the session limit.Change
blockrun_llm/tx_log.py:settlement_skipped(headers) -> boolreturns True whenX-Settlement-Skippedis present with a non-empty value, orX-Payment-Waivedis present. Lookup is case-insensitive overhttpx.Headersor a plain dict, and it never raises.booked_cost_usd(headers, cost)returns 0.0 when skipped, otherwisecost.X-Payment-Settled: falsealone is not a skip marker. It means settlement had not landed yet and the call is still owed, so it keeps booking the full quote._last_call_cost,save_to_cachecost and_log_transactioncost all come from the gated value:client.py(Base/EVM):_booked_cost/_book_paid_calltakeskipped=. When skipped they return(0.0, "settlement_skipped")and release an upto hold, because that permit will never settle. The sites are sync chat stream, sync chat, sync raw POST, sync raw GET, async chat stream, async chat, async raw POST and async raw GET.solana_client.py: the sites are sync and async chat stream, chat, raw POST, raw GET, inline image (200), settle-at-submit image (202, gated on the submit response) and video completion poll (gated on the completed poll).PAYMENT-RESPONSEdoes not raise or warn. The tests assert no warnings and empty stderr.## Unreleasedentry, following the repo's convention.Tests
tests/unit/test_settlement_skipped.pyhas 81 tests:X-Payment-Settled: falsealone,Noneinput and a broken mapping.X-Payment-Settled: falsealone → full $1 booked. Normal paid → full $1 booked. Each test asserts the session total,_last_call_cost, thesave_to_cachecost and the_log_transactioncost. Sync sites also checkget_spending()and chat checksresp.cost_usd.max_session_cost=1.5. A fourth call is refused.Results
client.py,solana_client.pyandcache.pyand confirmed by grep that 0 references to the helper were left. 24 failed, 57 passed: every site'sskippedcase plus both spend-limit tests. The tests that still passed are the helper tests and the control cases, which should behave the same before and after the fix. After restoring the files, 81 passed andgit diffshowed only the intended changes.pytest tests/unit: 1423 passed.black --check .: 107 files unchanged.ruff check .: all checks passed.node scripts/sync-brand-numbers.mjs --check: up to date.mypy blockrun_llm(not in CI): 247 errors on bothmainand this branch, so none are new.llama_index.coreis not installed in this env. CI installs it.🤖 Generated with Claude Code