Skip to content

fix: skip key selection on anthropic provider - #6536

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
08-26-fix_skip_key_selection_on_anthropic_provider
Aug 26, 2026
Merged

fix: skip key selection on anthropic provider#6536
Pratham-Mishra04 merged 1 commit into
devfrom
08-26-fix_skip_key_selection_on_anthropic_provider

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

SkipKeySelection was previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that require max_tokens.

The fix tightens isKeySkippingAllowed to an allowlist of exactly one provider (Anthropic), since SkipKeySelection exists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it.

Changes

  • isKeySkippingAllowed now returns true only for schemas.Anthropic, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool.
  • The selectKeyFromProviderForModelWithPool call site now passes baseProviderType instead of providerKey to isKeySkippingAllowed, so the gate is evaluated against the resolved base provider.
  • SkipKeySelection is intentionally not cleared in clearAnthropicPassthroughForNonNativeProvider — it also drives IsClaudeCodeMaxMode, which suppresses x-api-key on the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead.
  • A new test TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider verifies that Anthropic skips key selection while Fireworks (with UseAnthropicEndpoints) still selects its own key.
  • TestClearAnthropicPassthroughForNonNativeProvider is updated to assert that SkipKeySelection survives the clear operation and documents why.

Type of change

  • Bug fix

Affected areas

  • Core (Go)
  • Providers/Integrations

How to test

go test ./core/... -run TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider
go test ./core/... -run TestClearAnthropicPassthroughForNonNativeProvider
go test ./...

The new test covers the regression directly: with SkipKeySelection set and a Fireworks provider, the selected key must be present and must have UseAnthropicEndpoints = true. Without this fix, the key pool would be empty and that assertion would fail.

Breaking changes

  • Yes
  • No

Security considerations

SkipKeySelection bypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider.

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.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f7e245ac-8852-4414-9946-036b00261603

📥 Commits

Reviewing files that changed from the base of the PR and between d1dfba6 and bb4e6b6.

📒 Files selected for processing (3)
  • core/bifrost.go
  • core/bifrost_test.go
  • core/utils.go

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved provider handling for OAuth passthrough requests.
    • Anthropic requests now correctly skip key selection while preserving configured settings.
    • Other providers continue selecting the appropriate configured key and endpoint behavior.
    • Added safeguards to ensure key-selection skipping is limited to supported Anthropic requests.

Walkthrough

The change restricts key-selection skipping to Anthropic OAuth passthrough. It evaluates the resolved base provider for wrapped providers and adds regression coverage for Anthropic and Fireworks behavior.

Changes

Provider key selection

Layer / File(s) Summary
Anthropic-only key skipping
core/bifrost.go, core/utils.go
Skip-key-selection documentation now describes OAuth passthrough. Eligibility uses the base provider type and allows skipping only for Anthropic.
Passthrough and provider-selection regression coverage
core/bifrost_test.go
Tests confirm that SkipKeySelection remains enabled, Anthropic skips key selection, and Fireworks selects its configured key while preserving UseAnthropicEndpoints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to bb4e6

The change restricts key-selection bypass behavior to Anthropic and adds regression coverage for non-Anthropic routing; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: akshaydeo, pratham-mishra04, roroghost17

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not address the directly linked issue [#123], which requires File API support for providers such as OpenAI or Anthropic. The changes only modify Anthropic OAuth passthrough and key-selecti… Link this PR to the issue that defines the SkipKeySelection fix, or implement the File API support required by [#123].
Out of Scope Changes check ⚠️ Warning The code changes are unrelated to the linked issue [#123]. They modify provider key selection and Anthropic OAuth passthrough behavior, while the issue concerns File API endpoints and file uploads. Remove these changes from the PR linked to [#123], or update the linked issue relationship to the correct key-selection/OAuth passthrough issue.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files.
Description check ✅ Passed The description clearly explains the bug, the implementation, the affected areas, test commands, security impact, and checklist status. Screenshots are not needed because this PR has no UI changes. Th…
Title check ✅ Passed The title clearly and concisely identifies the main change: restricting key-selection skipping to the Anthropic provider.
Full details: Linked Issues check

Explanation

The PR does not address the directly linked issue [#123], which requires File API support for providers such as OpenAI or Anthropic. The changes only modify Anthropic OAuth passthrough and key-selection behavior.

Full details: Description check

Explanation

The description clearly explains the bug, the implementation, the affected areas, test commands, security impact, and checklist status. Screenshots are not needed because this PR has no UI changes. The Related issues section is not included, but the description is otherwise complete.

  • Fix all pre-merge checks with AI
✨ 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 08-26-fix_skip_key_selection_on_anthropic_provider

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

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 August 26, 2026 06:29

Pratham-Mishra04 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Aug 26, 7:19 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 26, 7:20 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 merged commit e34883c into dev Aug 26, 2026
14 of 15 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 08-26-fix_skip_key_selection_on_anthropic_provider branch August 26, 2026 07:20
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
## Summary

`SkipKeySelection` was previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that require `max_tokens`.

The fix tightens `isKeySkippingAllowed` to an allowlist of exactly one provider (`Anthropic`), since `SkipKeySelection` exists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it.

## Changes

- `isKeySkippingAllowed` now returns `true` only for `schemas.Anthropic`, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool.
- The `selectKeyFromProviderForModelWithPool` call site now passes `baseProviderType` instead of `providerKey` to `isKeySkippingAllowed`, so the gate is evaluated against the resolved base provider.
- `SkipKeySelection` is intentionally **not** cleared in `clearAnthropicPassthroughForNonNativeProvider` — it also drives `IsClaudeCodeMaxMode`, which suppresses `x-api-key` on the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead.
- A new test `TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider` verifies that Anthropic skips key selection while Fireworks (with `UseAnthropicEndpoints`) still selects its own key.
- `TestClearAnthropicPassthroughForNonNativeProvider` is updated to assert that `SkipKeySelection` survives the clear operation and documents why.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Core (Go)
- [x] Providers/Integrations

## How to test

```sh
go test ./core/... -run TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider
go test ./core/... -run TestClearAnthropicPassthroughForNonNativeProvider
go test ./...
```

The new test covers the regression directly: with `SkipKeySelection` set and a Fireworks provider, the selected key must be present and must have `UseAnthropicEndpoints = true`. Without this fix, the key pool would be empty and that assertion would fail.

## Breaking changes

- [ ] Yes
- [x] No

## Security considerations

`SkipKeySelection` bypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider.

## Checklist

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

`SkipKeySelection` was previously allowed for any provider that wasn't Azure, Bedrock, BedrockMantle, or Vertex. This meant that if a governance routing rule rewrote the provider/model after the Claude Code OAuth transport set the flag, a non-Anthropic provider (e.g. Fireworks) would skip key selection entirely — leaving it without a configured key and causing request construction to fall back to the OpenAI schema, which breaks providers like Fireworks that require `max_tokens`.

The fix tightens `isKeySkippingAllowed` to an allowlist of exactly one provider (`Anthropic`), since `SkipKeySelection` exists solely for Claude Code OAuth passthrough where the caller's token is the upstream credential and only the Anthropic provider forwards it.

## Changes

- `isKeySkippingAllowed` now returns `true` only for `schemas.Anthropic`, replacing the previous denylist approach. This ensures non-Anthropic providers always receive a configured key from the pool.
- The `selectKeyFromProviderForModelWithPool` call site now passes `baseProviderType` instead of `providerKey` to `isKeySkippingAllowed`, so the gate is evaluated against the resolved base provider.
- `SkipKeySelection` is intentionally **not** cleared in `clearAnthropicPassthroughForNonNativeProvider` — it also drives `IsClaudeCodeMaxMode`, which suppresses `x-api-key` on the Anthropic provider. Clearing it during a non-native attempt would cause an Anthropic fallback to send the account key alongside the caller's OAuth token. The flag is gated at the read site instead.
- A new test `TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider` verifies that Anthropic skips key selection while Fireworks (with `UseAnthropicEndpoints`) still selects its own key.
- `TestClearAnthropicPassthroughForNonNativeProvider` is updated to assert that `SkipKeySelection` survives the clear operation and documents why.

## Type of change

- [x] Bug fix

## Affected areas

- [x] Core (Go)
- [x] Providers/Integrations

## How to test

```sh
go test ./core/... -run TestSelectKeyFromProviderForModelWithPool_SkipKeySelectionGatedOnBaseProvider
go test ./core/... -run TestClearAnthropicPassthroughForNonNativeProvider
go test ./...
```

The new test covers the regression directly: with `SkipKeySelection` set and a Fireworks provider, the selected key must be present and must have `UseAnthropicEndpoints = true`. Without this fix, the key pool would be empty and that assertion would fail.

## Breaking changes

- [ ] Yes
- [x] No

## Security considerations

`SkipKeySelection` bypasses key injection entirely, relying on the caller's OAuth token as the upstream credential. Tightening the allowlist to Anthropic-only reduces the surface where a misconfigured or rewritten routing rule could cause a request to be sent without any credential, or with the wrong credential type for the target provider.

## Checklist

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