Repository navigation
Add AWS Bedrock provider to the ai module - #329
Merged
Merged
Conversation
Agents can select provider="bedrock", resolved through LangChain's bedrock_converse (ChatBedrockConverse). BedrockConfig reads region, IAM credentials, session token, profile, Bedrock API key and model id from the standard AWS env vars; unset values are omitted so boto3's default credential chain applies. langchain-aws ships as the optional bedrock extra. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
langchain-aws does not depend on langchain, which provides init_chat_model, so installing only fastapi-startkit[bedrock] failed with ModuleNotFoundError. The extra now self-references fastapi-startkit[ai]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
The QA note about the
Verification, on Python 3.14 with fresh venvs:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tmgbedu
approved these changes
Oct 30, 2026
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
provider="bedrock", resolved through LangChain'sbedrock_converse(ChatBedrockConverse). It goes through the sameinit_chat_modelpath as the other providers, so tools, structured output, streaming and fakes work unchanged.BedrockConfigreadsAWS_REGION(falls back toAWS_DEFAULT_REGION),AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN,AWS_PROFILE,AWS_BEARER_TOKEN_BEDROCK(Bedrock API key) andAWS_BEDROCK_MODEL. It is registered inAIConfig.providersand exported fromfastapi_startkit.ai.Lab.get_client_options()maps these settings to ChatBedrockConverse arguments and drops empty values, so boto3's default credential chain applies when they are unset. Other providers return{}, so their behaviour is unchanged.langchain-awsis the new optionalbedrockextra (fastapi-startkit[ai,bedrock]). The framework never imports it. When it is missing, a Bedrock agent raises LangChain'sImportErrornaminglangchain-aws.Notes
us.anthropic.claude-sonnet-4-6is a cross-region inference profile id. Override it withAWS_BEDROCK_MODELif it is not enabled in your account or region.uv.lockbumpslangchain-coreandlangsmithbecauselangchain-awsrequires the newer versions.Test plan
tests/ai/test_bedrock.py: config env mapping, region fallback, empty defaults, provider/model resolution, client options with and without credentialstests/ai/test_agent.py: Bedrock agent build with a mockedinit_chat_model(runs where langchain is installed; checked on Python 3.14)ChatBedrockConverseinstance is built with the right model id, region and timeout (no AWS call), and there is a clear ImportError when the extra is missinguv run pytest --ignore=tests/masoniteorm/postgres --cov: 3502 passed, 92.23% coverage🤖 Generated with Claude Code