feat(sdk): Support additional AWS Bedrock authentication methods#2598
feat(sdk): Support additional AWS Bedrock authentication methods#2598enyst merged 11 commits intoOpenHands:mainfrom
Conversation
|
@OpenHands /codereview-roasted /github-pr-review |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
xingyaoww
left a comment
There was a problem hiding this comment.
Taste Rating: 🔴 Needs improvement
The idea is right — users need more Bedrock auth methods. But the implementation has a fundamental correctness bug: 3 of 5 new fields are dead code that silently do nothing.
Linus-Style Analysis
LiteLLM reads aws_role_name, aws_session_name, and aws_bedrock_runtime_endpoint from kwargs passed to litellm.completion(), NOT from environment variables. The PR stores them on the model but never wires them into the completion call. A user who sets aws_role_name will get no error — the field is quietly ignored, and they'll hit a confusing auth failure.
The fields that do work (aws_session_token → AWS_SESSION_TOKEN, aws_profile_name → AWS_PROFILE) work only because boto3 itself reads those standard env vars. That's luck, not design.
VERDICT: ❌ Needs rework — 3 of 5 fields are silently broken.
KEY INSIGHT: Don't add config fields to a model unless you wire them through to the system that actually consumes them. Storing a value and never using it is worse than not having it — it gives users false confidence.
SummaryI completed the requested code review on PR #2598 ("feat(sdk): Support additional AWS Bedrock authentication methods") using both the What was done
Key finding
The review is posted at: #2598 (review) |
Forward aws_role_name, aws_session_name, and aws_bedrock_runtime_endpoint as kwargs to both litellm_completion() and litellm_responses() so they are actually consumed by LiteLLM instead of being silently ignored. Add test verifying the params reach litellm. Co-authored-by: openhands <openhands@all-hands.dev>
Move all AWS Bedrock authentication parameters from process-global environment variables to litellm kwargs. This prevents credential clobbering when multiple LLM instances use different AWS configs. Co-authored-by: openhands <openhands@all-hands.dev>
|
Changes addressing review feedback:
Testingimport os
from openhands.sdk import LLM
# Clear any existing AWS env vars
for k in ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AWS_REGION_NAME", "AWS_PROFILE"]:
os.environ.pop(k, None)
llm = LLM(
model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
api_key=None,
aws_access_key_id="test-key",
aws_secret_access_key="test-secret",
aws_region_name="us-west-2",
)
# These should NOT be set anymore
assert "AWS_ACCESS_KEY_ID" not in os.environ
assert "AWS_SECRET_ACCESS_KEY" not in os.environ
assert "AWS_REGION_NAME" not in os.environ
print("Confirmed: no env var pollution") |
|
@OpenHands /codereview-roasted /github-pr-review |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
xingyaoww
left a comment
There was a problem hiding this comment.
Taste Rating: 🟡 Acceptable
Solid change that fixes a real problem — Bedrock users with temporary STS creds, SSO profiles, or cross-account roles can now authenticate without hacky env-var workarounds. The _aws_kwargs() helper eliminates global env-var side effects (good), and the fields map 1:1 to litellm's Bedrock auth params.
Two things worth addressing before merge, one important and one minor.
VERDICT: ✅ Worth merging after addressing the breaking-change callout.
KEY INSIGHT: Passing AWS creds as explicit kwargs instead of mutating os.environ is the correct design — it eliminates cross-instance interference. But removing the env-var writes is a silent breaking change that needs to be documented.
Summary of Work CompletedI performed a code review on PR #2598 ("feat(sdk): Support additional AWS Bedrock authentication methods") using both the What was done:
Review Findings Posted:
Review Decision:Used COMMENT (not APPROVE) because the PR modifies No code changes were made — this was a review-only task as requested. |
Keep os.environ writes for AWS credentials alongside the new _aws_kwargs() approach. This ensures existing users who rely on env vars for other AWS SDK calls in the same process are not broken. Also move inline test imports to top of file per repo convention. Co-authored-by: openhands <openhands@all-hands.dev>
|
|
@OpenHands /codereview-roasted /github-pr-review |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
xingyaoww
left a comment
There was a problem hiding this comment.
🟡 Acceptable — Works, but has one inconsistency worth addressing
Taste Rating: The _aws_kwargs() helper is clean and the overall approach of forwarding AWS params as kwargs rather than relying solely on env vars is the right call — it’s how LiteLLM actually consumes them. The change is well-scoped and solves a real problem for users with temporary credentials, SSO profiles, or cross-account roles.
Linus-style summary: "The data structure is right (a dict built from optional fields), the flow is clean (splat into litellm calls), and it solves a real problem. But there’s one inconsistency that’ll bite someone."
VERDICT: ✅ Worth merging after the env var inconsistency is addressed.
KEY INSIGHT: The _aws_kwargs() correctly handles aws_session_token, but _set_env_side_effects doesn’t write AWS_SESSION_TOKEN to env — creating two inconsistent auth paths for temp credentials.
See inline comments for details.
Summary of Work CompletedI performed a code review on PR #2598 ("feat(sdk): Support additional AWS Bedrock authentication methods") using both the What was done:
Review posted: PR #2598 ReviewKey findings:
Overall verdict: 🟡 Acceptable — worth merging after the env var inconsistency for |
Include aws_session_token in _set_env_side_effects to keep the STS credential triplet consistent (access key + secret key + session token). Co-authored-by: openhands <openhands@all-hands.dev>
Use dict merge instead of double-splat so caller kwargs win on conflict instead of raising TypeError. Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
|
|
@OpenHands /codereview-roasted /github-pr-review |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
xingyaoww
left a comment
There was a problem hiding this comment.
🟢 Good taste — Clean, pragmatic feature addition
Taste Rating: 🟢 Elegant enough — solves a real problem with minimal complexity.
Linus-Style Verdict
This solves an actual problem real users have (temporary AWS creds, SSO profiles, cross-account roles). The _aws_kwargs() helper is straightforward — build a dict from non-None fields, splat it into the litellm call. No special cases, no over-engineering, no unnecessary abstractions.
The dual strategy (env vars for backward compat on the original 3 fields + kwargs for all 8) is pragmatic. The PR has been through multiple review rounds and all prior feedback has been addressed.
All 19 tests pass. Pre-commit hooks (ruff, pyright) pass clean.
✅ Worth merging — LGTM.
SummaryI completed the requested code review on PR #2598 ("feat(sdk): Support additional AWS Bedrock authentication methods") using both the What was done
Review Verdict: 🟢 Good taste — APPROVEDThe PR is a clean, pragmatic feature addition that:
No code changes were madeThis was a review-only task — I only posted the review comment on the PR, no code modifications. |
|
@sjathin Looks good to me :) Happy to merge it if you can confirm the latest version still works |
Yes the latest version works. Tested using: I see the response from LLM: |
The mock_llm fixture in test_llm_summarizing_condenser.py was missing the new AWS Bedrock auth fields (aws_session_token, aws_profile_name, aws_role_name, aws_session_name, aws_bedrock_runtime_endpoint). Since the mock uses spec=LLM, accessing these unset attributes returns truthy MagicMock objects, causing _aws_kwargs() to fail on the isinstance assertion.
|
Fixed the sdk-tests CI failure caused by the "Update branch" merge. The mock_llm fixture in test_llm_summarizing_condenser.py was missing the 5 new AWS fields — since the mock uses spec=LLM, the unset attributes were truthy MagicMock objects that caused _aws_kwargs() to hit the isinstance(self.aws_session_token, SecretStr) assertion. Added None defaults for all new fields to match the existing pattern. |
|
@OpenHands Look in this codebase for Answer directly on the PR as a comment. |
|
I'm on it! enyst can track my progress at all-hands.dev |
|
@enyst I looked through Short answer: for Why:
So the important compatibility work was in
This PR already does that, so I don't see another code change needed specifically for On test coverage: I think the current coverage is enough.
The only extra thing I could imagine adding would be a tiny belt-and-suspenders nested roundtrip test like This comment was created by an AI assistant (OpenHands) on behalf of the user. |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
Thank you for this @sjathin ! Let's take this in. |
Summary
Adds support for additional AWS Bedrock authentication methods in the LLM class, fixing #2198.
Previously, only basic IAM key auth was supported (aws_access_key_id, aws_secret_access_key, aws_region_name), forcing users with temporary credentials, SSO profiles, or cross-account roles to manually set
environment variables outside the SDK.
This PR adds 6 new fields that map directly to LiteLLM's Bedrock auth parameters:
aws_session_token— temporary STS credentials (e.g. from aws sso login)aws_profile_name— named profiles from ~/.aws/configaws_role_name— IAM role ARN for cross-account accessaws_session_name— session name for STS AssumeRoleaws_bedrock_runtime_endpoint— custom Bedrock proxy endpointsTested end-to-end with temporary AWS credentials against Bedrock (Claude 3.5 Sonnet).`
Checklist
Testing
Executed: