feat(bedrock): add Anthropic Claude 4 support (fixes #5549)#5551
Closed
devin-ai-integration[bot] wants to merge 1 commit into
Closed
feat(bedrock): add Anthropic Claude 4 support (fixes #5549)#5551devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…models Fixes #5549 — adds Bedrock cross-region inference profile IDs for the Claude 4 family (Sonnet 4/4.5, Opus 4/4.1/4.5, Haiku 4.5) to BEDROCK_MODELS and BedrockModels so provider inference and validation work out-of-the-box for these identifiers. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5549. Adds Anthropic Claude 4 Bedrock cross-region inference profile model IDs to
BEDROCK_MODELS(and theBedrockModelsLiteraltype alias) inlib/crewai/src/crewai/llms/constants.py.On AWS Bedrock, the Claude 4 family (Sonnet 4 / 4.5, Opus 4 / 4.1 / 4.5, Haiku 4.5) is only invocable through cross-region inference profile IDs (e.g.
us.anthropic.claude-sonnet-4-5-20250929-v1:0,eu.anthropic.claude-sonnet-4-20250514-v1:0,global.anthropic.claude-haiku-4-5-20251001-v1:0), not the bareanthropic.claude-*IDs. Before this change those inference profile IDs were absent fromBEDROCK_MODELS, so:LLM._infer_provider_from_model("us.anthropic.claude-sonnet-4-5-20250929-v1:0")returned the default"openai"instead of"bedrock".bedrock/and/or specifyprovider="bedrock"to route the call correctly.The fix lists the full Claude 4 inference-profile IDs across all Bedrock regional prefixes currently catalogued in LiteLLM's
model_prices_and_context_window.json(us.,us-gov.,eu.,apac.,au.,jp.,global.).Model IDs added (to both
BedrockModelsandBEDROCK_MODELS):us.anthropic.claude-sonnet-4-20250514-v1:0,us.anthropic.claude-sonnet-4-5-20250929-v1:0us.anthropic.claude-opus-4-20250514-v1:0,us.anthropic.claude-opus-4-1-20250805-v1:0,us.anthropic.claude-opus-4-5-20251101-v1:0us.anthropic.claude-haiku-4-5-20251001-v1:0eu.anthropic.claude-{sonnet,opus,haiku}-4-*-v1:0variantsapac.anthropic.claude-{sonnet,haiku}-4-*-v1:0,au.anthropic.claude-{sonnet,haiku}-4-5-*-v1:0,jp.anthropic.claude-{sonnet,haiku}-4-5-*-v1:0global.anthropic.claude-{sonnet,opus,haiku}-4-*-v1:0us-gov.anthropic.claude-sonnet-4-5-20250929-v1:0Tests (
lib/crewai/tests/test_llm.py):test_validate_model_in_constantswith Bedrock Claude 4 cross-region inference-profile assertions.test_bedrock_claude_4_models_in_constantsverifying both direct IDs and inference profiles are present inBEDROCK_MODELS.test_infer_provider_for_bedrock_claude_4_modelsverifying_infer_provider_from_modelreturns"bedrock"for Claude 4 direct IDs and cross-region inference profiles.All three tests pass locally (
uv run pytest lib/crewai/tests/test_llm.py::test_validate_model_in_constants ::test_bedrock_claude_4_models_in_constants ::test_infer_provider_for_bedrock_claude_4_models). Ruff and mypy pass on the changed files.Review & Testing Checklist for Human
model_prices_and_context_window.json, which may lag real Bedrock availability by region). If any of these aren't yet generally available in your regions, they can still be listed here — they simply won't resolve at call-time — but flag any you'd rather defer.us.anthropic.claude-opus-4-7,global.anthropic.claude-sonnet-4-6) are not included — they carry 2026 release dates and aren't generally available yet. If you'd like those added now, say the word.LLM(model="bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0")completes successfully end-to-end. I only validated the static constants/provider-inference behavior, not a live Bedrock invocation (that requires AWS credentials and model access).Notes
_matches_provider_patternfor bedrock — its existing"." in model_lowerfallback already accepts these IDs, so validation wasn't the blocker. The fix is specifically about_infer_provider_from_modeland keeping theLiteraltype alias accurate.mainand adds the inference-profile IDs plus tests. Happy to close either side depending on your preference.Link to Devin session: https://app.devin.ai/sessions/e0c7012d0e26488ab18765a172e71307
Note
Low Risk
Low risk constants/test update that only affects provider inference for specific Bedrock Claude 4 model ID strings, ensuring they no longer fall back to the default provider.
Overview
Fixes Bedrock provider inference for Anthropic Claude 4 by adding cross-region inference profile model IDs (e.g.
us.,eu.,apac.,global., etc.) to theBedrockModelsliteral andBEDROCK_MODELSlist inconstants.py.Extends
test_validate_model_in_constantsand adds targeted tests to assert Claude 4 direct IDs + inference profiles are present inBEDROCK_MODELSand thatLLM._infer_provider_from_model()returns"bedrock"for those IDs (preventing an"openai"fallback).Reviewed by Cursor Bugbot for commit 04dcabc. Bugbot is set up for automated code reviews on this repo. Configure here.