Skip to content

feat: add KeyID filter to ListModelsRequest to scope calls to a single key - #4036

Merged
akshaydeo merged 1 commit into
devfrom
06-04-feat_adds_key_param_in_list_models
Jun 9, 2026
Merged

feat: add KeyID filter to ListModelsRequest to scope calls to a single key#4036
akshaydeo merged 1 commit into
devfrom
06-04-feat_adds_key_param_in_list_models

Conversation

@Pratham-Mishra04

@Pratham-Mishra04 Pratham-Mishra04 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a KeyID field to BifrostListModelsRequest that allows callers to scope a ListModels call to a single configured key by ID. This enables the catalog composer (and other callers) to cache list-models responses on a per-key basis without needing an extra round-trip, and prevents the provider from aggregating results across all configured keys when only one key's models are needed.

Changes

  • Added KeyID *string to BifrostListModelsRequest — when set, the request worker filters the available keys down to the single key matching that ID before dispatching the request. If no key matches, a BifrostError is returned immediately.
  • The field is tagged json:"-" so it is never forwarded to the provider; it is purely an internal routing hint.

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 ./...

To validate manually, issue a ListModels request with KeyID set to a valid key ID and confirm only that key's models are returned. Then set KeyID to an unknown ID and confirm a BifrostError is returned with a message indicating no key was found.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

KeyID is an internal-only field (json:"-") and is never transmitted to the provider. No secrets or PII are introduced. The error message includes the key ID string and provider key name, which should be treated as internal identifiers — ensure these are not surfaced in public-facing error responses.

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

Summary by CodeRabbit

  • New Features
    • Listing models can be scoped to a specific key for more precise results and per-key caching/invalidation.
  • Bug Fixes
    • Requests that specify a key now validate existence and return a clear error when no matching key is found; provider handling is skipped for invalid keys.
  • Tests
    • Added unit tests to verify key-scoping behavior and ensure input slices are not mutated.

@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.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an optional KeyID to BifrostListModelsRequest and makes requestWorker filter eligible keys to that ID; if no key matches the worker emits a BifrostError and skips provider handling. A new filterKeysByID helper and unit test validate filtering and non-mutation.

Changes

Single-key model listing scope

Layer / File(s) Summary
Key ID field in ListModelsRequest
core/schemas/models.go
BifrostListModelsRequest adds optional KeyID *string (JSON "-") for internal per-key scoping.
Key filtering in worker + helper + tests
core/bifrost.go, core/bifrost.go, core/bifrost_test.go
requestWorker narrows eligible keys to the provided KeyID, sends a BifrostError if no matching key exists, filterKeysByID implements the filtering, and TestFilterKeysByID verifies match, no-match, empty-target, and non-mutation.

Sequence Diagram(s)

sequenceDiagram
  participant RequestWorker
  participant filterKeysByID
  participant Provider
  RequestWorker->>filterKeysByID: filter(keys, KeyID)
  filterKeysByID-->>RequestWorker: filteredKeys
  alt filteredKeys empty
    RequestWorker->>RequestWorker: send BifrostError on req.Err
  else
    RequestWorker->>Provider: call ListModels with filteredKeys
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 I scoped a key with a gentle hop,
One ID to find, no need to stop,
The filter nibbles down the list with care,
If none are found it sighs into the air,
A tidy hop — a tiny change to spare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature addition: adding a KeyID filter to ListModelsRequest to scope calls to a single key, which aligns with the changeset.
Description check ✅ Passed The description comprehensively covers all required sections: summary, changes, type of change, affected areas, testing instructions, breaking changes, and security considerations. All critical information is present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-04-feat_adds_key_param_in_list_models

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

Pratham-Mishra04 commented Jun 3, 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 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — a small, focused change that adds an internal routing hint to ListModels with no impact on other request types.

The KeyID filter is applied after getAllSupportedKeys, follows the existing error-path conventions, has no pool-safety concerns, and cannot trigger fallback loops because ListModelsRequest never carries fallbacks. The helper function is straightforward and well-tested.

No files require special attention.

Important Files Changed

Filename Overview
core/schemas/models.go Adds KeyID *string to BifrostListModelsRequest — correctly tagged json:"-", well-documented including the "disabled/invalid key indistinguishable from missing" caveat.
core/bifrost.go Adds filterKeysByID helper and the KeyID filter block inside requestWorker; follows existing error-handling patterns, IsBifrostError: false yields HTTP 400, and pool safety is preserved because resetBifrostRequest already nils ListModelsRequest.
core/bifrost_test.go Unit tests for filterKeysByID cover the hit, miss, empty-target, and no-mutation cases; focused on the helper rather than end-to-end worker path.

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

Comment thread core/bifrost.go
Comment thread core/bifrost.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 5163c7a to ba81f93 Compare June 4, 2026 20:49
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from e78233f to 8056692 Compare June 4, 2026 20:49
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from ba81f93 to 9b90058 Compare June 5, 2026 09:48
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from 8056692 to 5895dc2 Compare June 5, 2026 09:48
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 9b90058 to 6faef35 Compare June 5, 2026 10:43
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from 5895dc2 to 6ce23f5 Compare June 5, 2026 10:43

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/bifrost.go`:
- Around line 5994-6005: The error currently sent to req.Err
(schemas.BifrostError creation in the error branch) exposes the requested key id
(target) and provider.GetProviderKey() to clients; change the client-facing
Message to a generic string like "requested key not found" without embedding
target or provider, and remove or redact provider/target from any fields that
flow to HTTP responses (e.g., ExtraFields.Provider, OriginalModelRequested,
ResolvedModelUsed) while emitting the full identifiers to an internal debug log
instead (use the existing logger in scope rather than returning them in
schemas.BifrostError). Ensure req.Err still receives a schemas.BifrostError but
with non-sensitive client message and only write sensitive details to internal
logs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c7acb0f2-538d-49df-b25c-a599881ad2a8

📥 Commits

Reviewing files that changed from the base of the PR and between 5895dc2 and 6ce23f5.

📒 Files selected for processing (2)
  • core/bifrost.go
  • core/schemas/models.go

Comment thread core/bifrost.go
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch 2 times, most recently from 5f43cbc to 99af5b8 Compare June 7, 2026 07:25
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch 2 times, most recently from 396eb1d to ff79d23 Compare June 8, 2026 06:54
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from 99af5b8 to 8934e2e Compare June 8, 2026 06:54
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from ff79d23 to 435aa3d Compare June 8, 2026 07:18
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from 8934e2e to 400b52e Compare June 8, 2026 07:18
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 435aa3d to 8089c10 Compare June 8, 2026 07:22
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from 400b52e to e77b1f7 Compare June 8, 2026 07:22
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 8089c10 to b79deca Compare June 8, 2026 11:55
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch 2 times, most recently from 1f7578f to 6300061 Compare June 8, 2026 12:24
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch 2 times, most recently from 0cee600 to 94d7bdd Compare June 8, 2026 12:28
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch 2 times, most recently from 4ec2730 to b6de129 Compare June 8, 2026 17:02
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 94d7bdd to 50dcfba Compare June 8, 2026 17:02
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from b6de129 to b66eb67 Compare June 8, 2026 21:20
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from 50dcfba to b53280a Compare June 8, 2026 21:20
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_datasheet_store_to_modelcatalog branch from b53280a to b982660 Compare June 8, 2026 21:28
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_adds_key_param_in_list_models branch from b66eb67 to 215242f Compare June 8, 2026 21:28

akshaydeo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 9, 5:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 5:34 AM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 06-04-feat_adds_datasheet_store_to_modelcatalog to graphite-base/4036 June 9, 2026 05:33
@akshaydeo
akshaydeo changed the base branch from graphite-base/4036 to dev June 9, 2026 05:33
@akshaydeo
akshaydeo merged commit 47e7962 into dev Jun 9, 2026
10 of 11 checks passed
@akshaydeo
akshaydeo deleted the 06-04-feat_adds_key_param_in_list_models branch June 9, 2026 05:34
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.

3 participants