Skip to content
This repository was archived by the owner on Jul 24, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions docs/src/content/docs/configuration/anthropic-bedrock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<Tabs>
<TabItem label="Access Keys">
```bash
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_SESSION_TOKEN="..." # Optional, for temporary credentials
```
</TabItem>

<TabItem label="AWS Profile">
```bash
export AWS_PROFILE="my-profile"
```
</TabItem>

<TabItem label="Bedrock API Key">
```bash
export AWS_BEARER_TOKEN_BEDROCK="your-bedrock-api-key"
```
</TabItem>
</Tabs>

### 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

<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
```

</Steps>

<LLMProviderFeatures provider="anthropic_bedrock" />
47 changes: 43 additions & 4 deletions packages/core/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,52 @@ 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 (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,
modelId,
source: "AWS SDK",
base: undefined,
token: MODEL_PROVIDER_ANTHROPIC_BEDROCK,
// Store AWS-specific configuration for reference
version: region,
} satisfies LanguageModelConfiguration;
}

Expand Down Expand Up @@ -938,17 +977,17 @@ export function parseAllowedDomains(env: Record<string, string>): 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
}

// 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);
}

/**
Expand Down
36 changes: 35 additions & 1 deletion packages/core/src/llmsdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down