Repository navigation
feat(routing): honor lynkr-* tier ids on the OpenAI-compatible endpoints - #139
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The virtual tier ids lynkr-auto / lynkr-simple / lynkr-medium /
lynkr-complex / lynkr-reasoning (src/routing/model-slots.js) pinned their
tier only on the Anthropic /v1/messages route, even though the opencode
docs promise they "work from any client". /v1/chat/completions and
/v1/responses never go through router.js's pin code and only knew Codex's
(model, reasoning.effort) mapping, so a Codex CLI, Cline, Continue or Kilo
user who set `model = "lynkr-reasoning"` silently got content scoring
instead of the tier they asked for. Worse, `lynkr-auto` from Codex was
pinned by whatever effort Codex attached (it sends one on every request),
so "auto" never meant auto there.
Add resolveOpenAIRequestPin() to src/routing/openai-model-slots.js and
use it from both OpenAI handlers:
1. A virtual tier id in `model` (case-insensitive, same table as the
Anthropic route) pins its tier with method `model_id_pin`, the label
router.js already uses, and outranks the effort mapping.
`lynkr-auto` is an explicit no-pin and skips the effort mapping.
2. Anything else keeps the existing (model, effort) mapping, still
labelled `openai_model_effort_pin`.
The pinned tier rides the same _forceProvider/_tierModel plumbing as
before, so downstream behavior (telemetry, headers, badge) is unchanged.
Docs: new documentation/model-switching.md answers the questions from
issue Fast-Editor#32 in one place: how to pick a tier from Claude Code, opencode,
Codex and OpenAI-compatible clients; how to see which model served a
request (status line, LYNKR_VISIBLE_ROUTING badge, X-Lynkr-* headers,
dashboard, `lynkr route --preview`); how to change the rules (hot-reloaded
TIER_* in .env, force patterns); and how to give each CLI its own model.
tier-pinning.md documents the virtual ids as a third mechanism,
codex-cli.md gains a "Pinning a Routing Tier" section, and the FAQ and
documentation index link the new guide.
Tests: test/openai-virtual-tier-pin.test.js covers the resolver
(precedence, case-insensitivity, lynkr-auto suppressing the effort pin,
unchanged effort mapping, junk input) and drives both endpoints end to
end through the real Express app with a mocked orchestrator, asserting
the pinned tier's provider/model reach the orchestrator. The four
end-to-end pin cases fail without the router change.
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s). |
This branch has not been deployed
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.
Description
Fixes #32
#32 asks how to switch model from a client, how to tell which model answered, how to change the switching rules, and how to give each CLI its own model (for example Ollama in Claude Code and GLM in opencode). Lynkr already has the pieces for most of this, but they were spread across several docs, and one of them didn't work on half of the endpoints.
The
lynkr-auto/lynkr-simple/lynkr-medium/lynkr-complex/lynkr-reasoningids (src/routing/model-slots.js) pin a tier on/v1/messages, anddocumentation/opencode.mdsays they "work from any client". The OpenAI-format handlers (/v1/chat/completions,/v1/responses) never go throughrouter.js's pin code, though. They only know Codex's(model, reasoning.effort)mapping. So:model = "lynkr-reasoning"got content scoring instead of the tier they asked for;lynkr-autofrom Codex was pinned by whatever effort Codex sends (it sends one on every request), so "auto" never meant auto there.This PR makes the ids work on the OpenAI endpoints too, and adds one guide that answers the four questions in the issue.
Type of Change
Changes Made
src/routing/openai-model-slots.js: newresolveOpenAIRequestPin(model, effort)returning{ tier, method }ornull:model(case-insensitive, same table as the Anthropic route) pins its tier with methodmodel_id_pin, the labelrouter.jsalready uses. It also takes precedence over the effort mapping.lynkr-automeans no pin and skips the effort mapping.(model, effort)mapping, still labelledopenai_model_effort_pin.src/api/openai-router.js: both/chat/completionsand/responsescall the new resolver. The pinned tier still goes through the existing_forceProvider/_tierModel/_tierName/_forcedMethodfields, so telemetry, headers and the badge work as before.documentation/model-switching.md(new): answers the four questions in Switching not clear! #32. It covers picking a tier from Claude Code, opencode, Codex and OpenAI-compatible clients; seeing which model served a request (lynkr-statusline, theLYNKR_VISIBLE_ROUTINGbadge,X-Lynkr-*headers,/dashboard,lynkr route --preview); changing the rules (TIER_*in.env, reloaded on save; force patterns); and giving each CLI its own model, with the limits of that approach.documentation/tier-pinning.md: the virtual ids are documented as a third mechanism next to Claude Desktop slots and the Codex effort mapping.documentation/codex-cli.md: new "Pinning a Routing Tier" section (model = "lynkr-…"/codex -m).documentation/faq.md,documentation/README.md: short FAQ entry and index link to the new guide.test/openai-virtual-tier-pin.test.js(added totest:unit).Testing
test/openai-virtual-tier-pin.test.jshas 13 tests:lynkr-autosuppressing the effort pin, the effort mapping unchanged for real model ids, and junk input.openai-ingress-tool-injection.test.js. These assert the pinned tier's provider and model reach the orchestrator. The four end-to-end pin cases fail without the router change.I ran the full
test:unitlist on this branch and onmain. Failures are identical on both: all of them come frombetter-sqlite3not being built in my local install. The 13 new tests all pass.eslint src index.js --max-warnings 0is clean.Manual check: I ran Lynkr against a local mock OpenAI-compatible upstream, with each tier set to
openai:mock-<tier>:/v1/chat/completionswithlynkr-reasoningreached the upstream asmock-reasoning.lynkr-simple+reasoning_effort: "high"reached it asmock-simple./v1/responseswithlynkr-medium+ efforthighreached it asmock-medium.lynkr-auto+ efforthighwas content-routed (SIMPLE for "hi"). Before this change it was pinned to REASONING.gpt-5.6-sol+highstill pins REASONING.The badge and the headers described in the guide were checked on the same server.
Checklist