Skip to content

Upstream provider restriction for Kilo exclusive models#3030

Open
chrarnoldus wants to merge 3 commits intomainfrom
christiaan/provider-restriction
Open

Upstream provider restriction for Kilo exclusive models#3030
chrarnoldus wants to merge 3 commits intomainfrom
christiaan/provider-restriction

Conversation

@chrarnoldus
Copy link
Copy Markdown
Contributor

@chrarnoldus chrarnoldus commented May 4, 2026

Summary

Upstream provider restriction for Kilo-exclusive models. Each Kilo-exclusive model can now declare an inference_provider_restriction list; when a request targets such a model via OpenRouter or the Vercel AI Gateway, the upstream provider.only list is narrowed to that restriction (intersecting with any caller-supplied only).

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 into applyKiloExclusiveModelSettings in kilo-exclusive-model.ts and covered by unit tests.

Verification

  • N/A — no manual verification beyond the new unit tests in apps/web/src/lib/ai-gateway/providers/kilo-exclusive-model.test.ts.

Visual Changes

N/A

Reviewer Notes

Set.prototype.intersection is used in applyKiloExclusiveModelSettings. The bot flagged this as potentially unsupported; this repo targets Node 24 (see engines in package.json), and Set.prototype.intersection has been stable since Node 22.12 / V8 12.2, so we're keeping it.

if (restriction.length > 0) {
const provider = requestToMutate.body.provider;
if (provider?.only) {
provider.only = [...new Set(provider.only).intersection(new Set(restriction))];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 4, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (11 files)
  • apps/web/src/lib/ai-gateway/providers/anthropic.constants.ts
  • apps/web/src/lib/ai-gateway/providers/apply-provider-specific-logic.ts
  • apps/web/src/lib/ai-gateway/providers/google.ts
  • apps/web/src/lib/ai-gateway/providers/kilo-exclusive-model.test.ts
  • apps/web/src/lib/ai-gateway/providers/kilo-exclusive-model.ts
  • apps/web/src/lib/ai-gateway/providers/minimax.ts
  • apps/web/src/lib/ai-gateway/providers/morph.ts
  • apps/web/src/lib/ai-gateway/providers/qwen.ts
  • apps/web/src/lib/ai-gateway/providers/seed.ts
  • apps/web/src/lib/ai-gateway/providers/stepfun.ts
  • apps/web/src/lib/ai-gateway/providers/xai.ts

Reviewed by gpt-5.5-20260423 · 286,520 tokens

kilo-code-bot Bot added 2 commits May 4, 2026 19:00
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.
@chrarnoldus chrarnoldus self-assigned this May 4, 2026
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.

1 participant