Skip to content

Commit f48752a

Browse files
Construct default Anthropic base URL for Bedrock (grll#9)
* Construct default Anthropic base URL for Bedrock ## Summary - Automatically constructs the Bedrock API endpoint URL using AWS_REGION when ANTHROPIC_BEDROCK_BASE_URL is not provided - Added test to document this behavior in test/validate-env.test.ts - Addresses issues anthropics#32 and anthropics#43 where users encountered 404 errors when using Bedrock integration without explicitly setting the base URL ## Background Users of AWS Bedrock integration were encountering 404 API errors when the ANTHROPIC_BEDROCK_BASE_URL was not explicitly set. This change ensures the URL is automatically constructed using the AWS_REGION, making the integration more user-friendly and preventing the confusing error messages reported in issues anthropics#32 and anthropics#43. ## Test Plan - Added test in test/validate-env.test.ts to document the behavior - Manual testing with AWS Bedrock integration * test: format test file with prettier to fix CI checks Ran `bun run format` to ensure proper code formatting and make CI checks pass. ## Test Plan - Verify formatting with `bun run format:check` - Ensure all CI checks pass
1 parent f99496e commit f48752a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ You can authenticate with Claude using any of these three methods:
179179
- Bedrock and Vertex use OIDC authentication exclusively
180180
- AWS Bedrock automatically uses cross-region inference profiles for certain models
181181
- For cross-region inference profile models, you need to request and be granted access to the Claude models in all regions that the inference profile uses
182+
- The Bedrock API endpoint URL is automatically constructed using the AWS_REGION environment variable (e.g., `https://bedrock-runtime.us-west-2.amazonaws.com`)
183+
- You can override the Bedrock API endpoint URL by setting the `ANTHROPIC_BEDROCK_BASE_URL` environment variable
182184

183185
### Model Configuration
184186

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ runs:
122122
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
123123
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
124124
AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
125-
ANTHROPIC_BEDROCK_BASE_URL: ${{ env.ANTHROPIC_BEDROCK_BASE_URL }}
125+
ANTHROPIC_BEDROCK_BASE_URL: ${{ env.ANTHROPIC_BEDROCK_BASE_URL || (env.AWS_REGION && format('https://bedrock-runtime.{0}.amazonaws.com', env.AWS_REGION)) }}
126126

127127
# GCP configuration
128128
ANTHROPIC_VERTEX_PROJECT_ID: ${{ env.ANTHROPIC_VERTEX_PROJECT_ID }}

test/validate-env.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ describe("validateEnvironmentVariables", () => {
6464
expect(() => validateEnvironmentVariables()).not.toThrow();
6565
});
6666

67+
test("should construct Bedrock base URL from AWS_REGION when ANTHROPIC_BEDROCK_BASE_URL is not provided", () => {
68+
// This test verifies our action.yml change, which constructs:
69+
// ANTHROPIC_BEDROCK_BASE_URL: ${{ env.ANTHROPIC_BEDROCK_BASE_URL || (env.AWS_REGION && format('https://bedrock-runtime.{0}.amazonaws.com', env.AWS_REGION)) }}
70+
71+
process.env.CLAUDE_CODE_USE_BEDROCK = "1";
72+
process.env.AWS_REGION = "us-west-2";
73+
process.env.AWS_ACCESS_KEY_ID = "test-access-key";
74+
process.env.AWS_SECRET_ACCESS_KEY = "test-secret-key";
75+
// ANTHROPIC_BEDROCK_BASE_URL is intentionally not set
76+
77+
// The actual URL construction happens in the composite action in action.yml
78+
// This test is a placeholder to document the behavior
79+
expect(() => validateEnvironmentVariables()).not.toThrow();
80+
81+
// In the actual action, ANTHROPIC_BEDROCK_BASE_URL would be:
82+
// https://bedrock-runtime.us-west-2.amazonaws.com
83+
});
84+
6785
test("should fail when AWS_REGION is missing", () => {
6886
process.env.CLAUDE_CODE_USE_BEDROCK = "1";
6987
process.env.AWS_ACCESS_KEY_ID = "test-access-key";

0 commit comments

Comments
 (0)