Repository navigation
fix(chat): reserve at the long-context step for huge prompts - #165
Merged
Merged
Conversation
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.
estimateChatCost reserved at base rates for every prompt size. Past a model's
pricing.long_contextthreshold, the gateway reprices the whole request, so a huge prompt under-reserved. Examples: gpt-6-astra over 272K reserved $10/$50 against a $20/$75 quote, and Grok from 200K reserved half the quote.LONG_CONTEXT_PRICE_PER_MTOKENcopies the live steps from GET /v1/models (both chains agree; the Qwen steps are Base-only). That covers GPT-6, GPT-5.4/5.5/5.6 (>272K, 2x in / 1.5x out), Gemini 3.1/2.5 Pro (>200K, 2x/1.5x), Grok 4.3–4.7 and build-0.1 (>=200K, 2x/2x), and Qwen 3.7 plus/flash (inclusive; flash steps twice).chatRateAt/tierWorstPriceAtpick the highest step reached, using the gateway's own inclusive/exclusive rule. They are pure in prompt tokens and never lower the base rate. They are used byestimateChatCostfor both an explicit model and a mode, and byaccountLedgerUsd.verify:pricesnow fails when a live step would settle above the reserve. A control run with the astra step removed and grok made exclusive flagged both models on both chains.Refs BlockRunAI/blockrun#781