feat: let orgs restrict BYOK keys to models - #3466
Conversation
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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
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 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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
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. Comment |
Follow-up to #3418, which added the
provider_key.allowedModelsrestriction and wired gateway enforcement for both managed credentials and BYOK keys, but only exposed the editing surface in theee/adminmanaged-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/providerandPATCH /keys/provider/{id}acceptallowedModels; every provider-key response returns it.admin-provider-credentials.tsintolib/provider-key-allowed-models.tsand are shared by both routes, so managed and BYOK keys behave identically (trim + dedupe, empty list stored asNULL, unknown ids rejected with the offending id in the message).PATCHvalidates 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.customproviders, whose models are not catalogue ids — the gateway already exempts them from this filter for the same reason.Dashboard (
apps/ui)MultiModelIdSelectorfrom feat: restrict provider keys to specific models #3418 (paste a comma-separated list, unknown ids flagged as chips).N modelsbadge 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 throughproviderKeyAllowsModel. 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 modelsbadge on the restricted key:Allowed-models dialog (light / dark):
Add-key dialog with the new field (light / dark):
Verification
keys-provider.spec.tscover 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) andadmin-provider-credentials.spec.ts(62) both pass.pnpm build(17/17) andpnpm formatclean.🤖 Generated with Claude Code