From 79a1fcfa277a24a0f81712ccf5057d891455a369 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:07:34 +0000 Subject: [PATCH 1/4] Initial plan From 910c8385c9d6b9365da744c5c739852b0c9759ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:19:35 +0000 Subject: [PATCH 2/4] Add comprehensive AWS Bedrock environment variable support - 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> --- .../docs/configuration/anthropic-bedrock.mdx | 72 ++++++++++++++++++- packages/core/src/env.ts | 25 +++++++ packages/core/src/llmsdata.ts | 36 +++++++++- 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/docs/src/content/docs/configuration/anthropic-bedrock.mdx b/docs/src/content/docs/configuration/anthropic-bedrock.mdx index 73d130916c..0360b0b5cb 100644 --- a/docs/src/content/docs/configuration/anthropic-bedrock.mdx +++ b/docs/src/content/docs/configuration/anthropic-bedrock.mdx @@ -26,12 +26,78 @@ import LLMProviderFeatures from "../../../components/LLMProviderFeatures.astro"; The `anthropic_bedrock` provider accesses Anthropic models on Amazon Bedrock. You can find the model names in the [Anthropic model documentation](https://docs.anthropic.com/en/docs/about-claude/models#model-names). -GenAIScript assumes that you have configured Amazon Web Services (AWS) credentials -in a way that the [AWS Node SDK will recognize](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html). - ```js "anthropic_bedrock:" script({ model: "anthropic_bedrock:anthropic.claude-3-sonnet-20240229-v1:0", }); ``` + +## Configuration + +GenAIScript supports multiple ways to configure AWS credentials for Bedrock access: + +### Required Environment Variables + +- `AWS_REGION` - The AWS region where Bedrock is enabled (e.g., `us-east-1`, `us-west-2`) + +### Authentication Options + +Choose one of the following authentication methods: + + + +```bash +export AWS_ACCESS_KEY_ID="AKIA..." +export AWS_SECRET_ACCESS_KEY="..." +export AWS_SESSION_TOKEN="..." # Optional, for temporary credentials +``` + + + +```bash +export AWS_PROFILE="my-profile" +``` + + + +```bash +export AWS_BEARER_TOKEN_BEDROCK="your-bedrock-api-key" +``` + + + +### Optional Environment Variables + +- `ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION` - Override AWS region for small/fast models +- `DISABLE_PROMPT_CACHING` - Set to `1` to disable Anthropic prompt caching +- `ANTHROPIC_MODEL` - Override the default Anthropic model ID for Bedrock + +### Setup Steps + + + +1. **Enable Bedrock Access** + + Request access to Claude models in the [Amazon Bedrock console](https://console.aws.amazon.com/bedrock/) under "Model Access". + +2. **Configure Credentials** + + Set up your AWS credentials using one of the methods above. GenAIScript follows the standard [AWS credential provider chain](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html). + +3. **Set Region** + + Configure the AWS region where you have Bedrock access: + ```bash + export AWS_REGION="us-east-1" + ``` + +4. **Test Configuration** + + ```bash + genaiscript configure anthropic_bedrock + ``` + + + + diff --git a/packages/core/src/env.ts b/packages/core/src/env.ts index 1ef290335f..dbf30fde53 100644 --- a/packages/core/src/env.ts +++ b/packages/core/src/env.ts @@ -535,6 +535,29 @@ export async function parseTokenFromEnv( if (provider === MODEL_PROVIDER_ANTHROPIC_BEDROCK) { dbg(`processing ${MODEL_PROVIDER_ANTHROPIC_BEDROCK}`); + + // AWS region is required for Bedrock + const region = env.AWS_REGION; + if (!region) { + throw new Error("AWS_REGION is required for Anthropic Bedrock"); + } + + // Check for AWS credentials or Bedrock API key + const hasAwsCredentials = env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY; + const hasBedrockApiKey = env.AWS_BEARER_TOKEN_BEDROCK; + const hasAwsProfile = env.AWS_PROFILE; + + if (!hasAwsCredentials && !hasBedrockApiKey && !hasAwsProfile) { + throw new Error( + "AWS credentials are required for Anthropic Bedrock. Set AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, AWS_BEARER_TOKEN_BEDROCK, or AWS_PROFILE" + ); + } + + dbg(`AWS region: ${region}`); + if (hasAwsCredentials) dbg("using AWS access key credentials"); + if (hasBedrockApiKey) dbg("using AWS Bedrock API key"); + if (hasAwsProfile) dbg(`using AWS profile: ${env.AWS_PROFILE}`); + return { provider, model, @@ -542,6 +565,8 @@ export async function parseTokenFromEnv( source: "AWS SDK", base: undefined, token: MODEL_PROVIDER_ANTHROPIC_BEDROCK, + // Store AWS-specific configuration for reference + version: region, } satisfies LanguageModelConfiguration; } diff --git a/packages/core/src/llmsdata.ts b/packages/core/src/llmsdata.ts index 5f2b7120e9..499d5d301e 100644 --- a/packages/core/src/llmsdata.ts +++ b/packages/core/src/llmsdata.ts @@ -460,7 +460,41 @@ export default { vision: "anthropic.claude-3-7-sonnet-20250219-v1:0:0", vision_small: "anthropic.claude-3-5-haiku-20241022-v1:0", }, - env: {}, + env: { + AWS_REGION: { + description: "AWS region where Bedrock is enabled (required)", + required: true, + }, + AWS_ACCESS_KEY_ID: { + description: "AWS access key ID for authentication", + secret: true, + }, + AWS_SECRET_ACCESS_KEY: { + description: "AWS secret access key for authentication", + secret: true, + }, + AWS_SESSION_TOKEN: { + description: "AWS session token for temporary credentials", + secret: true, + }, + AWS_PROFILE: { + description: "AWS profile name to use for authentication", + }, + AWS_BEARER_TOKEN_BEDROCK: { + description: "AWS Bedrock API key for simplified authentication", + secret: true, + }, + ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION: { + description: "Override AWS region for small/fast models", + }, + DISABLE_PROMPT_CACHING: { + description: "Set to '1' to disable Anthropic prompt caching", + enum: ["1", "true"], + }, + ANTHROPIC_MODEL: { + description: "Override the default Anthropic model ID for Bedrock", + }, + }, }, { id: "google", From bcd0f71b21fb423de6dc6ffe3d0c6bee49b59986 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Sep 2025 22:24:24 +0000 Subject: [PATCH 3/4] Add comprehensive logging for optional Bedrock environment variables - 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> --- packages/core/src/env.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/src/env.ts b/packages/core/src/env.ts index dbf30fde53..f661336ce0 100644 --- a/packages/core/src/env.ts +++ b/packages/core/src/env.ts @@ -554,10 +554,24 @@ export async function parseTokenFromEnv( } dbg(`AWS region: ${region}`); - if (hasAwsCredentials) dbg("using AWS access key credentials"); + if (hasAwsCredentials) { + dbg("using AWS access key credentials"); + if (env.AWS_SESSION_TOKEN) dbg("with session token (temporary credentials)"); + } if (hasBedrockApiKey) dbg("using AWS Bedrock API key"); if (hasAwsProfile) dbg(`using AWS profile: ${env.AWS_PROFILE}`); + // Log optional configurations + if (env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION) { + dbg(`small/fast model region override: ${env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION}`); + } + if (env.DISABLE_PROMPT_CACHING) { + dbg(`prompt caching disabled: ${env.DISABLE_PROMPT_CACHING}`); + } + if (env.ANTHROPIC_MODEL) { + dbg(`model override: ${env.ANTHROPIC_MODEL}`); + } + return { provider, model, From 2214cbbbb0d308f51aaa00563f78c3c288ffb183 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Sep 2025 23:29:54 +0000 Subject: [PATCH 4/4] genai: /docs [skip ci] --- packages/core/src/env.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/core/src/env.ts b/packages/core/src/env.ts index f661336ce0..0f00c0f4d6 100644 --- a/packages/core/src/env.ts +++ b/packages/core/src/env.ts @@ -535,24 +535,24 @@ export async function parseTokenFromEnv( if (provider === MODEL_PROVIDER_ANTHROPIC_BEDROCK) { dbg(`processing ${MODEL_PROVIDER_ANTHROPIC_BEDROCK}`); - + // AWS region is required for Bedrock const region = env.AWS_REGION; if (!region) { throw new Error("AWS_REGION is required for Anthropic Bedrock"); } - + // Check for AWS credentials or Bedrock API key const hasAwsCredentials = env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY; const hasBedrockApiKey = env.AWS_BEARER_TOKEN_BEDROCK; const hasAwsProfile = env.AWS_PROFILE; - + if (!hasAwsCredentials && !hasBedrockApiKey && !hasAwsProfile) { throw new Error( - "AWS credentials are required for Anthropic Bedrock. Set AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, AWS_BEARER_TOKEN_BEDROCK, or AWS_PROFILE" + "AWS credentials are required for Anthropic Bedrock. Set AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, AWS_BEARER_TOKEN_BEDROCK, or AWS_PROFILE", ); } - + dbg(`AWS region: ${region}`); if (hasAwsCredentials) { dbg("using AWS access key credentials"); @@ -560,7 +560,7 @@ export async function parseTokenFromEnv( } if (hasBedrockApiKey) dbg("using AWS Bedrock API key"); if (hasAwsProfile) dbg(`using AWS profile: ${env.AWS_PROFILE}`); - + // Log optional configurations if (env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION) { dbg(`small/fast model region override: ${env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION}`); @@ -571,7 +571,7 @@ export async function parseTokenFromEnv( if (env.ANTHROPIC_MODEL) { dbg(`model override: ${env.ANTHROPIC_MODEL}`); } - + return { provider, model, @@ -977,7 +977,7 @@ export function parseAllowedDomains(env: Record): string[] { try { const parsed = YAMLTryParse(envValue); if (Array.isArray(parsed)) { - return parsed.filter(domain => typeof domain === 'string' && domain.trim()); + return parsed.filter((domain) => typeof domain === "string" && domain.trim()); } } catch { // Fall through to comma-separated parsing @@ -985,9 +985,9 @@ export function parseAllowedDomains(env: Record): string[] { // Parse as comma-separated list return envValue - .split(',') - .map(domain => domain.trim()) - .filter(domain => domain.length > 0); + .split(",") + .map((domain) => domain.trim()) + .filter((domain) => domain.length > 0); } /**