Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/ai/llms.txt
Use this file to discover all available pages before exploring further.
Amazon Bedrock Provider
The Amazon Bedrock provider enables you to use various foundation models from Amazon and third-party providers through a unified API.
Installation
npm install @ai-sdk/amazon-bedrock
Setup
Configure your AWS credentials:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1
Usage
Basic Text Generation
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';
const { text } = await generateText({
model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
prompt: 'Explain cloud architecture.',
});
Streaming Responses
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { streamText } from 'ai';
const result = streamText({
model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
prompt: 'Describe AWS services.',
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
Structured Output
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateObject } from 'ai';
import { z } from 'zod';
const { object } = await generateObject({
model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
schema: z.object({
services: z.array(z.string()),
costs: z.number(),
}),
prompt: 'Estimate AWS infrastructure costs.',
});
Configuration
Custom Provider Instance
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
const bedrock = createAmazonBedrock({
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
Provider Options
- region: AWS region for API calls
- accessKeyId: AWS access key ID
- secretAccessKey: AWS secret access key
- sessionToken: Optional session token
Available Models
Anthropic Claude
anthropic.claude-3-5-sonnet-20241022-v2:0 - Most capable Claude model
anthropic.claude-3-haiku-20240307-v1:0 - Fast and cost-effective
Amazon Titan
amazon.titan-text-premier-v1:0 - Amazon’s text model
amazon.titan-embed-text-v2:0 - Text embeddings
meta.llama3-70b-instruct-v1:0 - Llama 3 70B
meta.llama3-8b-instruct-v1:0 - Llama 3 8B
Mistral AI
mistral.mistral-large-2407-v1:0 - Mistral Large
mistral.mistral-small-2402-v1:0 - Mistral Small
Advanced Features
Guardrails
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';
const result = await generateText({
model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
prompt: 'Generate content.',
providerOptions: {
bedrock: {
guardrailConfig: {
guardrailIdentifier: 'your-guardrail-id',
guardrailVersion: '1',
trace: 'enabled',
},
},
},
});
Vision (Claude Models)
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';
import fs from 'fs';
const result = await generateText({
model: bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe this image.' },
{ type: 'image', image: fs.readFileSync('./image.jpg') },
],
},
],
});
PDF Support
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { generateText } from 'ai';
import fs from 'fs';
const result = await generateText({
model: bedrock('anthropic.claude-3-haiku-20240307-v1:0'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize this document.' },
{
type: 'file',
data: fs.readFileSync('./document.pdf'),
mediaType: 'application/pdf',
},
],
},
],
});
Embeddings
import { bedrock } from '@ai-sdk/amazon-bedrock';
import { embed } from 'ai';
const { embedding } = await embed({
model: bedrock.embedding('amazon.titan-embed-text-v2:0'),
value: 'AWS cloud infrastructure',
});
Model Capabilities
| Model | Vision | Tools | Structured Output |
|---|
| anthropic.claude-3-5-sonnet-v2 | ✓ | ✓ | ✓ |
| anthropic.claude-3-haiku | ✓ | ✓ | ✓ |
| amazon.titan-text-premier | ✗ | ✗ | ✓ |
| meta.llama3-70b-instruct | ✗ | ✓ | ✓ |
Resources