Skip to content
Open
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
23 changes: 23 additions & 0 deletions content/providers/01-ai-sdk-providers/08-amazon-bedrock.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ See the [Model Access Docs](https://docs.aws.amazon.com/bedrock/latest/userguide

### Authentication

The Amazon Bedrock provider supports API key authentication and AWS credentials (IAM/SigV4). API keys are recommended for simpler setup.

#### Using API Key (Recommended)

Set the `AWS_BEARER_TOKEN_BEDROCK` environment variable:

```makefile
AWS_BEARER_TOKEN_BEDROCK=your-api-key-here
```

The API key will be automatically used. If not provided, the provider falls back to AWS credentials.

#### Using IAM Access Key and Secret Key

**Step 1: Creating AWS Access Key and Secret Key**
Expand Down Expand Up @@ -124,6 +136,13 @@ If you need a customized setup, you can import `createAmazonBedrock` from `@ai-s
```ts
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';

// With API key:
const bedrock = createAmazonBedrock({
apiKey: 'your-api-key',
region: 'us-east-1',
});

// Or with IAM credentials:
const bedrock = createAmazonBedrock({
region: 'us-east-1',
accessKeyId: 'xxxxxxxxx',
Expand All @@ -143,6 +162,10 @@ const bedrock = createAmazonBedrock({

You can use the following optional settings to customize the Amazon Bedrock provider instance:

- **apiKey** _string_

The API key for authentication. It uses the `AWS_BEARER_TOKEN_BEDROCK` environment variable by default. When provided, this takes precedence over AWS credentials.

- **region** _string_

The AWS region that you want to use for the API calls.
Expand Down
8 changes: 4 additions & 4 deletions packages/amazon-bedrock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const { text } = await generateText({

#### Using Direct Configuration

You can also pass the API key directly in the provider configuration:
You can also pass the API key directly when creating a custom provider instance:

```ts
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';

const bedrockWithApiKey = bedrock.withSettings({
const bedrockWithApiKey = createAmazonBedrock({
apiKey: process.env.AWS_BEARER_TOKEN_BEDROCK, // or your API key directly
region: 'us-east-1', // Optional: specify region
});
Expand Down Expand Up @@ -90,7 +90,7 @@ This method requires standard AWS environment variables:

The provider uses the following authentication precedence:

1. **API key from direct configuration** (`apiKey` in `withSettings()`)
1. **API key from direct configuration** (`apiKey` in `createAmazonBedrock()`)
2. **API key from environment variable** (`AWS_BEARER_TOKEN_BEDROCK`)
3. **SigV4 authentication** (AWS credential chain fallback)

Expand Down