@@ -47,10 +47,12 @@ const (
4747// compile-time type validation
4848var _ requesthandling.RequestProcessor = & APITranslationPlugin {}
4949var _ requesthandling.ResponseProcessor = & APITranslationPlugin {}
50+ var _ requesthandling.ResponseBodyRequirement = & APITranslationPlugin {}
5051
5152// apiTranslationConfig holds configuration for provider-specific translators.
5253type apiTranslationConfig struct {
53- VertexOpenAI * vertexOpenAIConfig `json:"vertexOpenAI,omitempty"`
54+ VertexOpenAI * vertexOpenAIConfig `json:"vertexOpenAI,omitempty"`
55+ BodyProcessingMode string `json:"responseBodyMode,omitempty"`
5456}
5557
5658type vertexOpenAIConfig struct {
@@ -100,27 +102,34 @@ func NewAPITranslationPlugin(ctx context.Context, config apiTranslationConfig) (
100102 )
101103 }
102104
105+ bodyMode , err := parseBodyProcessingMode (config .BodyProcessingMode )
106+ if err != nil {
107+ return nil , err
108+ }
109+
103110 keys := make ([]string , 0 , len (providers ))
104111 for key := range providers {
105112 keys = append (keys , key )
106113 }
107114
108- log .FromContext (ctx ).V (logutil .VERBOSE ).Info ("plugin initialized" , "providers" , strings .Join (keys , "," ))
115+ log .FromContext (ctx ).V (logutil .VERBOSE ).Info ("plugin initialized" , "providers" , strings .Join (keys , "," ), "responseBodyMode" , bodyMode )
109116
110117 return & APITranslationPlugin {
111118 typedName : plugin.TypedName {
112119 Type : APITranslationPluginType ,
113120 Name : APITranslationPluginType ,
114121 },
115- providers : providers ,
122+ providers : providers ,
123+ responseBodyMode : bodyMode ,
116124 }, nil
117125}
118126
119127// APITranslationPlugin translates inference API requests and responses between
120128// OpenAI Chat Completions format and provider-native formats (e.g., Anthropic Messages API).
121129type APITranslationPlugin struct {
122- typedName plugin.TypedName
123- providers map [string ]translator.Translator // map from provider name to translator interface
130+ typedName plugin.TypedName
131+ providers map [string ]translator.Translator // map from provider name to translator interface
132+ responseBodyMode requesthandling.BodyProcessingMode
124133}
125134
126135// TypedName returns the type and name tuple of this plugin instance.
@@ -134,6 +143,25 @@ func (p *APITranslationPlugin) WithName(name string) *APITranslationPlugin {
134143 return p
135144}
136145
146+ // BodyProcessingMode returns the configured response body mode.
147+ // Defaults to Full. Configurable via the "responseBodyMode" parameter.
148+ func (p * APITranslationPlugin ) BodyProcessingMode () requesthandling.BodyProcessingMode {
149+ return p .responseBodyMode
150+ }
151+
152+ func parseBodyProcessingMode (s string ) (requesthandling.BodyProcessingMode , error ) {
153+ switch strings .ToLower (s ) {
154+ case "" , "full" :
155+ return requesthandling .Full , nil
156+ case "chunked" :
157+ return requesthandling .Chunks , nil
158+ case "none" :
159+ return requesthandling .Skip , nil
160+ default :
161+ return 0 , fmt .Errorf ("invalid responseBodyMode %q (valid: none, chunked, full)" , s )
162+ }
163+ }
164+
137165// ProcessRequest reads the provider from CycleState (set by an upstream plugin) and translates
138166// the request body from OpenAI format to the provider's native format if needed.
139167// When the incoming client format matches the upstream API format (passthrough mode),
0 commit comments