Skip to content

Conversation

@mfenderov
Copy link
Contributor

@mfenderov mfenderov commented Dec 6, 2025

Add AWS Bedrock provider using the Converse API. Supports all Bedrock models (Claude, Titan, Llama, Mistral) with AWS credential chain and Bedrock API key authentication.

models:
  claude:
    provider: bedrock
    model: global.anthropic.claude-sonnet-4-5-20250929-v1:0
    provider_opts:
      region: us-east-1

This is an initial implementation to keep PR size manageable. Future additions: prompt caching, IAM policy examples, troubleshooting docs.

P.S.
There's an existing PR #542 that also adds Bedrock support, but there's been no movement in more than a month.

@mfenderov mfenderov marked this pull request as ready for review December 6, 2025 13:00
@mfenderov mfenderov requested a review from a team as a code owner December 6, 2025 13:00
@mfenderov mfenderov force-pushed the feature/bedrock-provider branch from 254c74e to d657e41 Compare December 6, 2025 13:48
@inercia
Copy link

inercia commented Dec 11, 2025

Seems related to #542

@krissetto
Copy link
Contributor

Finally got around to testing things with bedrock setup properly, sorry for the delay.

This provider seems to work, but i noticed that cost/usage information is not being handled properly, the TUI shows both tokens and cost at zero. The models.dev data we use for pricing should include plenty of bedrock models, so we can use that and consider it good enough. With usage tracked, I think it'd be enough to merge this for now

mfenderov and others added 6 commits January 8, 2026 13:54
Implement Bedrock provider using AWS SDK v2 with:
- Default credential chain (env vars, shared config, IAM roles)
- Support for all Bedrock models via Converse API
- Cross-region inference profiles
- provider_opts: region, profile, role_arn, external_id, endpoint_url
- Streaming responses with tool calling support

New files:
- pkg/model/provider/bedrock/client.go - Main client
- pkg/model/provider/bedrock/convert.go - Message/tool conversion
- pkg/model/provider/bedrock/adapter.go - Stream adapter
- pkg/model/provider/bedrock/client_test.go - Unit tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add prerequisites section with link to Bedrock Console
- Link to AWS SDK credential chain documentation
- Clarify authentication flow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add bearer token auth support (AWS_BEARER_TOKEN_BEDROCK or api_key provider_opt)
- Update default model to global.anthropic.claude-sonnet-4-5-20250929-v1:0
- Add inference profile prefix documentation (global., us., eu.)
- Add unit test for bearer token transport
- Update docs with API key authentication section

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Bedrock's Converse API requires that multiple tool results be grouped
into a single user message. The previous implementation created
separate messages for each tool result, causing ValidationException:
"Expected toolResult blocks at messages.N.content for the following Ids"

Changes:
- Modified loop to use index-based iteration for index manipulation
- Added grouping logic for consecutive MessageRoleTool messages
- Added comprehensive test for multi-tool result scenarios

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add 7 new tests to improve coverage:
- TestConvertImageURL_NonDataURL
- TestConvertImageURL_InvalidDataURLFormat
- TestConvertImageURL_InvalidBase64
- TestConvertImageURL_AllFormats (table-driven)
- TestConvertImageURL_ValidImage
- TestNewClient_NilConfig
- TestNewClient_WrongProvider

These tests cover critical error paths identified in code review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add pr-reviewer-bedrock.yaml - a multi-agent PR review toolkit that
mirrors Claude Code's pr-review-toolkit plugin with 6 specialized agents:
- code-reviewer: Guidelines compliance and bug detection
- silent-failure-hunter: Error handling audit
- code-simplifier: Code simplification
- comment-analyzer: Comment quality analysis
- test-analyzer: Test coverage analysis
- type-analyzer: Type design and invariants

Also adds 8 new tests for Bedrock provider:
- buildAWSConfig tests (region precedence, env vs provider_opts)
- NewClient validation tests (valid config, bearer token paths)
- getProviderOpt type mismatch edge cases
- Interface compliance assertion

Test coverage: Bedrock now at 58% (highest of all providers).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@mfenderov mfenderov force-pushed the feature/bedrock-provider branch from 00b6939 to f548e0c Compare January 8, 2026 13:01
- Update env.Get() calls to handle new (string, bool) return signature
- Fix MaxTokens pointer dereference (*int64 instead of int64)
- Update mockEnvProvider in tests to match new interface
- Remove version field from example (examples shouldn't define version)
- Fix typo in example comment

🤖 Co-Authored-By: Claude <[email protected]>
- Add support for cache tokens (CacheReadInputTokens, CacheWriteInputTokens)
- Add debug logging to help diagnose usage tracking issues
- Add tests for deref helper functions and usage conversion

This addresses PR feedback about TUI showing zero tokens/cost.

🤖 Co-Authored-By: Claude <[email protected]>
Match models.dev naming convention for automatic pricing lookup.

🤖 Co-Authored-By: Claude <[email protected]>
@mfenderov mfenderov requested a review from krissetto January 8, 2026 14:21
Address review feedback:
- Remove amazon-bedrock skip since models.dev has pricing data
- Add amazon-bedrock to TestDefaultModels expected providers
- Improve dmr skip comment to explain why (local models)

🤖 Co-Authored-By: Claude <[email protected]>
@krissetto
Copy link
Contributor

After that last issue regarding the api_key, the rest looks good and I'm ready to merge :)

Replace api_key provider_opt with token_key field for Bedrock authentication.
This aligns with other providers and keeps agent configs shareable by storing
env var names instead of secrets directly in YAML.

Changes:
- Use cfg.TokenKey to specify custom env var name for bearer token
- Default to AWS_BEARER_TOKEN_BEDROCK if token_key not specified
- Add debug logging when token_key is configured but env var is empty
- Update docs to show token_key usage pattern
- Fix test to use new TokenKey field

Addresses @krissetto's review feedback on PR docker#1045.

🤖 Co-Authored-By: Claude <[email protected]>
@mfenderov mfenderov requested a review from krissetto January 8, 2026 17:30
@krissetto krissetto merged commit fb290a4 into docker:main Jan 8, 2026
5 checks passed
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