Upstream provider restriction for Kilo exclusive models#3030
Upstream provider restriction for Kilo exclusive models#3030chrarnoldus wants to merge 3 commits intomainfrom
Conversation
| if (restriction.length > 0) { | ||
| const provider = requestToMutate.body.provider; | ||
| if (provider?.only) { | ||
| provider.only = [...new Set(provider.only).intersection(new Set(restriction))]; |
There was a problem hiding this comment.
WARNING: Set.prototype.intersection can crash in unsupported runtimes
Set.prototype.intersection is a new Set method and is not available in older Node/edge/browser runtimes unless polyfilled. This request path will throw a TypeError whenever a Kilo-exclusive model with inference_provider_restriction is used together with an existing provider.only array, causing the gateway request to fail before it reaches the provider. Use a compatibility-safe array filter against a Set instead.
There was a problem hiding this comment.
This repo targets Node 24 (see the engines field in package.json); Set.prototype.intersection has been stable since Node 22.12 / V8 12.2, so keeping it as-is.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (11 files)
Reviewed by gpt-5.5-20260423 · 286,520 tokens |
Pull the inner block of applyProviderSpecificLogic that rewrites the model id and narrows the OpenRouter provider restriction into a standalone function, and cover it with unit tests.
Summary
Upstream provider restriction for Kilo-exclusive models. Each Kilo-exclusive model can now declare an
inference_provider_restrictionlist; when a request targets such a model via OpenRouter or the Vercel AI Gateway, the upstreamprovider.onlylist is narrowed to that restriction (intersecting with any caller-suppliedonly).One reason to restrict the inference provider is that the free version of a model may only be offered by a specific inference provider, so we need to make sure routing stays pinned to that provider instead of falling through to a paid one.
The body of the
if (kiloExclusiveModel)branch is extracted intoapplyKiloExclusiveModelSettingsinkilo-exclusive-model.tsand covered by unit tests.Verification
apps/web/src/lib/ai-gateway/providers/kilo-exclusive-model.test.ts.Visual Changes
N/A
Reviewer Notes
Set.prototype.intersectionis used inapplyKiloExclusiveModelSettings. The bot flagged this as potentially unsupported; this repo targets Node 24 (seeenginesinpackage.json), andSet.prototype.intersectionhas been stable since Node 22.12 / V8 12.2, so we're keeping it.