Skip to content

Fill missing model limits from models.dev so discovery clients get per-model context windows - #53

Merged
jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
cheerc:models-dev-limits
Oct 7, 2026
Merged

jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
cheerc:models-dev-limits

Conversation

@cheerc

@cheerc cheerc commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

/v1/models only advertised context and token limits for models that OpenCode's capability catalog describes. Every other routable model returned no context_window, context_length, max_input or max_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.input and limit.output for 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: Price carries context_window, max_input and max_output; decodeModelsDev reads limit from models.dev.
  • internal/models/pricing.go: decodeModelsDev now merges every OpenCode provider instead of returning on the first one that has models. The primary opencode provider 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: MetadataForTier fills omitted limits from the pricing store. The store lock is taken after releasing the catalog lock, matching the existing lock order in MetadataSnapshot.
  • 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/models keeps 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 ./..., gofmt clean, go test ./... passing.
  • Against a live gateway: 77 of 79 exposed models already carried catalog limits, and the patched build fills the remaining ones. The three models configured in CLIProxyAPI for Pi now match the gateway response exactly on contextWindow and maxTokens, which is what made Pi report per-model limits instead of a constant.
  • End-to-end confirmed through CLIProxyAPI -> Pi.

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.json forces an immediate refetch.

Related

Issue #52 describes the report this fixes.

`/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.
@jasonxu114514
jasonxu114514 merged commit 2603eff into jasonxu114514:main Oct 7, 2026
jasonxu114514 added a commit that referenced this pull request Oct 7, 2026
保留 reasoning 配置,新增免费模型可用性探测 / 手动恢复、首 SSE 事件超时,元数据改用官方地址。按维护者要求,最终文件树排除测试文件。

验证:本地 Go 回归、go vet / build、Prettier、JS / shell 语法及独立实例管理端验收通过。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants