fix: resolve translated model name against live Copilot catalog#41
Open
clairewangjia wants to merge 1 commit into
Open
fix: resolve translated model name against live Copilot catalog#41clairewangjia wants to merge 1 commit into
clairewangjia wants to merge 1 commit into
Conversation
The Copilot models endpoint sometimes exposes 1m/preview variants
under an `-internal` suffix (observed today: `claude-opus-4.7-1m-internal`,
no plain `claude-opus-4.7-1m`). `translateModelName` always emits the
plain form, so requests with `anthropic-beta: context-1m-*` against
opus-4.7 are rejected upstream with:
400 {"code":"model_not_supported", ...}
This adds `resolveAgainstCatalog(name, catalogIds)`: if the translated
name is missing from the live `/v1/models` catalog but the `-internal`
variant exists, use the variant. Catalog passed through `preprocessPayload`
(defaults to `[]`, preserving prior behaviour for any caller that doesn't
opt in). `routes/messages/handler.ts` threads `state.models.data` in and
also overrides `openAIPayload.model` on the translated-Copilot path so
the resolved id is what actually goes on the wire.
When the catalog already contains the plain id (the common case for
accounts where Copilot exposes the model directly), behaviour is
unchanged — the resolver short-circuits on exact match.
Tests: 5 new cases on `resolveAgainstCatalog` + 2 on `preprocessPayload`
threading. All existing tests still pass.
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
The Copilot
/v1/modelsendpoint sometimes exposes 1M / preview variants under an-internalsuffix.Concrete case I hit today on a Microsoft Copilot account:
claude-opus-4.7-1m-internalclaude-opus-4.7-1mtranslateModelName(\"claude-opus-4-7\", \"context-1m-2025-08-07\")always emitsclaude-opus-4.7-1m, so the request is rejected upstream:```
400 {"error":{"message":"The requested model is not supported.","code":"model_not_supported",...}}
```
Fix
New pure helper
resolveAgainstCatalog(name, catalogIds):catalogIdsis empty → returnname(back-compat for callers that don't pass catalog)nameis in catalog → returnname(the common case — no behaviour change for accounts where Copilot exposes the plain id)${name}-internalis in catalog → return thatname(let upstream reject as before, so we don't mask other errors)Threaded through:
preprocessPayload(..., catalogIds = [])— new optional 3rd arg, defaults to[]routes/messages/handler.ts— passesstate.models?.data?.map(m => m.id) ?? []and overridesopenAIPayload.model = copilotModelon the translated-Copilot path so the resolved id is actually used on the wireWhy this is safe for users who don't see
-internalvariantsThe exact-match branch fires first. If your catalog has
claude-opus-4.7-1mdirectly, this PR is a no-op for your traffic.Test plan
preprocess.test.tstests still passresolveAgainstCatalog(empty catalog, exact match, internal-only, both-present prefers-exact, neither-present)preprocessPayloadcatalog threading (with + without catalog)bun test packages/proxy/test/routes/preprocess.test.ts→ 56 passclaude-cli→ opus-4.7 + 1M context beta now works end-to-end through raven against my Copilot account (previously 400)Open question for maintainer
Happy to narrow the heuristic if you'd prefer (e.g. only attempt
-internalfor known-1msuffixes) — current version is intentionally a generic fallback since the upstream naming may extend to other variants.