Skip to content

feat: service tier mappings for gemini and anthropic - #3554

Merged
akshaydeo merged 1 commit into
devfrom
05-17-feat_service_tier_mappings_for_gemini_and_anthropic
May 18, 2026
Merged

feat: service tier mappings for gemini and anthropic#3554
akshaydeo merged 1 commit into
devfrom
05-17-feat_service_tier_mappings_for_gemini_and_anthropic

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented May 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds proper service_tier translation between Bifrost's OpenAI-compatible values and the native wire formats for Anthropic and Gemini providers, rather than passing the raw string through unchanged.

Changes

  • Introduced four mapping helpers in the Anthropic provider (MapBifrostServiceTierToAnthropicRequest, MapAnthropicRequestServiceTierToBifrost, MapAnthropicServiceTierToBifrost, MapBifrostServiceTierToAnthropicResponse) to translate between Bifrost values (auto, default, priority, flex) and Anthropic's request values (auto, standard_only) and response values (standard, priority, batch).
  • Applied these mappers in both the chat and responses conversion paths for Anthropic, covering request encoding and response decoding in both directions.
  • Added a ServiceTier typed string and constants (unspecified, flex, standard, priority) to the Gemini types, along with a ServiceTier field on GenerationConfig.
  • Introduced mapBifrostServiceTierToGemini and mapGeminiServiceTierToBifrost helpers and wired them into both the chat and responses parameter conversion paths for Gemini.
  • Added tests covering forward and reverse service tier mapping for Gemini chat, responses, and the reverse-mapping path from a GeminiGenerationRequest back to a BifrostResponsesRequest.

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 test ./core/providers/anthropic/...
go test ./core/providers/gemini/...

The new Gemini tests (TestServiceTierMappingChat, TestServiceTierMappingResponses, TestServiceTierReverseMapping) exercise all tier values in both directions. Verify that:

  • Bifrost "default" → Anthropic request "standard_only", Gemini "standard"
  • Bifrost "auto" / "priority" → Anthropic request "auto"
  • Anthropic response "standard" → Bifrost "default"
  • Gemini "flex" / "priority" round-trip correctly through Bifrost

Breaking changes

  • Yes
  • No

Related issues

Security considerations

None.

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 May 17, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2cfb3088-153e-44cc-8c3d-154916bf47a4

📥 Commits

Reviewing files that changed from the base of the PR and between dd66f43 and d24b9d7.

📒 Files selected for processing (22)
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/bedrock/bedrock_test.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/types.go
  • core/providers/bedrock/utils.go
  • core/providers/gemini/chat.go
  • core/providers/gemini/gemini_test.go
  • core/providers/gemini/responses.go
  • core/providers/gemini/types.go
  • core/providers/gemini/utils.go
  • core/providers/vertex/types.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
  • core/schemas/chatcompletions.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/pricing_test.go
  • plugins/semanticcache/plugin_responses_test.go
✅ Files skipped from review due to trivial changes (1)
  • core/providers/vertex/types.go
🚧 Files skipped from review as they are similar to previous changes (20)
  • plugins/semanticcache/plugin_responses_test.go
  • core/providers/gemini/chat.go
  • core/providers/gemini/types.go
  • core/providers/bedrock/utils.go
  • core/providers/anthropic/chat.go
  • core/providers/gemini/utils.go
  • core/schemas/chatcompletions.go
  • framework/modelcatalog/pricing.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/chat.go
  • core/schemas/responses.go
  • core/providers/anthropic/utils.go
  • core/providers/gemini/responses.go
  • core/providers/gemini/gemini_test.go
  • core/providers/vertex/vertex.go
  • framework/modelcatalog/pricing_test.go
  • core/providers/anthropic/types.go
  • core/providers/bedrock/types.go
  • core/providers/anthropic/responses.go
  • core/providers/bedrock/bedrock_test.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Typed service-tier selection (priority/flex/default/auto) added and consistently propagated across providers; responses may now include the tier used.
    • Provider integrations updated to translate and honor service-tier choices (Anthropic, Bedrock, Gemini, Vertex, etc.).
    • Vertex now requests priority/flex via a header and strips unsupported service-tier fields from payloads.
    • Provider feature flags enabled where supported.
  • Tests

    • Added/updated tests validating service-tier mappings and reverse conversions across requests, responses, and streaming paths.

Walkthrough

Adds typed Bifrost service-tier enums and provider-specific mapping/helpers; propagates mapped tiers across Anthropic, Bedrock, Gemini, and Vertex request/response conversions; updates schemas, pricing, and tests.

Changes

Anthropic Service Tier Mapping

Layer / File(s) Summary
Anthropic mapping helpers
core/providers/anthropic/utils.go
New request/response mapping functions and raw-body stripping logic for Anthropic service_tier when provider feature is disabled.
Anthropic chat conversions
core/providers/anthropic/chat.go
Chat request/response conversions now map service tiers via helpers.
Anthropic responses conversions
core/providers/anthropic/responses.go
Responses request/response conversions map service tiers both directions and initialize Usage when required.
Anthropic feature flags
core/providers/anthropic/types.go
Adds ServiceTier feature flag and enables it for Anthropic, Bedrock, and Azure.

Bedrock Service Tier Typing and Mapping

Layer / File(s) Summary
Bedrock types & mapping
core/providers/bedrock/types.go, core/providers/bedrock/utils.go
Adds BedrockServiceTierType and mapping helpers; maps Bifrost↔Bedrock tiers with sensible fallbacks.
Bedrock conversions
core/providers/bedrock/chat.go, core/providers/bedrock/responses.go
ServiceTier assignments in conversions now use mapping helpers.
Bedrock tests
core/providers/bedrock/bedrock_test.go
Tests updated to use typed schemas.BifrostServiceTier* constants and clarified table entries.

Gemini Service Tier Mapping

Layer / File(s) Summary
Gemini service tier type
core/providers/gemini/types.go
Adds ServiceTier enum and optional serviceTier fields on generation request and usage metadata.
Gemini mapping & conversion
core/providers/gemini/utils.go, core/providers/gemini/responses.go, core/providers/gemini/chat.go
Adds mapping helpers and wires them into generation↔responses conversions and streaming completion logic.
Gemini tests
core/providers/gemini/gemini_test.go
Adds table-driven tests verifying chat/responses mapping and reverse mapping to Bifrost, including nil/unspecified cases.

Schemas and Consumers

Layer / File(s) Summary
Typed BifrostServiceTier and schema updates
core/schemas/chatcompletions.go, core/schemas/responses.go
Introduce BifrostServiceTier enum and retype ServiceTier fields; update WithDefaults to handle enum values.
Pricing and tests updated
framework/modelcatalog/pricing.go, framework/modelcatalog/pricing_test.go
tierFromString accepts typed *schemas.BifrostServiceTier; pricing tests updated to pass enum constants.
Plugin tests
plugins/semanticcache/plugin_responses_test.go
Test updated to set Params.ServiceTier using typed schemas.BifrostServiceTierDefault pointer.

Vertex header forwarding and stripping

Layer / File(s) Summary
Vertex header constant & helper
core/providers/vertex/types.go, core/providers/vertex/utils.go
Adds VertexServiceTierHeader and vertexServiceTierHeaderValue to compute header value for global region.
Vertex integration
core/providers/vertex/vertex.go
Forward service-tier via HTTP header for Gemini/all-digits requests and strip serviceTier from Gemini payloads/raw JSON.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

I hop through code with a tiny cheer,
Mapping tiers both far and near,
Enums snug in every place,
Tests give every mapping grace,
🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: service tier mappings for gemini and anthropic' directly and clearly summarizes the main change: adding service tier translation between Bifrost and native provider formats for Gemini and Anthropic.
Description check ✅ Passed The PR description includes all required template sections: Summary, Changes, Type of change (Feature selected), Affected areas (Core and Providers selected), How to test, Breaking changes (No), and Checklist with relevant items marked.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-17-feat_service_tier_mappings_for_gemini_and_anthropic

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

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 May 17, 2026 18:10
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 17, 2026
@greptile-apps

greptile-apps Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

Safe to merge with minor known gaps; the mapping logic is correct for the common paths but a few edge cases in the Anthropic and Bedrock reverse mappers still return unrecognised Bifrost tier values to callers.

The core mappings, type promotion, and Vertex header injection are all correct and well-tested. However, MapAnthropicServiceTierToBifrost passes "batch" through as a raw BifrostServiceTier (an unrecognised value for downstream clients), and mapBedrockServiceTierToBifrost lets "reserved" fall through despite the comment stating it should map to priority. These gaps were surfaced in prior review rounds and are acknowledged by the team, but they are not yet resolved in this revision.

core/providers/anthropic/utils.go (batch tier passthrough) and core/providers/bedrock/utils.go (reserved tier not mapped to priority)

Important Files Changed

Filename Overview
core/schemas/chatcompletions.go Introduces BifrostServiceTier typed string and constants (auto, default, flex, priority); upgrades ServiceTier fields in BifrostChatResponse and ChatParameters from *string to *BifrostServiceTier.
core/schemas/responses.go Upgrades ServiceTier in BifrostResponsesResponse and ResponsesParameters to typed *BifrostServiceTier; rewrites WithDefaults to preserve valid known tier values and default to "auto" when nil or unrecognised, addressing the previous nil/drop bugs.
core/providers/anthropic/utils.go Adds four service-tier mapping helpers; MapAnthropicServiceTierToBifrost still passes "batch" through as a raw BifrostServiceTier value (acknowledged in previous threads); MapBifrostServiceTierToAnthropicResponse default branch likewise returns unknown values verbatim.
core/providers/anthropic/chat.go Wires the new Anthropic mapping helpers into both request encoding and response decoding for the chat path; nil-guards are consistent.
core/providers/anthropic/responses.go Wires Anthropic mapping helpers into both directions of the responses path; adds AnthropicUsage allocation guard when re-encoding service tier back to Anthropic format.
core/providers/anthropic/types.go Adds ServiceTier bool to ProviderFeatureSupport and marks it true for Anthropic, Bedrock, and Azure; Vertex is intentionally left false since it uses HTTP headers instead.
core/providers/gemini/utils.go Adds mapGeminiServiceTierToBifrost and mapBifrostServiceTierToGemini; BifrostServiceTierAuto falls to default and maps to ServiceTierUnspecified ("unspecified"), which the team confirmed is intentional.
core/providers/gemini/chat.go Wires Gemini service tier mapping into request encoding, response decoding, and the last-chunk streaming path; all inside existing nil guards.
core/providers/gemini/responses.go Adds service tier round-trip in all four directions for the Gemini responses path: request encode, request decode, response encode, response decode, plus the stream close helper.
core/providers/gemini/types.go Adds ServiceTier typed string and four constants on the Gemini side; adds ServiceTier field to GeminiGenerationRequest (top-level) and to GenerateContentResponseUsageMetadata.
core/providers/gemini/gemini_test.go Adds TestServiceTierMappingChat, TestServiceTierMappingResponses, and TestServiceTierReverseMapping covering forward/reverse mapping for all tier values including nil and empty-string edge cases.
core/providers/bedrock/utils.go Adds typed mapBifrostServiceTierToBedrock and mapBedrockServiceTierToBifrost; BedrockServiceTierTypeReserved falls through to passthrough rather than mapping to BifrostServiceTierPriority as the comment states (acknowledged in prior review threads).
core/providers/bedrock/types.go Introduces BedrockServiceTierType typed string with priority, default, flex, and reserved constants; changes BedrockServiceTier.Type from string to the new type.
core/providers/vertex/vertex.go Adds X-Vertex-AI-LLM-Shared-Request-Type header injection for priority/flex tiers in all four request paths (chat, chat-stream, responses, responses-stream); strips serviceTier from the JSON body since Vertex uses the header instead.
core/providers/vertex/utils.go Adds hardcoded model-prefix lists for Vertex priority/flex support and helpers isVertexModelSupportedForTier and vertexServiceTierHeaderValue; custom-model pass-through via IsAllDigitsASCII is a reasonable heuristic.
framework/modelcatalog/pricing.go Updates tierFromString to accept *BifrostServiceTier and switches on typed constants; no behavioural change.

Reviews (7): Last reviewed commit: "feat: service tier mappings for gemini a..." | Re-trigger Greptile

Comment thread core/providers/gemini/utils.go Outdated
Comment thread core/providers/gemini/types.go
Comment thread core/providers/anthropic/utils.go
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from f28d336 to ae06dac Compare May 17, 2026 19:13
@coderabbitai
coderabbitai Bot requested review from akshaydeo and danpiths May 17, 2026 19:15
Comment thread core/schemas/responses.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.

Actionable comments posted: 2

🤖 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/providers/bedrock/utils.go`:
- Around line 91-104: The mapping function mapBedrockServiceTierToBifrost
incorrectly lets the BedrockServiceTierTypeReserved fall through to the default
cast; update the switch in mapBedrockServiceTierToBifrost to include an explicit
case for BedrockServiceTierTypeReserved that returns
schemas.BifrostServiceTierPriority (so "reserved" maps to priority), leaving the
other cases (BedrockServiceTierTypePriority, BedrockServiceTierTypeFlex,
BedrockServiceTierTypeDefault) unchanged and keeping the default cast as a
fallback.

In `@core/schemas/responses.go`:
- Around line 179-185: In WithDefaults(), the current logic only assigns
result.ServiceTier when the incoming resp.ServiceTier is invalid, causing valid
tiers to be dropped; update the logic in the resp.ServiceTier handling so that
if resp.ServiceTier is non-nil and one of the valid enum values
(BifrostServiceTierAuto, BifrostServiceTierDefault, BifrostServiceTierFlex,
BifrostServiceTierPriority) you set result.ServiceTier = new(BifrostServiceTier)
and copy the value from resp.ServiceTier, otherwise set result.ServiceTier to a
default (new(BifrostServiceTierAuto)); keep the nil behavior unchanged.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16418932-b105-4492-89ef-f94517f5c61c

📥 Commits

Reviewing files that changed from the base of the PR and between f28d336 and ae06dac.

📒 Files selected for processing (17)
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/utils.go
  • core/providers/bedrock/bedrock_test.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/types.go
  • core/providers/bedrock/utils.go
  • core/providers/gemini/gemini_test.go
  • core/providers/gemini/responses.go
  • core/providers/gemini/types.go
  • core/providers/gemini/utils.go
  • core/schemas/chatcompletions.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/pricing_test.go
  • plugins/semanticcache/plugin_responses_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • core/providers/gemini/responses.go
  • core/providers/gemini/types.go
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/utils.go
  • core/providers/anthropic/responses.go
  • core/providers/gemini/gemini_test.go

Comment thread core/providers/bedrock/utils.go
Comment thread core/schemas/responses.go
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from ae06dac to 9395231 Compare May 18, 2026 05:13
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 18, 2026
Comment thread core/providers/bedrock/utils.go
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from 9395231 to 10d67be Compare May 18, 2026 06:54

@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

🧹 Nitpick comments (2)
core/providers/gemini/utils.go (2)

1245-1257: ⚡ Quick win

Consider adding an explicit case for BifrostServiceTierAuto.

The default case currently handles unknown Bifrost tiers by returning ServiceTierUnspecified. For clarity and maintainability, add an explicit case:

case schemas.BifrostServiceTierAuto:
    return ServiceTierUnspecified

This makes the mapping intention clear and ensures bidirectional consistency is explicit: Gemini's Unspecified ↔ Bifrost's Auto.

🤖 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/gemini/utils.go` around lines 1245 - 1257, Add an explicit
mapping for the BifrostServiceTierAuto value inside
mapBifrostServiceTierToGemini so it returns ServiceTierUnspecified; update the
switch in mapBifrostServiceTierToGemini to include the case
schemas.BifrostServiceTierAuto returning ServiceTierUnspecified to make the
intent explicit and keep bidirectional mapping consistent with Gemini's
Unspecified.

356-368: ⚡ Quick win

Consider adding an explicit case for ServiceTierUnspecified.

The default case currently handles unknown/unspecified tiers by returning BifrostServiceTierAuto. For clarity and maintainability, add an explicit case:

case ServiceTierUnspecified:
    return schemas.BifrostServiceTierAuto

This makes the mapping intention clear and prevents future tier additions from silently falling through to the auto default.

Also, the comment "OpenAI-compatible BifrostServiceTier" is slightly misleading—Bifrost's service tier enum is provider-agnostic. Consider: "Converts a Gemini ServiceTier to Bifrost's BifrostServiceTier."

🤖 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/gemini/utils.go` around lines 356 - 368, The
mapGeminiServiceTierToBifrost function currently relies on the default branch
for unspecified/unknown tiers; add an explicit case for ServiceTierUnspecified
that returns schemas.BifrostServiceTierAuto to make the intent clear (in the
same switch alongside ServiceTierStandard, ServiceTierFlex,
ServiceTierPriority). Also update the function comment to "Converts a Gemini
ServiceTier to Bifrost's BifrostServiceTier" to avoid implying an
OpenAI-specific mapping; keep the rest of the switch logic unchanged.
🤖 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/providers/gemini/responses.go`:
- Around line 1834-1837: The Completed branch in ToGeminiResponsesStreamResponse
is failing to copy Response.ServiceTier into
streamResp.UsageMetadata.ServiceTier, dropping service_tier for streamed
completed events; update the Completed branch of ToGeminiResponsesStreamResponse
to check Response.ServiceTier and, if present, map it back to Gemini form (use
the inverse mapping, e.g., mapBifrostServiceTierToGemini or equivalent) and
assign it to streamResp.UsageMetadata.ServiceTier (handle nil/pointer conversion
as done when setting completedResp.ServiceTier earlier) so streamed responses
preserve service_tier metadata.

---

Nitpick comments:
In `@core/providers/gemini/utils.go`:
- Around line 1245-1257: Add an explicit mapping for the BifrostServiceTierAuto
value inside mapBifrostServiceTierToGemini so it returns ServiceTierUnspecified;
update the switch in mapBifrostServiceTierToGemini to include the case
schemas.BifrostServiceTierAuto returning ServiceTierUnspecified to make the
intent explicit and keep bidirectional mapping consistent with Gemini's
Unspecified.
- Around line 356-368: The mapGeminiServiceTierToBifrost function currently
relies on the default branch for unspecified/unknown tiers; add an explicit case
for ServiceTierUnspecified that returns schemas.BifrostServiceTierAuto to make
the intent clear (in the same switch alongside ServiceTierStandard,
ServiceTierFlex, ServiceTierPriority). Also update the function comment to
"Converts a Gemini ServiceTier to Bifrost's BifrostServiceTier" to avoid
implying an OpenAI-specific mapping; keep the rest of the switch logic
unchanged.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55800d91-fa97-4981-8fe9-97786b93f7a1

📥 Commits

Reviewing files that changed from the base of the PR and between 9395231 and 10d67be.

📒 Files selected for processing (18)
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/utils.go
  • core/providers/bedrock/bedrock_test.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/types.go
  • core/providers/bedrock/utils.go
  • core/providers/gemini/chat.go
  • core/providers/gemini/gemini_test.go
  • core/providers/gemini/responses.go
  • core/providers/gemini/types.go
  • core/providers/gemini/utils.go
  • core/schemas/chatcompletions.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/pricing_test.go
  • plugins/semanticcache/plugin_responses_test.go
🚧 Files skipped from review as they are similar to previous changes (13)
  • framework/modelcatalog/pricing.go
  • core/providers/bedrock/types.go
  • plugins/semanticcache/plugin_responses_test.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/bedrock_test.go
  • core/schemas/chatcompletions.go
  • core/providers/bedrock/utils.go
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/utils.go
  • core/providers/bedrock/responses.go
  • core/schemas/responses.go
  • core/providers/anthropic/responses.go
  • framework/modelcatalog/pricing_test.go

Comment thread core/providers/gemini/responses.go
Comment thread core/providers/anthropic/utils.go
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from 10d67be to 25ea64e Compare May 18, 2026 07:41
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 18, 2026
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from 25ea64e to dd66f43 Compare May 18, 2026 08:45

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/providers/vertex/vertex.go (1)

2570-2573: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Always strip top-level serviceTier before early returns in raw sanitizer.

Line 2570-2573 returns early when contents is missing/non-array, so the new top-level serviceTier deletion at Line 2602-2607 is skipped. That leaks an unsupported field for valid raw bodies that omit contents.

💡 Suggested fix
 func stripVertexGeminiUnsupportedFieldsRaw(jsonBody []byte) []byte {
   if len(jsonBody) == 0 {
     return jsonBody
   }

+  out := jsonBody
+  // Strip top-level serviceTier first so it applies regardless of contents shape.
+  if providerUtils.JSONFieldExists(out, "serviceTier") {
+    if updated, err := providerUtils.DeleteJSONField(out, "serviceTier"); err == nil {
+      out = updated
+    }
+  }
+
-  contents := gjson.GetBytes(jsonBody, "contents")
+  contents := gjson.GetBytes(out, "contents")
   if !contents.IsArray() {
-    return jsonBody
+    return out
   }

-  out := jsonBody
   contentIndex := 0
   contents.ForEach(func(_, content gjson.Result) bool {
     ...
   })
-
-  // Strip top-level serviceTier — Vertex uses HTTP headers for this, not the request body.
-  if providerUtils.JSONFieldExists(out, "serviceTier") {
-    if updated, err := providerUtils.DeleteJSONField(out, "serviceTier"); err == nil {
-      out = updated
-    }
-  }
   return out
 }

Also applies to: 2602-2607

🤖 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/vertex/vertex.go` around lines 2570 - 2573, The raw sanitizer
currently checks contents via gjson.GetBytes(jsonBody, "contents") and returns
early if it's not an array, which skips the top-level serviceTier removal; move
or duplicate the logic that deletes the top-level "serviceTier" field so it runs
before any early returns (i.e., execute the serviceTier strip immediately after
parsing jsonBody and before the contents check in the same function), and ensure
any other early-return paths in the same sanitizer also call the same removal
routine so "serviceTier" is always stripped for raw bodies.
🤖 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/providers/anthropic/utils.go`:
- Around line 390-396: The raw-path branch removes the "service_tier" JSON field
when features.ServiceTier is false (using providerUtils.JSONFieldExists and
providerUtils.DeleteJSONField) but the typed-path function
stripUnsupportedAnthropicFields still leaves req.ServiceTier set; make their
behavior consistent by updating stripUnsupportedAnthropicFields to clear or
unset req.ServiceTier when features.ServiceTier is false (mirror the same guard
and removal logic), ensuring both code paths strip service_tier for unsupported
providers.

In `@core/providers/vertex/vertex.go`:
- Around line 913-919: The VertexServiceTierHeader is being set whenever
request.Params.ServiceTier exists in multiple places (see the block that uses
headers[VertexServiceTierHeader] = v), which allows Gemma models to receive
unsupported values; update the other two sites to match the guard used at the
earlier location by first checking that provider.networkConfig.ExtraHeaders does
not override VertexServiceTierHeader and that the computed
vertexServiceTierHeaderValue(region, *request.Params.ServiceTier) is only
applied for Gemini/all-digits requests (i.e., replicate the same guard pattern
used around the existing header-setting block that checks
provider.networkConfig.ExtraHeaders and uses vertexServiceTierHeaderValue before
writing headers[VertexServiceTierHeader]); ensure you change the two additional
occurrences where request.Params.ServiceTier is used to set
VertexServiceTierHeader.

---

Outside diff comments:
In `@core/providers/vertex/vertex.go`:
- Around line 2570-2573: The raw sanitizer currently checks contents via
gjson.GetBytes(jsonBody, "contents") and returns early if it's not an array,
which skips the top-level serviceTier removal; move or duplicate the logic that
deletes the top-level "serviceTier" field so it runs before any early returns
(i.e., execute the serviceTier strip immediately after parsing jsonBody and
before the contents check in the same function), and ensure any other
early-return paths in the same sanitizer also call the same removal routine so
"serviceTier" is always stripped for raw bodies.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 002c75e9-fa31-4cce-884f-8e688e0bbb5c

📥 Commits

Reviewing files that changed from the base of the PR and between 25ea64e and dd66f43.

📒 Files selected for processing (22)
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/types.go
  • core/providers/anthropic/utils.go
  • core/providers/bedrock/bedrock_test.go
  • core/providers/bedrock/chat.go
  • core/providers/bedrock/responses.go
  • core/providers/bedrock/types.go
  • core/providers/bedrock/utils.go
  • core/providers/gemini/chat.go
  • core/providers/gemini/gemini_test.go
  • core/providers/gemini/responses.go
  • core/providers/gemini/types.go
  • core/providers/gemini/utils.go
  • core/providers/vertex/types.go
  • core/providers/vertex/utils.go
  • core/providers/vertex/vertex.go
  • core/schemas/chatcompletions.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/pricing_test.go
  • plugins/semanticcache/plugin_responses_test.go
🚧 Files skipped from review as they are similar to previous changes (17)
  • core/providers/bedrock/chat.go
  • framework/modelcatalog/pricing.go
  • core/providers/bedrock/types.go
  • core/providers/gemini/utils.go
  • plugins/semanticcache/plugin_responses_test.go
  • core/providers/gemini/chat.go
  • core/providers/bedrock/utils.go
  • core/providers/bedrock/responses.go
  • core/providers/anthropic/chat.go
  • core/schemas/chatcompletions.go
  • core/providers/bedrock/bedrock_test.go
  • core/providers/gemini/types.go
  • framework/modelcatalog/pricing_test.go
  • core/providers/gemini/gemini_test.go
  • core/providers/gemini/responses.go
  • core/schemas/responses.go
  • core/providers/anthropic/responses.go

Comment thread core/providers/anthropic/utils.go
Comment thread core/providers/vertex/vertex.go Outdated
@TejasGhatte
TejasGhatte force-pushed the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch from dd66f43 to d24b9d7 Compare May 18, 2026 09:24

akshaydeo commented May 18, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • May 18, 1:41 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 18, 1:42 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 811acfc into dev May 18, 2026
15 of 16 checks passed
@akshaydeo
akshaydeo deleted the 05-17-feat_service_tier_mappings_for_gemini_and_anthropic branch May 18, 2026 13:42
akshaydeo pushed a commit that referenced this pull request May 20, 2026
## Summary

Adds proper `service_tier` translation between Bifrost's OpenAI-compatible values and the native wire formats for Anthropic and Gemini providers, rather than passing the raw string through unchanged.

## Changes

- Introduced four mapping helpers in the Anthropic provider (`MapBifrostServiceTierToAnthropicRequest`, `MapAnthropicRequestServiceTierToBifrost`, `MapAnthropicServiceTierToBifrost`, `MapBifrostServiceTierToAnthropicResponse`) to translate between Bifrost values (`auto`, `default`, `priority`, `flex`) and Anthropic's request values (`auto`, `standard_only`) and response values (`standard`, `priority`, `batch`).
- Applied these mappers in both the chat and responses conversion paths for Anthropic, covering request encoding and response decoding in both directions.
- Added a `ServiceTier` typed string and constants (`unspecified`, `flex`, `standard`, `priority`) to the Gemini types, along with a `ServiceTier` field on `GenerationConfig`.
- Introduced `mapBifrostServiceTierToGemini` and `mapGeminiServiceTierToBifrost` helpers and wired them into both the chat and responses parameter conversion paths for Gemini.
- Added tests covering forward and reverse service tier mapping for Gemini chat, responses, and the reverse-mapping path from a `GeminiGenerationRequest` back to a `BifrostResponsesRequest`.

## 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

```sh
go test ./core/providers/anthropic/...
go test ./core/providers/gemini/...
```

The new Gemini tests (`TestServiceTierMappingChat`, `TestServiceTierMappingResponses`, `TestServiceTierReverseMapping`) exercise all tier values in both directions. Verify that:
- Bifrost `"default"` → Anthropic request `"standard_only"`, Gemini `"standard"`
- Bifrost `"auto"` / `"priority"` → Anthropic request `"auto"`
- Anthropic response `"standard"` → Bifrost `"default"`
- Gemini `"flex"` / `"priority"` round-trip correctly through Bifrost

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None.

## 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
@akshaydeo akshaydeo mentioned this pull request May 20, 2026
18 tasks
akshaydeo added a commit that referenced this pull request May 20, 2026
## Summary

This PR cuts the `v1.5.11` / `v1.3.11` release across core, framework, and all plugins, and introduces a new Claude skill (`release-checklist`) for pre-release migration safety auditing.

## Changes

- **`release-checklist` skill** — Adds `.claude/skills/release-checklist/SKILL.md`, a read-only pre-release audit tool that scans Go-defined database migrations changed in a release for high-scale deadlock/lock-contention risks and boot-time-blocking operations. It produces a structured `PASS`/`WARN`/`FAIL` report with a concrete remediation plan per finding. The skill is designed to grow via an extensible Checks Registry.
- **Version bumps** — `core` → `1.5.11`, `framework` → `1.3.11`, `transports` → `1.5.3`, `plugins/governance` → `1.5.11`, `plugins/logging` → `1.5.11`, `plugins/semanticcache` → `1.5.11`, `plugins/otel` → `1.2.11`, `plugins/maxim` → `1.6.11`, `plugins/prompts` → `1.0.11`, and remaining plugins bumped accordingly.
- **Changelogs populated** — All per-package changelogs updated with the full set of features and fixes shipping in this release.

Key highlights in this release:
- Temporary access tokens for scoped, time-limited API access
- MCP per-user OAuth flow refactor
- Bedrock Mantle inference engine support
- Azure Realtime provider with enriched session tracking
- Direct access control (DAC) and virtual key rotation
- Cluster-aware log metadata and per-node usage aggregation
- Feature flag framework
- Config-hash-based file value override of DB on restart
- Semantic cache plugin rewrite
- Numerous streaming stability, Bedrock, Anthropic, and Gemini fixes
- AWS SDK and dependency security updates

## Type of change

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

## Affected areas

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

## How to test

```sh
# Verify version files reflect the new release
cat core/version          # expect 1.5.11
cat framework/version     # expect 1.3.11
cat transports/version    # expect 1.5.3

# Core/Transports
go test ./...
```

To exercise the new `release-checklist` skill, invoke it via Claude with:
```
/release-checklist origin/dev...HEAD
```
Expected output: a structured report with `PASS`/`WARN`/`FAIL` per check and a Remediation Plan table for any findings.

## Screenshots/Recordings

N/A

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

#3603, #3565, #3489, #3334, #3335, #3435, #3554, #3590, #3444, #3198, #3581, #3610, #3599, #3567, #3382, #3461 and others listed in the changelogs.

## Security considerations

- AWS SDK and dependency security updates are included (#3461).
- `FullyRedacted()` for proxy passwords and `MarshalForStorage()` for `ProxyConfig` prevent partial secret leakage in API responses (#3445).
- The `release-checklist` skill is strictly read-only and never modifies files.

## 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)
- [ ] I verified the CI pipeline passes locally if applicable
@akshaydeo akshaydeo mentioned this pull request May 20, 2026
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.

4 participants