Skip to content

feat(bedrock): add support for Anthropic Claude V4 models#4701

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1772635340-bedrock-anthropic-v4-support
Open

feat(bedrock): add support for Anthropic Claude V4 models#4701
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1772635340-bedrock-anthropic-v4-support

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 4, 2026

feat(bedrock): add support for Anthropic Claude V4 models

Summary

Adds support for AWS Bedrock's Anthropic Claude V4 model family (Claude Sonnet 4, Opus 4, Opus 4.1, Haiku 4.5, Sonnet 4.5, Opus 4.5). These models use the same Converse API as V3, so the changes are primarily capability detection and configuration — no new API implementation was needed.

Key changes:

  • _strip_region_prefix() static method on BedrockCompletion — strips us./eu./apac./global. region qualifiers from model IDs so capability lookups work uniformly regardless of cross-region inference prefix.
  • get_context_window_size() — added V4 model prefix entries (all 200K tokens), now uses _strip_region_prefix for matching.
  • supports_multimodal() — refactored to use _strip_region_prefix instead of hardcoding region-prefixed model names. Added V4 model prefixes.
  • _is_nova_model() — also updated to use _strip_region_prefix for consistency (minor behavioral change: substring match → prefix match after stripping).
  • LLM_CONTEXT_WINDOW_SIZES in llm.py — added V4 model IDs with us., eu., apac., and bare prefixes.
  • 11 new tests covering V4 model detection, context windows, multimodal support, region prefix handling, function calling, inference config, mocked API calls, and a V3 regression test.

Closes #4700

Review & Testing Checklist for Human

  • Prefix matching order in get_context_window_size(): "anthropic.claude-opus-4" will match opus-4-1 and opus-4-5 via startswith. This is currently fine since all have 200K context, but the pattern is fragile if future models diverge. Verify this is acceptable.
  • EU/APAC region coverage in LLM_CONTEXT_WINDOW_SIZES: The eu. and apac. sections have fewer V4 entries than us. — confirm this matches actual AWS regional availability rather than being an omission.
  • supports_multimodal() refactor: Previously hardcoded us.amazon.nova-* for Nova vision support; now uses _strip_region_prefix which means eu./apac./global. Nova models are also covered. Verify this is a desired side-effect fix.
  • Real Bedrock API test: All 11 new tests use mocks. If you have AWS credentials, try instantiating LLM(model="bedrock/anthropic.claude-sonnet-4-20250514-v1:0") and calling it against real Bedrock to confirm the model IDs are correct.

Test plan

  1. Run the full bedrock test suite: uv run pytest tests/llms/bedrock/test_bedrock.py -vv (39 passed ✅)
  2. Verify lint passes: uv run ruff check lib/crewai/src/crewai/llm.py lib/crewai/src/crewai/llms/providers/bedrock/completion.py lib/crewai/tests/llms/bedrock/test_bedrock.py (all checks passed ✅)
  3. Optional: Test against real AWS Bedrock with a V4 model ID to confirm the implementation actually works end-to-end.

Notes


Note

Medium Risk
Updates Bedrock model capability detection (context window, multimodal, Nova identification) and introduces region-prefix normalization, which could subtly change behavior for existing region-prefixed model IDs if matching assumptions were relied on.

Overview
Adds recognition of Anthropic Claude 4.x Bedrock model IDs (including us./eu./apac./global.-prefixed variants) and maps them to a 200K context window in LLM_CONTEXT_WINDOW_SIZES.

In BedrockCompletion, introduces _strip_region_prefix() and uses it to make get_context_window_size(), supports_multimodal(), and _is_nova_model() work consistently across region-prefixed model IDs; multimodal detection is expanded to include Claude 4.x and simplified to base-model prefixes.

Extends test_bedrock.py with a focused suite covering Claude 4.x routing, context window sizing, multimodal support, region-prefix handling, inference config, mocked calls, Nova detection with prefixes, and a Claude 3.x regression check.

Written by Cursor Bugbot for commit d0da114. This will update automatically on new commits. Configure here.

- Add _strip_region_prefix() to handle us./eu./apac./global. prefixes
- Update get_context_window_size() with V4 model entries (200K tokens)
- Update supports_multimodal() to detect V4 models
- Update _is_nova_model() to use region prefix stripping
- Add V4 model context windows to LLM_CONTEXT_WINDOW_SIZES in llm.py
- Add 11 comprehensive tests covering V4 model detection, context windows,
  multimodal support, region prefixes, function calling, and regression

Closes #4700

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

[FEATURE] Support Bedrock's Anthropic V4 LLM's

0 participants