Skip to content

fix: add mantle list models endpoint in bedrock list models method - #4677

Merged
akshaydeo merged 1 commit into
devfrom
06-24-fix_add_mantle_list_models_endpoint_in_bedrock_list_models_method
Jun 24, 2026
Merged

fix: add mantle list models endpoint in bedrock list models method#4677
akshaydeo merged 1 commit into
devfrom
06-24-fix_add_mantle_list_models_endpoint_in_bedrock_list_models_method

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Bedrock's ListFoundationModels API omits models served exclusively through the Mantle OpenAI-compatible endpoint (e.g. gpt-5.x, gemma-4). This PR adds a supplementary call to the Mantle /v1/models endpoint and merges the results into the existing foundation model list, ensuring those models are discoverable through Bifrost's list models API.

Changes

  • Added listMantleModels which calls the Bedrock Mantle /v1/models endpoint, supporting both Bearer token and AWS SigV4 signing. The function is best-effort and returns nil on any failure so the foundation model list is always returned.
  • After the standard listModelsByKey response is built, the Mantle catalog is merged in, deduplicating by model ID and applying the same allow/blacklist/alias gating as the foundation model path.
  • Reused the existing OpenAIListModelsResponse.ToBifrostListModelsResponse conversion to normalize Mantle model entries into the Bifrost schema.

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

Call the Bifrost list models endpoint against a Bedrock key configured for a region where Mantle models are available and verify that models such as gpt-5.x or gemma-4 appear in the response alongside the standard foundation models.

go test ./...

Confirm that a failure to reach the Mantle endpoint (e.g. network error, non-200 response) does not prevent the foundation model list from being returned.

Screenshots/Recordings

N/A

Breaking changes

  • Yes
  • No

Related issues

N/A

Security considerations

The Mantle request uses the same signing path (signAWSRequestFromKey) as other Bedrock requests, or falls back to a Bearer token if a key value is present. No new credentials or secrets 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

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


tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Collaborator Author

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

@TejasGhatte
TejasGhatte marked this pull request as ready for review June 24, 2026 18:04
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Bedrock provider's listModelsByKey function is extended to also query the Bedrock Mantle (OpenAI-compatible) /v1/models endpoint. A new listMantleModels helper handles the signed request, response parsing, and key gating; its results are merged into the foundation-model list with ID-based deduplication.

Changes

Bedrock Mantle Model Listing

Layer / File(s) Summary
listMantleModels helper and OpenAI import
core/providers/bedrock/bedrock.go
Imports core/providers/openai for Mantle response types and introduces listMantleModels, which issues a signed GET to /v1/models, parses the OpenAI-format JSON, applies the same allow/blacklist/alias gating as the foundation-model path, and returns nil on any failure.
Mantle result merge in listModelsByKey
core/providers/bedrock/bedrock.go
Calls listMantleModels after the foundation-model list is built and appends unique entries (deduped by model ID) from the mantle response into response.Data; the merge is silently skipped if listMantleModels returns nil.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • maximhq/bifrost#4676: Updates Mantle chat/response routing to use canonicalized model names — directly paired with this PR's Mantle model discovery work in the same Bedrock provider.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐇 Hop hop, the mantle reveals its stash,
Models merging in a blink and a flash.
Duplicates? Banished by IDs so neat,
The foundation list now feels complete.
A signed GET sent, a nil caught with grace—
More models discovered, every trace! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not address #123 Files API Support; it changes Bedrock list-models instead of adding POST /v1/files support. Implement the Files API flow requested by #123, especially POST /v1/files, or retarget the PR if this Bedrock list-models work is separate.
Out of Scope Changes check ⚠️ Warning The Bedrock Mantle list-models work is unrelated to the linked Files API support objective. Remove or split the list-models changes, and keep this PR focused on Files API support for #123.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the Bedrock list-models enhancement and matches the main code change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description follows the required template and includes clear summaries, changes, testing steps, and impact notes.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-24-fix_add_mantle_list_models_endpoint_in_bedrock_list_models_method

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

@coderabbitai
coderabbitai Bot requested review from akshaydeo and danpiths June 24, 2026 18:05
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The change is additive and best-effort — failures in the new mantle call never propagate to callers, so the existing foundation-model listing path is unaffected.

The new function is well-isolated: auth handling mirrors the rest of the mantle path, the dedup logic is correct, and nil is returned on any failure so the foundation-models response is always returned. The two findings are minor: a misplaced doc comment that mis-attributes listMantleModels description to the wrong function in godoc, and a behavioral change where the Latency field now includes the mantle round-trip time in addition to the foundation-models call.

core/providers/bedrock/bedrock.go — the doc comment block and the latency field behavior change are both in this file.

Important Files Changed

Filename Overview
core/providers/bedrock/bedrock.go Adds listMantleModels (best-effort GET to Bedrock Mantle /v1/models) and merges results into listModelsByKey; doc comment misplaced and reported latency now includes the mantle round-trip

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant listModelsByKey
    participant BedrockFoundationModels as Bedrock /foundation-models
    participant listMantleModels
    participant BedrockMantle as Bedrock Mantle /v1/models

    Caller->>listModelsByKey: ListModels(ctx, key, request)
    listModelsByKey->>BedrockFoundationModels: GET /foundation-models (SigV4 or Bearer)
    BedrockFoundationModels-->>listModelsByKey: BedrockListModelsResponse
    listModelsByKey->>listModelsByKey: ToBifrostListModelsResponse()
    listModelsByKey->>listMantleModels: listMantleModels(ctx, key, region, unfiltered)
    listMantleModels->>BedrockMantle: GET /v1/models (SigV4 or Bearer)
    alt success
        BedrockMantle-->>listMantleModels: OpenAIListModelsResponse
        listMantleModels-->>listModelsByKey: BifrostListModelsResponse (mantle models)
        listModelsByKey->>listModelsByKey: dedup by ID, append new mantle models
    else any error
        BedrockMantle-->>listMantleModels: error / non-200
        listMantleModels-->>listModelsByKey: nil (best-effort, silent)
    end
    listModelsByKey->>listModelsByKey: set Latency (includes mantle call time)
    listModelsByKey-->>Caller: merged BifrostListModelsResponse
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant listModelsByKey
    participant BedrockFoundationModels as Bedrock /foundation-models
    participant listMantleModels
    participant BedrockMantle as Bedrock Mantle /v1/models

    Caller->>listModelsByKey: ListModels(ctx, key, request)
    listModelsByKey->>BedrockFoundationModels: GET /foundation-models (SigV4 or Bearer)
    BedrockFoundationModels-->>listModelsByKey: BedrockListModelsResponse
    listModelsByKey->>listModelsByKey: ToBifrostListModelsResponse()
    listModelsByKey->>listMantleModels: listMantleModels(ctx, key, region, unfiltered)
    listMantleModels->>BedrockMantle: GET /v1/models (SigV4 or Bearer)
    alt success
        BedrockMantle-->>listMantleModels: OpenAIListModelsResponse
        listMantleModels-->>listModelsByKey: BifrostListModelsResponse (mantle models)
        listModelsByKey->>listModelsByKey: dedup by ID, append new mantle models
    else any error
        BedrockMantle-->>listMantleModels: error / non-200
        listMantleModels-->>listModelsByKey: nil (best-effort, silent)
    end
    listModelsByKey->>listModelsByKey: set Latency (includes mantle call time)
    listModelsByKey-->>Caller: merged BifrostListModelsResponse
Loading

Reviews (1): Last reviewed commit: "fix: add mantle list models endpoint in ..." | Re-trigger Greptile

Comment thread core/providers/bedrock/bedrock.go
Comment thread core/providers/bedrock/bedrock.go

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

🧹 Nitpick comments (1)
core/providers/bedrock/bedrock.go (1)

865-881: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Mantle fetch now runs on every listModelsByKey call.

listMantleModels issues an extra signed GET (via the unary provider.client) on every list-models request. It's best-effort (nil on failure), but an unreachable/slow Mantle endpoint can add up to the unary client's timeout to each call, and startTime (L791) now folds the Mantle round-trip into the reported Latency. Consider whether this should be gated (e.g., only when Mantle is configured/relevant) and confirm the latency semantics are acceptable.

🤖 Prompt for 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.

In `@core/providers/bedrock/bedrock.go` around lines 865 - 881, The Mantle merge
in listModelsByKey currently triggers listMantleModels on every request, which
adds an extra signed client call and inflates the reported Latency. Update the
logic around listModelsByKey and listMantleModels to only fetch Mantle models
when Mantle is actually configured/relevant (or another explicit gate applies),
and make sure the latency measurement in response.ExtraFields.Latency reflects
the intended scope of the call.
🤖 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.

Nitpick comments:
In `@core/providers/bedrock/bedrock.go`:
- Around line 865-881: The Mantle merge in listModelsByKey currently triggers
listMantleModels on every request, which adds an extra signed client call and
inflates the reported Latency. Update the logic around listModelsByKey and
listMantleModels to only fetch Mantle models when Mantle is actually
configured/relevant (or another explicit gate applies), and make sure the
latency measurement in response.ExtraFields.Latency reflects the intended scope
of the call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 47ffe943-ffbb-40a7-806a-d00433c18912

📥 Commits

Reviewing files that changed from the base of the PR and between b98ba21 and 3a14d2c.

📒 Files selected for processing (1)
  • core/providers/bedrock/bedrock.go

akshaydeo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 24, 6:15 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 24, 6:15 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 7131032 into dev Jun 24, 2026
13 of 16 checks passed
@akshaydeo
akshaydeo deleted the 06-24-fix_add_mantle_list_models_endpoint_in_bedrock_list_models_method branch June 24, 2026 18:15
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…aximhq#4677)

## Summary

Bedrock's `ListFoundationModels` API omits models served exclusively through the Mantle OpenAI-compatible endpoint (e.g. `gpt-5.x`, `gemma-4`). This PR adds a supplementary call to the Mantle `/v1/models` endpoint and merges the results into the existing foundation model list, ensuring those models are discoverable through Bifrost's list models API.

## Changes

- Added `listMantleModels` which calls the Bedrock Mantle `/v1/models` endpoint, supporting both Bearer token and AWS SigV4 signing. The function is best-effort and returns `nil` on any failure so the foundation model list is always returned.
- After the standard `listModelsByKey` response is built, the Mantle catalog is merged in, deduplicating by model ID and applying the same allow/blacklist/alias gating as the foundation model path.
- Reused the existing `OpenAIListModelsResponse.ToBifrostListModelsResponse` conversion to normalize Mantle model entries into the Bifrost schema.

## Type of change

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

## Affected areas

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

## How to test

Call the Bifrost list models endpoint against a Bedrock key configured for a region where Mantle models are available and verify that models such as `gpt-5.x` or `gemma-4` appear in the response alongside the standard foundation models.

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

Confirm that a failure to reach the Mantle endpoint (e.g. network error, non-200 response) does not prevent the foundation model list from being returned.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

The Mantle request uses the same signing path (`signAWSRequestFromKey`) as other Bedrock requests, or falls back to a Bearer token if a key value is present. No new credentials or secrets 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
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
…aximhq#4677)

## Summary

Bedrock's `ListFoundationModels` API omits models served exclusively through the Mantle OpenAI-compatible endpoint (e.g. `gpt-5.x`, `gemma-4`). This PR adds a supplementary call to the Mantle `/v1/models` endpoint and merges the results into the existing foundation model list, ensuring those models are discoverable through Bifrost's list models API.

## Changes

- Added `listMantleModels` which calls the Bedrock Mantle `/v1/models` endpoint, supporting both Bearer token and AWS SigV4 signing. The function is best-effort and returns `nil` on any failure so the foundation model list is always returned.
- After the standard `listModelsByKey` response is built, the Mantle catalog is merged in, deduplicating by model ID and applying the same allow/blacklist/alias gating as the foundation model path.
- Reused the existing `OpenAIListModelsResponse.ToBifrostListModelsResponse` conversion to normalize Mantle model entries into the Bifrost schema.

## Type of change

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

## Affected areas

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

## How to test

Call the Bifrost list models endpoint against a Bedrock key configured for a region where Mantle models are available and verify that models such as `gpt-5.x` or `gemma-4` appear in the response alongside the standard foundation models.

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

Confirm that a failure to reach the Mantle endpoint (e.g. network error, non-200 response) does not prevent the foundation model list from being returned.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

N/A

## Security considerations

The Mantle request uses the same signing path (`signAWSRequestFromKey`) as other Bedrock requests, or falls back to a Bearer token if a key value is present. No new credentials or secrets 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
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