Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Add comprehensive AWS Bedrock environment variable support for Anthropic Claude models#1919

Merged
pelikhan merged 4 commits into
devfrom
copilot/support-anthropic-llm-configuration
Sep 5, 2025
Merged

Add comprehensive AWS Bedrock environment variable support for Anthropic Claude models#1919
pelikhan merged 4 commits into
devfrom
copilot/support-anthropic-llm-configuration

Conversation

Copilot AI commented Sep 5, 2025

Copy link
Copy Markdown

Problem

The current Anthropic Bedrock provider implementation had minimal environment variable support, only relying on AWS SDK's automatic credential discovery without proper validation or configuration options. This made it difficult for users to:

  • Configure specific AWS regions for Bedrock access
  • Use different authentication methods (API keys, profiles, temporary credentials)
  • Debug connection issues due to missing credentials
  • Access advanced Bedrock features like prompt caching controls

Solution

This PR implements comprehensive AWS Bedrock configuration support that aligns with Anthropic's official documentation and AWS best practices:

Required Environment Variables

  • AWS_REGION: Now validated as required since Bedrock is region-specific
  • Authentication (one method required):
    • AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY for standard credentials
    • AWS_SESSION_TOKEN for temporary/assumed role credentials
    • AWS_PROFILE for profile-based authentication
    • AWS_BEARER_TOKEN_BEDROCK for simplified Bedrock API key authentication

Optional Advanced Variables

  • ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION: Override region for small/fast models
  • DISABLE_PROMPT_CACHING: Control prompt caching behavior
  • ANTHROPIC_MODEL: Override default model selection

Changes Made

  1. Enhanced env.ts: Added comprehensive validation and error handling for all AWS Bedrock environment variables with clear error messages
  2. Updated llmsdata.ts: Documented all supported environment variables for the CLI configure command
  3. Improved documentation: Updated anthropic-bedrock.mdx with complete setup instructions and configuration examples
  4. Added debugging: Comprehensive logging for troubleshooting configuration issues

Example Usage

# Required setup
export AWS_REGION="us-east-1"
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="..."

# Optional advanced configuration
export ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION="us-west-2"
export DISABLE_PROMPT_CACHING="1"

# Now works with proper validation
genaiscript run my-script --model anthropic_bedrock:anthropic.claude-3-sonnet-20240229-v1:0

Validation

  • ✅ All changes build successfully
  • ✅ No security vulnerabilities introduced (CodeQL scan passed)
  • ✅ Comprehensive error messages for common misconfigurations
  • ✅ Backward compatible with existing AWS SDK credential discovery
  • ✅ Follows existing code patterns and conventions

This implementation ensures users have full control over their Bedrock configuration while maintaining the simplicity of the AWS SDK's automatic discovery when appropriate.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /home/REDACTED/.local/share/pnpm/.tools/pnpm/10.12.3/bin/pnpm install (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • example.com
  • https://api.github.com/markdown
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/branches
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/contents/README.md
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/contents/packages%2Fcore%2Fsrc
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/git/blobs
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/git/ref/heads%2Ftest-ignore
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/issues
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/labels
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/languages
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/pulls
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 1) (http block)
  • https://api.github.com/repos/microsoft/genaiscript/pulls/999999
    • Triggering command: node (vitest 2) (http block)
    • Triggering command: node (vitest 3) (http block)
  • https://api.github.com/test
    • Triggering command: node (vitest 3) (http block)
    • Triggering command: node (vitest 2) (http block)
  • microsoft.github.io
    • Triggering command: node (vitest 3) (dns block)
    • Triggering command: node (vitest 2) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 5, 2025 22:19
- Add AWS_REGION validation (required)
- Support multiple authentication methods: access keys, profiles, Bedrock API keys
- Add environment variable definitions to llmsdata.ts
- Update documentation with configuration examples
- Enhanced error messages for missing credentials

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Log session token usage for temporary credentials
- Log optional configuration: ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION
- Log prompt caching and model override settings
- Enhanced debugging visibility for Bedrock configuration

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze the anthropic LLM support and make sure that all possible configuration for Bedrock are supported. Deep research: Configuring Anthropic LLM Tools (Claude) Access Anthropic’s Claude models can be accessed through multiple platforms. The confi... Add comprehensive AWS Bedrock environment variable support for Anthropic Claude models Sep 5, 2025
Copilot AI requested a review from pelikhan September 5, 2025 22:25
@github-actions

github-actions Bot commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

Warning

LLM error (403): error

AI-generated content by docs may be incorrect.

@pelikhan pelikhan merged commit 353495a into dev Sep 5, 2025
1 check passed
@pelikhan pelikhan deleted the copilot/support-anthropic-llm-configuration branch September 5, 2025 23:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants