Skip to content

feat: let orgs restrict BYOK keys to models - #3466

Merged
steebchen merged 2 commits into
mainfrom
byok-allowed-models-ui
Aug 7, 2026
Merged

steebchen merged 2 commits into
mainfrom
byok-allowed-models-ui

Conversation

@steebchen

@steebchen steebchen commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #3418, which added the provider_key.allowedModels restriction and wired gateway enforcement for both managed credentials and BYOK keys, but only exposed the editing surface in the ee/admin managed-credentials dashboard. Organizations had no way to set it on their own keys.

For BYOK the restriction is arguably more useful than for managed credentials: users commonly bring a key from an account that only has some models enabled, and today routing happily picks that key for a model the upstream account will reject.

What changed

API (apps/api)

  • POST /keys/provider and PATCH /keys/provider/{id} accept allowedModels; every provider-key response returns it.
  • The normalize / catalogue-validate / pin-a-validation-model helpers move out of admin-provider-credentials.ts into lib/provider-key-allowed-models.ts and are shared by both routes, so managed and BYOK keys behave identically (trim + dedupe, empty list stored as NULL, unknown ids rejected with the offending id in the message).
  • A restricted key is validated at save time against one of its own allowed models rather than the provider's default validation model — otherwise the keys the restriction exists for are exactly the ones that fail to save. When no allowed model can answer a chat probe (image/embedding-only lists) the live check is skipped, matching the admin route.
  • PATCH validates against the catalogue only, no live probe: the token cannot change through it, narrowing the list can never break a working key, and a failing probe would block the edit a user makes because their account lost access to a model.
  • Rejected for custom providers, whose models are not catalogue ids — the gateway already exempts them from this filter for the same reason.

Dashboard (apps/ui)

  • Allowed-models picker in the add-key dialog and a per-key Restrict models dialog, both using the shared MultiModelIdSelector from feat: restrict provider keys to specific models #3418 (paste a comma-separated list, unknown ids flagged as chips).
  • Restricted keys show a N models badge in the list.

Shared (packages/shared)

  • getProviderModelIds / getModelIdsByProvider, replacing the inline catalogue walk in the admin catalog route and giving the dashboard the same provider→live-model-ids view without a round trip.

Nothing changed in the gateway: resolveProviderContext, the hybrid-mode credits fallback, and the per-model availability computation already filter org-owned keys through providerKeyAllowsModel. In hybrid mode an excluded model falls back to credits rather than failing, so restricting a key never takes a model away from a project.

Screenshots

Row actions, before and after — the new Restrict models entry, and the 3 models badge on the restricted key:

Before After
Provider key row menu before: Set spend limit, Deactivate, Delete Provider key row menu after: Restrict models added, key shows a 3 models badge

Allowed-models dialog (light / dark):

Light Dark
Allowed models dialog in light mode with three selected models Allowed models dialog in dark mode with three selected models

Add-key dialog with the new field (light / dark):

Light Dark
Add provider key dialog in light mode showing the Allowed models field Add provider key dialog in dark mode showing the Allowed models field

Verification

  • New specs in keys-provider.spec.ts cover normalization, the empty-list-is-no-restriction rule, unknown-model rejection on create and update, the pinned save-time probe, the custom-provider rejection, listing, clearing, and the audit entry. keys-provider.spec.ts (54) and admin-provider-credentials.spec.ts (62) both pass.
  • pnpm build (17/17) and pnpm format clean.
  • The screenshots were taken driving the real dashboard against a local stack: the restriction shown was applied through the dialog and persisted via the API, and the badge is read back from the list endpoint.

🤖 Generated with Claude Code

steebchen and others added 2 commits August 7, 2026 20:11
Opens the provider_key.allowedModels restriction (PR #3418) to end users:
the org-facing API now accepts and returns it, and the dashboard's provider
keys page can set it per key.

- apps/api: shared normalize/validate/pin helpers extracted from the admin
  route into lib/provider-key-allowed-models.ts and reused by
  POST/PATCH /keys/provider; a restricted key is validated against one of its
  own allowed models so a key with partial model access still saves.
  Rejected for custom providers, whose models are not catalogue ids.
- apps/ui: allowed-models picker in the add-key dialog, a per-key "Restrict
  models" dialog, and a badge on restricted keys.
- packages/shared: getProviderModelIds/getModelIdsByProvider, replacing the
  inline catalogue walk in the admin catalog route.

Gateway enforcement already covered BYOK keys, so nothing changes there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 7, 2026 18:24
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@steebchen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 296b86b1-7762-44fb-855a-dd3670195716

📥 Commits

Reviewing files that changed from the base of the PR and between f90f39d and d0ecb55.

📒 Files selected for processing (10)
  • apps/api/src/lib/provider-key-allowed-models.ts
  • apps/api/src/routes/admin-provider-credentials.ts
  • apps/api/src/routes/keys-provider.spec.ts
  • apps/api/src/routes/keys-provider.ts
  • apps/docs/content/learn/provider-keys.mdx
  • apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
  • apps/ui/src/components/provider-keys/provider-key-models-dialog.tsx
  • apps/ui/src/components/provider-keys/provider-keys-list.tsx
  • packages/shared/src/index.ts
  • packages/shared/src/provider-model-ids.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@steebchen
steebchen merged commit b26fc22 into main Aug 7, 2026
12 checks passed
@steebchen
steebchen deleted the byok-allowed-models-ui branch August 7, 2026 20:07
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.

2 participants