Repository navigation
Fix: Parse and price OpenCode Zen's endpoints - #1247
Conversation
Zen serves its Claude models, and most of its Qwen ones, on /zen/v1/messages, and OpenCode's Go plan mounts both of Zen's endpoints under /zen/go. Those paths fell to the parser's default arm, so a request recorded no model, no tokens and no cost. One predicate now names every Anthropic-dialect path, for the request and every response-side call site alike. Part of rossoctl#941. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
A call to one of Zen's free models was reported unpriced: Cortex ships only Anthropic's rates, and config cannot say zero, because a rate of 0 leaves its tier unset. A hand-kept pair of rows beside the generated table now prices Zen's "-free" models and big-pickle at zero, on opencode.ai only, so the call is a priced zero. bundled: false drops them with the rest of the shipped table. The OpenCode page and the pricing doc say which Zen endpoints are parsed and how each is priced. Part of rossoctl#941. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
agentop pricing rendered the zero-rate rows as "-", which reads as a coverage gap, because a zero rate is omitted on the wire like an unset tier. Describe and EffectiveFor now mark a row that prices every tier it sets at zero as free, and agentop renders it so. EffectiveFor also stops listing a shipped row scoped to another endpoint, so api.anthropic.com's view no longer shows *-free and big-pickle as UNPRICED. Configured rows for other hosts are still listed, as before. The Zen request test now carries fields only its own dialect reads, so a path routed to the wrong parser fails it. The buffered OnResponse path and the whole-stream terminal frame get Zen tests too. Docs: a configured catch-all for opencode.ai outranks the shipped zero, a zero still needs token counts, and a free call's cost cells are blank. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 25 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (12)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mrsabath
left a comment
There was a problem hiding this comment.
Review
Checked out the PR head and exercised every behavioral claim against the real API rather than reading the description.
Pricing — all six claims hold exactly
| Claim | Measured |
|---|---|
Zen -free + big-pickle are a priced zero |
prov=bundled, free=true, all four tiers set to 0 |
A -free model on another host stays unpriced |
api.anthropic.com / api.openai.com / example.com → prov=none |
| Non-free Zen models unaffected | claude-sonnet-4-6 on Zen prices normally; qwen3-coder, free, freely → unpriced |
| Configured catch-all outranks the zero | * for opencode.ai → prov=configured, input 3e-06 |
bundled: false drops the rows |
→ prov=none |
| Host view no longer shows Zen rows elsewhere | api.anthropic.com lists 0 Zen rows; opencode.ai lists both |
Parsing — routing is exact-match, confirmed per path
Each test body carries only its own dialect's fields (Anthropic input_schema vs OpenAI function.parameters), so a tools=1 result proves the correct parser ran:
/zen/v1/messages,/zen/go/v1/messages,/v1/messages→ Anthropic/zen/v1/chat/completions,/zen/go/v1/chat/completions→ OpenAI/zen/v1/responses,/zen/v1/models/<id>→ unparsed, asdocs/agents/opencode.mdstates- Near-misses (
/zen/go/go/v1/messages,/zen/v1/messages/extra) → unparsed, no leakage into the wrong parser
"Each test fails with its fix reverted"
Reverted both fixes independently and confirmed:
- Dropping the Zen paths from
isAnthropicMessagesPathfails all four response arms (buffered JSON, SSE, streamed frames, whole-stream terminal frame), each showing the exacttokens = 0/0symptom the PR describes. - Commenting out
bundledFreeRates()fails all three pricing tests.
go test -race ./cost/... ./plugins/inferenceparser/... clean, agentop pricing tests pass, gofmt -l . clean.
Two things worth noting
The host-scoping filter is the change with the widest reach, and it is correctly contained. if r.prov == ProvBundled && !matchHost(r.host, host) applies to every bundled row, not only Zen's, so I measured the blast radius rather than assuming it. The LiteLLM table ships all 33 rows under host "*", which matchHost treats as any-endpoint, so only Zen's 2 scoped rows are ever filtered. Every host view still shows 33 models, and api.anthropic.com went from 2 unpriced rows to 0 — no view loses anything it previously had.
Host matching has no suffix bleed. Since the zero rate is scoped by host, that scoping is worth probing: opencode.ai:443 and OPENCODE.AI match (port-stripped, case-insensitive), while api.opencode.ai, evil-opencode.ai and opencode.ai.attacker.com do not. A hostile lookalike cannot claim free pricing.
The Rates{Set: [...]bool{...}} construction is the right mechanism — it is the only way to express a genuine zero given that config leaves a 0 tier unset and rejects an all-zero entry, and the comment says exactly that. Keeping these rows in bundled_free.go rather than bundled.go, so make pricing-table cannot clobber them, is the same reasoning as bundledMultipliers and consistent with it.
Verdict
No must-fix, no suggestions, no nits. I went looking for scope leakage in the host filter and for suffix-matching weaknesses in the free rule, and found neither.
Replacing four scattered == anthropicMessagesPath comparisons with one predicate is the part that will keep paying off: it makes it structurally impossible for a path to be read as Anthropic on the way out and OpenAI on the way back, which is the bug class this PR is fixing.
LGTM.
OpenCode Zen serves each model on the endpoint of the SDK it speaks, and Cortex parsed only one of them. Calls on the others recorded no model, no tokens and no cost. Zen's free models were also reported as unpriced, which asks the operator for a rate that does not exist.
Parsing
/zen/v1/messagesand/zen/go/v1/messages(Claude and most Qwen models) now go to the Anthropic Messages parser. That covers the request, the buffered response, the streamed frames, and a whole SSE body delivered as one terminal frame./zen/go/v1/chat/completions(the Go plan's OpenAI-dialect endpoint) joins/zen/v1/chat/completionson the OpenAI parser./zen/v1/responses(GPT, Grok) and Gemini's/zen/v1/models/<id>remain unparsed. They need parsers Cortex does not have.docs/agents/opencode.mdsays so.Pricing
opencode.ai. These are every model whose id ends in-free, plusbig-pickle. A call to one is a priced zero and counts toward coverage.core/cost/pricing/bundled_free.go, beside the generated LiteLLM table rather than in it, like the shipped gateway discount. They ship because config cannot express zero: a tier with a rate of 0 is left unset, and an entry whose every rate is 0 fails at startup.bundled: falsedrops them.-freemodel on any other endpoint stays unpriced.agentop pricingshows these rows asfreerather than-, which reads as a missing rate./pricingresponses gain an omitemptyfreefield for this.--host api.anthropic.comstops showing Zen's free models as UNPRICED. Configured rows for other hosts are still listed.docs/pricing.mdcovers what operators should know:opencode.aireplaces the zero, so name Zen's paid models instead;Testing
OnResponsearms, streamed frames, and the whole-stream terminal frame. The request bodies carry fields only their own dialect reads, so a path sent to the wrong parser fails.bundled: false, thefreeflag, host-view scoping, and a configured catch-all outranking the zero.corepassesgo test -race ./.... agentop's tests pass, andcmd/cortexbuilds, vets and tests with thefullandlocalprofiles. gofmt andgo mod tidy -diffare clean.Assisted-By: Claude (Anthropic AI) [email protected]