Repository navigation
Fill missing model limits from models.dev so discovery clients get per-model context windows - #53
Merged
Conversation
`/v1/models` only advertised context and token limits for models that OpenCode's capability catalog describes. Everything else fell back to the defaults a discovery client hardcodes (128k context / 16k output), which made every such model look identically small to CLIProxyAPI and Pi. models.dev already publishes `limit.context`, `limit.input` and `limit.output` for the OpenCode providers, and the gateway already fetched that file for pricing and deprecation only. Store those limits in the metadata cache and fill the fields the capability catalog omitted. The capability catalog stays authoritative: capability flags always come from it, and a limit it published is never overwritten. This also merges the other OpenCode provider tiers instead of returning the first provider alone, so models that only one tier describes keep their cost, anonymous eligibility and limits. Clients holding a metadata cache written by an earlier build keep their old data until the next refresh; deleting config.json.models.dev.json forces an immediate refetch.
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.
Summary
/v1/modelsonly advertised context and token limits for models that OpenCode's capability catalog describes. Every other routable model returned nocontext_window,context_length,max_inputormax_output, so discovery clients such as CLIProxyAPI and Pi fell back to their own defaults (128k context / 16k output) and every such model looked identically small.models.dev already publishes
limit.context,limit.inputandlimit.outputfor the OpenCode providers, and the gateway already downloads that file for pricing and deprecation. This PR stores those limits in the metadata cache and uses them to fill the fields the capability catalog omitted.The capability catalog stays authoritative: capability flags always come from it, and a limit it published is never overwritten.
Changes
internal/models/pricing.go:Pricecarriescontext_window,max_inputandmax_output;decodeModelsDevreadslimitfrom models.dev.internal/models/pricing.go:decodeModelsDevnow merges every OpenCode provider instead of returning on the first one that has models. The primaryopencodeprovider still wins for duplicated model IDs, so models that only another tier (opencode-go) describes now keep their cost, anonymous eligibility and limits.internal/models/catalog.go:MetadataForTierfills omitted limits from the pricing store. The store lock is taken after releasing the catalog lock, matching the existing lock order inMetadataSnapshot.internal/models/pricing_test.go: covers provider merging, limit parsing and the catalog-wins fallback.README.md: documents the metadata sources and the fields exposed on/v1/models.Behaviour
GET /v1/modelskeeps reporting the capability catalog values when it has them, and fills the rest from models.dev. Capability flags are unaffected; routing is untouched, since metadata is additive for discovery clients only.Verification
go build ./...,go vet ./...,gofmtclean,go test ./...passing.contextWindowandmaxTokens, which is what made Pi report per-model limits instead of a constant.Compatibility note
A metadata cache written by an earlier build has no limit fields, so those models keep their previous values until the next refresh. Deleting
config.json.models.dev.jsonforces an immediate refetch.Related
Issue #52 describes the report this fixes.