Repository navigation
Read context windows and effort levels from gateways like OpenCode - #6
Merged
Merged
Conversation
OpenCode nests a model's limits and prices and lists the reasoning
levels it takes:
limit.context 1000000
cost.text.{input,output}.price 0.30 / 1.20
capabilities.reasoning.effort [low, high, max]
Only OpenRouter's flat context_length and string prices were read, so
through OpenCode every model came back with a context window of zero.
Compaction is gated on window > 0, so it never ran and a session grew
until the API refused it; the picker showed no price for the same
reason.
Effort had the mirror problem: max was lowered to high by the protocol
ceiling, again by openaiEffort, so a model that publishes max never got
it. When a provider lists a model's levels, that list is now used
instead of the protocol guess, and the UI clamps against the same list.
The list is carried to the picker on ModelInfo, so what it says a model
takes is what gets sent.
Verified against a live /models reply: 78 of 78 models now report a
window, and DeepSeek V4.1 Flash parses as 1000000 tokens at 0.30/1.20
with [low high max].
stawan15
force-pushed
the
fix/gateway-context-and-effort
branch
from
November 1, 2026 05:16
f338ecc to
18b5a91
Compare
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.
Two bugs that bite hardest through OpenCode, and both confirmed against a live
/modelsreply.1. Every model reported a context window of zero
OpenCode nests its metadata; OpenRouter is flat:
context_lengthlimit.contextpricing.prompt(string)cost.text.input.pricecapabilities.reasoning.effortOnly the first shape was parsed.
contextLimit()returned 0, and auto-compaction is gated onwindow > 0(engine.go:864), so compaction never ran and a long session kept growing until the API refused it. Prices were blank in the picker for the same reason.2.
maxeffort never reached a model that takes itCapped three times over: the protocol ceiling (
protocolEffort), the request builder (openaiEffortmappedmax→high), and the picker. DeepSeek publishes[low, high, max]and gothighevery time.Now, when a provider lists a model's levels, that list wins over the protocol guess — in the engine and in the UI, so what the picker shows is what is sent. A level the model doesn't list drops to the highest one it does that is still below what was asked (
xhigh→high, notmax, sincemaxranks higher).Verified against the real endpoint rather than only mocks — 78 of 78 models parse a window now, and DeepSeek V4.1 Flash reads as 1,000,000 tokens,
$0.30/$1.20,[low high max].New tests in
gateway_test.go: the nested-payload parse, the effort-list clamping (including fallback to the protocol when no list is published), and that the window actually reachescontextLimit, which is what gates compaction.Verified:
go vet,go test ./...,go test -race ./...,gofmt -l(clean),staticcheck@v0.8.2(clean).