fix: remove unsupported fields from requests to Bedrock#225
fix: remove unsupported fields from requests to Bedrock#225pawbana wants to merge 1 commit intopb/messages-remove-paramswrapfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
7d8c1ae to
dcc3668
Compare
| // supports the "adaptive" thinking type natively (i.e. Claude 4.6 models). | ||
| // See https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-adaptive-thinking.html | ||
| func bedrockModelSupportsAdaptiveThinking(model string) bool { | ||
| return strings.Contains(model, "anthropic.claude-opus-4-6") || |
There was a problem hiding this comment.
This doesn't match what the docs say:
| return strings.Contains(model, "anthropic.claude-opus-4-6") || | |
| return strings.Contains(model, "anthropic.claude-opus-4-6-v1") || |
|
|
||
| effort := gjson.GetBytes(p, messagesReqPathOutputConfigEffort).String() | ||
|
|
||
| // Effort-to-ratio mapping adapted from OpenRouter: |
There was a problem hiding this comment.
This explains the what, but not the why.
Can you please add more detail about why we're augmenting this value?
|
|
||
| func (p MessagesRequestPayload) delete(path string) (MessagesRequestPayload, error) { | ||
| out, err := sjson.DeleteBytes(p, path) | ||
| return MessagesRequestPayload(out), err |
| var err error | ||
| result, err = result.delete(field) | ||
| if err != nil { | ||
| return p, fmt.Errorf("removing %q: %w", field, err) |
There was a problem hiding this comment.
This isn't enough explanatory detail.
| return p, fmt.Errorf("removing %q: %w", field, err) | |
| return p, fmt.Errorf("removing %q field for Bedrock compatibility: %w", field, err) |
| result := p | ||
| for _, field := range bedrockUnsupportedFields { | ||
| var err error | ||
| result, err = result.delete(field) |
There was a problem hiding this comment.
Nit: doing this once per field means we have to parse the JSON each time.
Probably not a huge problem but I worry about memory usage since this will spill to the heap.
You could consider unmarshaling once into a map, deleting there, and remarshaling.

This PR removes unsupported fields from requests to Bedrock.
Adaptive thinking field is replaced for models that don't support with
type: enabled+budget_tokens: Ncombination.budget_tokensvalue is calculated as a ratio ofmax_tokens.Ratio depends on
output_config.effortvalue, used the same ratio values as OpenRouter does: https://openrouter.ai/docs/guides/best-practices/reasoning-tokens#reasoning-effort-levelFixes: #219