MCPcopy Index your code
hub / github.com/coder/coder / augmentRequestForBedrock

Method augmentRequestForBedrock

aibridge/intercept/messages/base.go:352–420  ·  view source on GitHub ↗

augmentRequestForBedrock will change the model used for the request since AWS Bedrock doesn't support Anthropics' model names. It also converts adaptive thinking to enabled with a budget for models that don't support adaptive thinking natively, or enabled thinking to adaptive for models that only su

()

Source from the content-addressed store, hash-verified

350// don't support adaptive thinking natively, or enabled thinking to adaptive for models that only support
351// adaptive (Opus 4.7+).
352func (i *interceptionBase) augmentRequestForBedrock() {
353 if i.bedrockCfg == nil {
354 return
355 }
356
357 model := i.Model()
358 updated, err := i.reqPayload.withModel(model)
359 if err != nil {
360 i.logger.Warn(context.Background(), "failed to set model in request payload for Bedrock", slog.Error(err))
361 return
362 }
363 i.reqPayload = updated
364
365 switch {
366 case bedrockModelRequiresAdaptiveThinking(model):
367 // Symmetric conversion for adaptive-only models (Opus 4.7+): rewrite
368 // thinking.type "enabled" with budget_tokens to the "adaptive" shape,
369 // since Bedrock returns 400 for these models when the legacy shape is
370 // used. Claude Code falls back to the legacy shape when it cannot
371 // read the upstream model's capability metadata (which is the case
372 // when AI Bridge is in the path).
373 updated, err = i.reqPayload.convertEnabledThinkingForBedrock()
374 if err != nil {
375 i.logger.Warn(context.Background(), "failed to convert enabled thinking for Bedrock", slog.Error(err))
376 return
377 }
378 i.reqPayload = updated
379 case !bedrockModelSupportsAdaptiveThinking(model):
380 updated, err = i.reqPayload.convertAdaptiveThinkingForBedrock()
381 if err != nil {
382 i.logger.Warn(context.Background(), "failed to convert adaptive thinking for Bedrock", slog.Error(err))
383 return
384 }
385 i.reqPayload = updated
386 }
387
388 // Filter Anthropic-Beta header to only include Bedrock-supported flags
389 // that the current model supports.
390 if i.clientHeaders != nil {
391 filterBedrockBetaFlags(i.clientHeaders, model)
392 }
393
394 // Strip body fields that Bedrock does not accept. Adaptive-only models
395 // (Opus 4.7+) support output_config natively without a beta flag, so
396 // keep it for those models even when the effort-2025-11-24 flag is
397 // absent from the request.
398 var exemptFields []string
399 if bedrockModelRequiresAdaptiveThinking(model) {
400 exemptFields = append(exemptFields, messagesReqPathOutputConfig)
401 }
402 updated, err = i.reqPayload.removeUnsupportedBedrockFields(i.clientHeaders, exemptFields...)
403 if err != nil {
404 i.logger.Warn(context.Background(), "failed to remove unsupported fields for Bedrock", slog.Error(err))
405 return
406 }
407 i.reqPayload = updated
408
409 // Adaptive-only models accept output_config but reject some of its