Skip to content

feat: scope ListModels to single key when KeyID is set, add filterKeysByID helper - #4193

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
feat_adds_key_param_in_list_models
Jun 9, 2026
Merged

Pratham-Mishra04 merged 1 commit into
devfrom
feat_adds_key_param_in_list_models

Conversation

@Pratham-Mishra04

Copy link
Copy Markdown
Collaborator

Summary

Adds a KeyID field to BifrostListModelsRequest that scopes a ListModels call to a single key matched by Key.ID. This allows callers such as the catalog composer to cache list-models output per-key for fine-grained invalidation without requiring an extra round-trip or having the provider aggregate results across every configured key.

Changes

  • Added KeyID *string to BifrostListModelsRequest (tagged json:"-" so it is never forwarded to providers). When set, the request worker filters the already-validated key set down to the single matching key before dispatching. If no key matches, a BifrostError is returned immediately.
  • Added filterKeysByID helper that returns a new slice containing only keys whose ID equals the target, leaving the input slice unmodified.
  • Added TestFilterKeysByID covering: a successful match, a missing key, an empty target string, and input-slice immutability.

Note: the lookup runs against the already-filtered set of supported keys (disabled or invalid keys are excluded before the match), so a KeyID pointing to a disabled key produces the same "no key found" error as a non-existent KeyID. Callers that need to distinguish these cases must inspect the raw account configuration directly.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go version
go test ./...

The new TestFilterKeysByID test directly exercises the helper and the key-scoping logic. To validate end-to-end, issue a ListModels request with KeyID set to a valid key ID and confirm only that key's models are returned. Issue one with an unknown KeyID and confirm a "no key found" error is returned.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

Security considerations

KeyID is tagged json:"-" and is never serialised or forwarded to any external provider. No secrets or PII are introduced.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Pratham-Mishra04, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2c7eda1a-276e-4258-acca-ba07c3c06eb1

📥 Commits

Reviewing files that changed from the base of the PR and between d923cda and 499ef15.

📒 Files selected for processing (3)
  • core/bifrost.go
  • core/bifrost_test.go
  • core/schemas/models.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat_adds_key_param_in_list_models

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

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge; the change is narrow, pool-safe, and the key filtering logic is straightforward.

The feature is a clean, well-tested addition. The only concern is that the "no key found" error leaves fallback behavior open, which could silently route to a different provider when fallbacks are configured — a minor edge case unlikely to occur in practice for ListModels requests.

core/bifrost.go — specifically the AllowFallbacks omission in the new error path at the KeyID filter block.

Important Files Changed

Filename Overview
core/schemas/models.go Adds KeyID *string field to BifrostListModelsRequest with json:"-" tag; clean addition consistent with the existing Unfiltered field pattern.
core/bifrost.go Adds key-scoping logic after getAllSupportedKeys and a filterKeysByID helper; the "no key found" error leaves AllowFallbacks unset (nil = allow fallbacks), which is consistent with surrounding error patterns but may be surprising for an explicitly-scoped request.
core/bifrost_test.go Adds TestFilterKeysByID covering match, miss, empty target, and input-slice immutability; table-driven subtests with clear failure messages.

Reviews (4): Last reviewed commit: "feat: adds key param in list models" | Re-trigger Greptile

Comment thread core/schemas/models.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the feat_adds_datasheet_store_to_modelcatalog branch from 0947354 to e042428 Compare June 9, 2026 08:10
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the feat_adds_key_param_in_list_models branch from 29ed4c0 to 267d94f Compare June 9, 2026 08:10
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the feat_adds_datasheet_store_to_modelcatalog branch from e042428 to 89bb042 Compare June 9, 2026 09:55
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the feat_adds_key_param_in_list_models branch from 267d94f to 5952bf3 Compare June 9, 2026 09:55

Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Jun 9, 10:11 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 10:55 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 9, 10:56 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from feat_adds_datasheet_store_to_modelcatalog to graphite-base/4193 June 9, 2026 10:51
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from graphite-base/4193 to dev June 9, 2026 10:53
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the feat_adds_key_param_in_list_models branch from 5952bf3 to 499ef15 Compare June 9, 2026 10:54
@Pratham-Mishra04
Pratham-Mishra04 merged commit aa4a44c into dev Jun 9, 2026
15 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the feat_adds_key_param_in_list_models branch June 9, 2026 10:56
akshaydeo pushed a commit that referenced this pull request Jun 12, 2026
…erKeysByID` helper (#4193)

## Summary

Adds a `KeyID` field to `BifrostListModelsRequest` that scopes a `ListModels` call to a single key matched by `Key.ID`. This allows callers such as the catalog composer to cache list-models output per-key for fine-grained invalidation without requiring an extra round-trip or having the provider aggregate results across every configured key.

## Changes

- Added `KeyID *string` to `BifrostListModelsRequest` (tagged `json:"-"` so it is never forwarded to providers). When set, the request worker filters the already-validated key set down to the single matching key before dispatching. If no key matches, a `BifrostError` is returned immediately.
- Added `filterKeysByID` helper that returns a new slice containing only keys whose `ID` equals the target, leaving the input slice unmodified.
- Added `TestFilterKeysByID` covering: a successful match, a missing key, an empty target string, and input-slice immutability.

Note: the lookup runs against the already-filtered set of supported keys (disabled or invalid keys are excluded before the match), so a `KeyID` pointing to a disabled key produces the same "no key found" error as a non-existent `KeyID`. Callers that need to distinguish these cases must inspect the raw account configuration directly.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

The new `TestFilterKeysByID` test directly exercises the helper and the key-scoping logic. To validate end-to-end, issue a `ListModels` request with `KeyID` set to a valid key ID and confirm only that key's models are returned. Issue one with an unknown `KeyID` and confirm a "no key found" error is returned.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

`KeyID` is tagged `json:"-"` and is never serialised or forwarded to any external provider. No secrets or PII are introduced.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…erKeysByID` helper (maximhq#4193)

## Summary

Adds a `KeyID` field to `BifrostListModelsRequest` that scopes a `ListModels` call to a single key matched by `Key.ID`. This allows callers such as the catalog composer to cache list-models output per-key for fine-grained invalidation without requiring an extra round-trip or having the provider aggregate results across every configured key.

## Changes

- Added `KeyID *string` to `BifrostListModelsRequest` (tagged `json:"-"` so it is never forwarded to providers). When set, the request worker filters the already-validated key set down to the single matching key before dispatching. If no key matches, a `BifrostError` is returned immediately.
- Added `filterKeysByID` helper that returns a new slice containing only keys whose `ID` equals the target, leaving the input slice unmodified.
- Added `TestFilterKeysByID` covering: a successful match, a missing key, an empty target string, and input-slice immutability.

Note: the lookup runs against the already-filtered set of supported keys (disabled or invalid keys are excluded before the match), so a `KeyID` pointing to a disabled key produces the same "no key found" error as a non-existent `KeyID`. Callers that need to distinguish these cases must inspect the raw account configuration directly.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

The new `TestFilterKeysByID` test directly exercises the helper and the key-scoping logic. To validate end-to-end, issue a `ListModels` request with `KeyID` set to a valid key ID and confirm only that key's models are returned. Issue one with an unknown `KeyID` and confirm a "no key found" error is returned.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

`KeyID` is tagged `json:"-"` and is never serialised or forwarded to any external provider. No secrets or PII are introduced.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
…erKeysByID` helper (maximhq#4193)

## Summary

Adds a `KeyID` field to `BifrostListModelsRequest` that scopes a `ListModels` call to a single key matched by `Key.ID`. This allows callers such as the catalog composer to cache list-models output per-key for fine-grained invalidation without requiring an extra round-trip or having the provider aggregate results across every configured key.

## Changes

- Added `KeyID *string` to `BifrostListModelsRequest` (tagged `json:"-"` so it is never forwarded to providers). When set, the request worker filters the already-validated key set down to the single matching key before dispatching. If no key matches, a `BifrostError` is returned immediately.
- Added `filterKeysByID` helper that returns a new slice containing only keys whose `ID` equals the target, leaving the input slice unmodified.
- Added `TestFilterKeysByID` covering: a successful match, a missing key, an empty target string, and input-slice immutability.

Note: the lookup runs against the already-filtered set of supported keys (disabled or invalid keys are excluded before the match), so a `KeyID` pointing to a disabled key produces the same "no key found" error as a non-existent `KeyID`. Callers that need to distinguish these cases must inspect the raw account configuration directly.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go version
go test ./...
```

The new `TestFilterKeysByID` test directly exercises the helper and the key-scoping logic. To validate end-to-end, issue a `ListModels` request with `KeyID` set to a valid key ID and confirm only that key's models are returned. Issue one with an unknown `KeyID` and confirm a "no key found" error is returned.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

`KeyID` is tagged `json:"-"` and is never serialised or forwarded to any external provider. No secrets or PII are introduced.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
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