Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions core/providers/anthropic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,9 @@ type AnthropicTextRequest struct {
StopSequences []string `json:"stop_sequences,omitempty"`

// Bifrost specific field (only parsed when converting from Provider -> Bifrost request)
Fallbacks []string `json:"fallbacks,omitempty"`
ExtraParams map[string]interface{} `json:"-"`
}
Fallbacks []string `json:"fallbacks,omitempty"`

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *AnthropicTextRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

// IsStreamingRequested implements the StreamingRequest interface
Expand Down Expand Up @@ -374,11 +370,10 @@ type AnthropicMessageRequest struct {
ServiceTier *string `json:"service_tier,omitempty"` // "auto" or "standard_only"
InferenceGeo *string `json:"inference_geo,omitempty"` // the geographic region for inference processing. If not specified, the workspace's default_inference_geo is used.
ContextManagement *ContextManagement `json:"context_management,omitempty"`
Container *AnthropicContainer `json:"container,omitempty"` // string id OR object with skills[]; skills require skills-2025-10-02 beta
Diagnostics *AnthropicDiagnostics `json:"diagnostics,omitempty"` // cache diagnostics opt-in; requires cache-diagnosis-2026-04-07 beta (Anthropic API only)
Container *AnthropicContainer `json:"container,omitempty"` // string id OR object with skills[]; skills require skills-2025-10-02 beta
Diagnostics *AnthropicDiagnostics `json:"diagnostics,omitempty"` // cache diagnostics opt-in; requires cache-diagnosis-2026-04-07 beta (Anthropic API only)

// Extra params for advanced use cases
ExtraParams map[string]interface{} `json:"-"`
providerUtils.ExtraParamsMixin

// Bifrost specific field (only parsed when converting from Provider -> Bifrost request)
Fallbacks []string `json:"fallbacks,omitempty"`
Expand All @@ -392,11 +387,6 @@ func (req *AnthropicMessageRequest) SetStripCacheControlScope(strip bool) {
req.stripCacheControlScope = strip
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *AnthropicMessageRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
}

type AnthropicMetaData struct {
UserID *string `json:"user_id"`
}
Expand Down
12 changes: 6 additions & 6 deletions core/providers/bedrock/bedrock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3479,9 +3479,9 @@ func TestAnthropicOrderedOutputConfigRoundTripsReasoning(t *testing.T) {
schemas.KV("effort", "medium"),
)),
),
ExtraParams: map[string]any{
"reasoning_summary": "auto",
},
}
request.ExtraParams = map[string]any{
"reasoning_summary": "auto",
}

ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
Expand Down Expand Up @@ -3525,9 +3525,9 @@ func TestAnthropicOutputConfigFormatStillFallsBackToBudgetTokensForReasoning(t *
)),
)),
),
ExtraParams: map[string]any{
"reasoning_summary": "auto",
},
}
request.ExtraParams = map[string]any{
"reasoning_summary": "auto",
}

ctx := schemas.NewBifrostContext(context.Background(), schemas.NoDeadline)
Expand Down
15 changes: 5 additions & 10 deletions core/providers/bedrock/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import (
"github.com/maximhq/bifrost/core/schemas"
)

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (r *BedrockInvokeRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
}

// IsStreamingRequested implements the StreamingRequest interface
func (r *BedrockInvokeRequest) IsStreamingRequested() bool {
return r.Stream
Expand Down Expand Up @@ -225,11 +220,11 @@ func (r *BedrockInvokeRequest) IsCohereCommandRRequest() bool {
// so we can reuse ToBifrostResponsesRequest() for messages-based requests.
func (r *BedrockInvokeRequest) ToBedrockConverseRequest() *BedrockConverseRequest {
converseReq := &BedrockConverseRequest{
ModelID: r.ModelID,
Messages: r.Messages,
Stream: r.Stream,
ExtraParams: r.ExtraParams,
ModelID: r.ModelID,
Messages: r.Messages,
Stream: r.Stream,
}
converseReq.ExtraParams = r.ExtraParams

// Convert system field: interface{} → []BedrockSystemMessage
converseReq.System = r.parseSystemMessages()
Expand Down Expand Up @@ -375,8 +370,8 @@ func (r *BedrockInvokeRequest) ToBifrostTextCompletionRequest(ctx *schemas.Bifro
System: r.System,
AnthropicVersion: r.AnthropicVersion,
Stream: r.Stream,
ExtraParams: r.ExtraParams,
}
textReq.ExtraParams = r.ExtraParams
return textReq.ToBifrostTextCompletionRequest(ctx)
}

Expand Down
8 changes: 2 additions & 6 deletions core/providers/bedrock/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ type BedrockRerankRequest struct {
Queries []BedrockRerankQuery `json:"queries"`
Sources []BedrockRerankSource `json:"sources"`
RerankingConfiguration BedrockRerankingConfiguration `json:"rerankingConfiguration"`
}

// GetExtraParams implements RequestBodyWithExtraParams.
func (*BedrockRerankRequest) GetExtraParams() map[string]interface{} {
return nil
providerUtils.ExtraParamsMixin
}

const (
Expand Down Expand Up @@ -127,4 +123,4 @@ func (response *BedrockListModelsResponse) ToBifrostListModelsResponse(providerK
pipeline.BackfillModels(included)...)

return bifrostResponse
}
}
101 changes: 29 additions & 72 deletions core/providers/bedrock/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

"github.com/bytedance/sonic"
providerUtils "github.com/maximhq/bifrost/core/providers/utils"
"github.com/maximhq/bifrost/core/schemas"
)

Expand Down Expand Up @@ -47,16 +48,11 @@ type BedrockTextCompletionRequest struct {
StopSequences []string `json:"stop_sequences,omitempty"` // Stop sequences (Anthropic format)

// Messages API parameters (Anthropic Claude 3)
Messages []BedrockMessage `json:"messages,omitempty"`
System interface{} `json:"system,omitempty"`
AnthropicVersion string `json:"anthropic_version,omitempty"`
Stream bool `json:"-"` // Whether streaming is requested (internal)
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (r *BedrockTextCompletionRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
Messages []BedrockMessage `json:"messages,omitempty"`
System interface{} `json:"system,omitempty"`
AnthropicVersion string `json:"anthropic_version,omitempty"`
Stream bool `json:"-"` // Whether streaming is requested (internal)
providerUtils.ExtraParamsMixin
}

// IsStreamingRequested implements the StreamingRequest interface
Expand Down Expand Up @@ -96,17 +92,12 @@ type BedrockConverseRequest struct {
Stream bool `json:"-"` // Whether streaming is requested (internal, not in JSON)

// Extra params for advanced use cases
ExtraParams map[string]interface{} `json:"-"`
providerUtils.ExtraParamsMixin

// Bifrost specific field (only parsed when converting from Provider -> Bifrost request)
Fallbacks []string `json:"fallbacks,omitempty"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (r *BedrockConverseRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
}

// IsStreamingRequested implements the StreamingRequest interface
func (r *BedrockConverseRequest) IsStreamingRequested() bool {
return r.Stream
Expand Down Expand Up @@ -292,10 +283,10 @@ type BedrockS3Location struct {

// BedrockToolUse represents a tool use request
type BedrockToolUse struct {
ToolUseID string `json:"toolUseId"` // Required: Unique identifier for this tool use
Name string `json:"name"` // Required: Name of the tool to use
Input json.RawMessage `json:"input"` // Required: Input parameters for the tool (json.RawMessage preserves key ordering for prompt caching)
Type string `json:"type,omitempty"` // Optional: "server_tool_use" for Nova system tools
ToolUseID string `json:"toolUseId"` // Required: Unique identifier for this tool use
Name string `json:"name"` // Required: Name of the tool to use
Input json.RawMessage `json:"input"` // Required: Input parameters for the tool (json.RawMessage preserves key ordering for prompt caching)
Type string `json:"type,omitempty"` // Optional: "server_tool_use" for Nova system tools
}

// BedrockToolResult represents the result of a tool use
Expand Down Expand Up @@ -524,7 +515,7 @@ type BedrockGuardrailTrace struct {

// BedrockGuardrailAssessment represents a guardrail assessment
type BedrockGuardrailAssessment struct {
AppliedGuardrailDetails *BedrockGuardrailAppliedDetails `json:"appliedGuardrailDetails,omitempty"`
AppliedGuardrailDetails *BedrockGuardrailAppliedDetails `json:"appliedGuardrailDetails,omitempty"`
AutomatedReasoningPolicy *BedrockGuardrailAutomatedReasoningPolicy `json:"automatedReasoningPolicy,omitempty"`
ContentPolicy *BedrockGuardrailContentPolicy `json:"contentPolicy,omitempty"`
ContextualGroundingPolicy *BedrockGuardrailContextualGroundingPolicy `json:"contextualGroundingPolicy,omitempty"`
Expand Down Expand Up @@ -843,15 +834,10 @@ type BedrockMetadataEvent struct {

// BedrockTitanEmbeddingRequest represents a Bedrock Titan embedding request
type BedrockTitanEmbeddingRequest struct {
InputText string `json:"inputText"` // Required: Text to embed
Dimensions *int `json:"dimensions,omitempty"` // Optional: 256, 512, or 1024 (titan-embed-text-v2 only)
Normalize *bool `json:"normalize,omitempty"` // Optional: normalize the embedding
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *BedrockTitanEmbeddingRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
InputText string `json:"inputText"` // Required: Text to embed
Dimensions *int `json:"dimensions,omitempty"` // Optional: 256, 512, or 1024 (titan-embed-text-v2 only)
Normalize *bool `json:"normalize,omitempty"` // Optional: normalize the embedding
providerUtils.ExtraParamsMixin
}

// BedrockTitanEmbeddingResponse represents a Bedrock Titan embedding response
Expand Down Expand Up @@ -888,12 +874,7 @@ type BedrockCohereEmbeddingRequest struct {
OutputDimension *int `json:"output_dimension,omitempty"` // 256, 512, 1024, or 1536
MaxTokens *int `json:"max_tokens,omitempty"` // max 128000
Truncate *string `json:"truncate,omitempty"` // NONE, LEFT, or RIGHT
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *BedrockCohereEmbeddingRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

// BedrockCohereEmbeddingResponse handles both Bedrock Cohere embedding response shapes.
Expand All @@ -918,12 +899,7 @@ type BedrockImageGenerationRequest struct {
TaskType *string `json:"taskType"` // Should be "TEXT_IMAGE"
TextToImageParams *BedrockTextToImageParams `json:"textToImageParams"` // Parameters for text-to-image
ImageGenerationConfig *ImageGenerationConfig `json:"imageGenerationConfig"` // Image generation config
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *BedrockImageGenerationRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

type BedrockTextToImageParams struct {
Expand All @@ -946,12 +922,7 @@ type BedrockImageVariationRequest struct {
TaskType *string `json:"taskType"` // Should be "IMAGE_VARIATION"
ImageVariationParams *BedrockImageVariationParams `json:"imageVariationParams"` // Parameters for image variation
ImageGenerationConfig *ImageGenerationConfig `json:"imageGenerationConfig"` // Image generation config (reused)
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *BedrockImageVariationRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

type BedrockImageVariationParams struct {
Expand All @@ -968,12 +939,7 @@ type BedrockImageEditRequest struct {
OutPaintingParams *BedrockOutPaintingParams `json:"outPaintingParams,omitempty"`
BackgroundRemovalParams *BedrockBackgroundRemovalParams `json:"backgroundRemovalParams,omitempty"`
ImageGenerationConfig *ImageGenerationConfig `json:"imageGenerationConfig,omitempty"` // Used by INPAINTING and OUTPAINTING
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *BedrockImageEditRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

type BedrockInPaintingParams struct {
Expand Down Expand Up @@ -1002,17 +968,12 @@ type BedrockBackgroundRemovalParams struct {
// StabilityAIImageGenerationRequest represents the request format for Stability AI models on Bedrock
// (e.g. stability.stable-image-core-v1:1, stability.stable-image-ultra-v1:1)
type StabilityAIImageGenerationRequest struct {
Prompt string `json:"prompt"`
AspectRatio *string `json:"aspect_ratio,omitempty"`
OutputFormat *string `json:"output_format,omitempty"`
Seed *int `json:"seed,omitempty"`
NegativePrompt *string `json:"negative_prompt,omitempty"`
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams implements the RequestBodyWithExtraParams interface
func (req *StabilityAIImageGenerationRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
Prompt string `json:"prompt"`
AspectRatio *string `json:"aspect_ratio,omitempty"`
OutputFormat *string `json:"output_format,omitempty"`
Seed *int `json:"seed,omitempty"`
NegativePrompt *string `json:"negative_prompt,omitempty"`
providerUtils.ExtraParamsMixin
}

// StabilityAIImageEditRequest is the flat JSON body for Stability AI image-edit models on Bedrock.
Expand Down Expand Up @@ -1057,11 +1018,7 @@ type StabilityAIImageEditRequest struct {
CompositionFidelity *float64 `json:"composition_fidelity,omitempty"`
ChangeStrength *float64 `json:"change_strength,omitempty"`

ExtraParams map[string]interface{} `json:"-"`
}

func (req *StabilityAIImageEditRequest) GetExtraParams() map[string]interface{} {
return req.ExtraParams
providerUtils.ExtraParamsMixin
}

// BedrockImageGenerationResponse represents a Bedrock image generation response.
Expand Down Expand Up @@ -1296,8 +1253,8 @@ type BedrockInvokeRequest struct {
Inputs []BedrockCohereEmbeddingInput `json:"inputs,omitempty"` // Cohere embed: mixed text+image inputs

// ==================== INTERNAL ====================
Stream bool `json:"-"`
ExtraParams map[string]interface{} `json:"-"`
Stream bool `json:"-"`
providerUtils.ExtraParamsMixin
}

// BedrockCohereRMessage represents a Cohere Command R/R+ chat history message
Expand Down
19 changes: 7 additions & 12 deletions core/providers/cohere/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import (

// CohereRerankRequest represents a Cohere rerank API request.
type CohereRerankRequest struct {
Model string `json:"model"`
Query string `json:"query"`
Documents []string `json:"documents"`
TopN *int `json:"top_n,omitempty"`
MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty"`
Priority *int `json:"priority,omitempty"`
ExtraParams map[string]interface{} `json:"-"`
}

// GetExtraParams returns extra parameters for the rerank request.
func (r *CohereRerankRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
Model string `json:"model"`
Query string `json:"query"`
Documents []string `json:"documents"`
TopN *int `json:"top_n,omitempty"`
MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty"`
Priority *int `json:"priority,omitempty"`
providerUtils.ExtraParamsMixin
}

// CohereRerankResult represents a single result from Cohere rerank.
Expand Down
22 changes: 5 additions & 17 deletions core/providers/cohere/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ type CohereChatRequest struct {
StrictToolChoice *bool `json:"strict_tool_choice,omitempty"` // Optional: Strict tool choice
Thinking *CohereThinking `json:"thinking,omitempty"` // Optional: Reasoning configuration
ResponseFormat *CohereResponseFormat `json:"response_format,omitempty"` // Optional: Format for the response
ExtraParams map[string]interface{} `json:"-"` // Optional: Extra parameters
providerUtils.ExtraParamsMixin
}

// IsStreamingRequested implements the StreamingRequest interface
func (r *CohereChatRequest) IsStreamingRequested() bool {
return r.Stream != nil && *r.Stream
}

func (r *CohereChatRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
}

type CohereChatRequestTool struct {
Type string `json:"type"` // always "function"
Function CohereChatRequestFunction `json:"function"`
Expand Down Expand Up @@ -252,13 +248,9 @@ type CohereTool struct {

// CohereCountTokensRequest represents a Cohere tokenize request
type CohereCountTokensRequest struct {
Model string `json:"model"` // Required: Model whose tokenizer should be used
Text string `json:"text"` // Required: Text to tokenize (1-65536 chars)
ExtraParams map[string]interface{} `json:"-"` // Optional: Extra parameters
}

func (r *CohereCountTokensRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
Model string `json:"model"` // Required: Model whose tokenizer should be used
Text string `json:"text"` // Required: Text to tokenize (1-65536 chars)
providerUtils.ExtraParamsMixin
}

// CohereEmbeddingRequest represents a Cohere embedding request
Expand All @@ -272,11 +264,7 @@ type CohereEmbeddingRequest struct {
OutputDimension *int `json:"output_dimension,omitempty"` // Optional: Embedding dimensions (256, 512, 1024, 1536)
EmbeddingTypes []string `json:"embedding_types,omitempty"` // Optional: Types of embeddings to return
Truncate *string `json:"truncate,omitempty"` // Optional: How to handle long inputs
ExtraParams map[string]interface{} `json:"-"` // Optional: Extra parameters
}

func (r *CohereEmbeddingRequest) GetExtraParams() map[string]interface{} {
return r.ExtraParams
providerUtils.ExtraParamsMixin
}

// CohereEmbeddingInput represents a mixed text/image input
Expand Down
Loading