@aeye/aws 0.3.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,407 +1,511 @@
1
- # @aeye/aws - AWS Bedrock Provider
2
-
3
- AWS Bedrock integration for the [@aeye](https://github.com/ClickerMonkey/aeye) framework, providing seamless access to Claude, Llama, Mistral, Cohere, Stability AI, and Amazon Titan models.
4
-
5
- ## Features
6
-
7
- - 🤖 **Multi-Model Support** - Access to all AWS Bedrock foundation models
8
- - 🔐 **Automatic Authentication** - Uses AWS SDK credential chain for seamless authentication
9
- - 🌊 **Streaming** - Full streaming support for real-time responses
10
- - 🎨 **Image Generation** - Stability AI models for image creation
11
- - 📊 **Embeddings** - Amazon Titan embeddings for semantic search
12
- - 🔧 **Type-Safe** - Full TypeScript support with type inference
13
- - ⚡ **Regional Flexibility** - Deploy across any AWS region with Bedrock
14
-
15
- ## Supported Models
16
-
17
- ### Chat Models
18
- - **Anthropic Claude** - Claude 3 Opus, Sonnet, Haiku, and Claude 3.5 Sonnet
19
- - **Meta Llama** - Llama 2, Llama 3, Llama 3.1, Llama 3.2
20
- - **Mistral AI** - Mistral 7B, Mixtral 8x7B, Mistral Large
21
- - **Cohere** - Command, Command Light, Command R, Command R+
22
- - **AI21 Labs** - Jurassic-2 models
23
-
24
- ### Image Models
25
- - **Stability AI** - Stable Diffusion XL, Stable Diffusion 3
26
-
27
- ### Embedding Models
28
- - **Amazon Titan** - Titan Text Embeddings v1 and v2
29
-
30
- ## Installation
31
-
32
- ```bash
33
- npm install @aeye/aws @aeye/ai @aeye/core zod
34
- ```
35
-
36
- ## Prerequisites
37
-
38
- ### AWS Credentials
39
-
40
- The provider uses the AWS SDK v3 credential chain to automatically discover credentials:
41
-
42
- 1. **Environment variables** - `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`
43
- 2. **Shared credentials file** - `~/.aws/credentials`
44
- 3. **IAM roles** - When running on EC2, ECS, Lambda, etc.
45
-
46
- ### AWS Bedrock Access
47
-
48
- Ensure you have:
49
- 1. Access to AWS Bedrock in your target region
50
- 2. Permissions to invoke foundation models
51
- 3. Model access enabled in the AWS Bedrock console
52
-
53
- ## Quick Start
54
-
55
- ### Basic Chat Completion
56
-
57
- ```typescript
58
- import { AI } from '@aeye/ai';
59
- import { AWSBedrockProvider } from '@aeye/aws';
60
-
61
- // Create provider (credentials picked up automatically)
62
- const aws = new AWSBedrockProvider({
63
- region: 'us-east-1',
64
- });
65
-
66
- // Create AI instance
67
- const ai = AI.with()
68
- .providers({ aws })
69
- .create();
70
-
71
- // Chat with Claude
72
- const response = await ai.chat.get([
73
- { role: 'user', content: 'What is AWS Bedrock?' }
74
- ], {
75
- model: 'anthropic.claude-3-sonnet-20240229-v1:0'
76
- });
77
-
78
- console.log(response.content);
79
- ```
80
-
81
- ### Streaming Responses
82
-
83
- ```typescript
84
- // Stream responses in real-time
85
- for await (const chunk of ai.chat.stream([
86
- { role: 'user', content: 'Write a poem about AI' }
87
- ], {
88
- model: 'anthropic.claude-3-haiku-20240307-v1:0'
89
- })) {
90
- if (chunk.content) {
91
- process.stdout.write(chunk.content);
92
- }
93
- }
94
- ```
95
-
96
- ### Image Generation
97
-
98
- ```typescript
99
- import { AWSBedrockProvider } from '@aeye/aws';
100
-
101
- const aws = new AWSBedrockProvider({
102
- region: 'us-east-1',
103
- defaultModels: {
104
- imageGenerate: 'stability.stable-diffusion-xl-v1',
105
- },
106
- });
107
-
108
- const ai = AI.with()
109
- .providers({ aws })
110
- .create();
111
-
112
- const result = await ai.image.generate({
113
- prompt: 'A serene mountain landscape at sunset',
114
- size: { width: 1024, height: 1024 },
115
- });
116
-
117
- console.log('Image URL:', result.images[0].url);
118
- ```
119
-
120
- ### Text Embeddings
121
-
122
- ```typescript
123
- const aws = new AWSBedrockProvider({
124
- region: 'us-east-1',
125
- defaultModels: {
126
- embedding: 'amazon.titan-embed-text-v1',
127
- },
128
- });
129
-
130
- const ai = AI.with()
131
- .providers({ aws })
132
- .create();
133
-
134
- const embeddings = await ai.embed.get({
135
- input: 'AWS Bedrock is a fully managed service',
136
- model: 'amazon.titan-embed-text-v1',
137
- });
138
-
139
- console.log('Embedding dimensions:', embeddings.embeddings[0].length);
140
- ```
141
-
142
- ## Configuration
143
-
144
- ### Provider Configuration
145
-
146
- ```typescript
147
- import { AWSBedrockProvider, type AWSBedrockConfig } from '@aeye/aws';
148
-
149
- const config: AWSBedrockConfig = {
150
- // AWS region (defaults to AWS_REGION env var or 'us-east-1')
151
- region: 'us-west-2',
152
-
153
- // Optional: Explicit credentials (if not using default chain)
154
- credentials: {
155
- accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
156
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
157
- sessionToken: process.env.AWS_SESSION_TOKEN, // Optional
158
- },
159
-
160
- // Optional: Default models for different capabilities
161
- defaultModels: {
162
- chat: 'anthropic.claude-3-sonnet-20240229-v1:0',
163
- imageGenerate: 'stability.stable-diffusion-xl-v1',
164
- embedding: 'amazon.titan-embed-text-v2:0',
165
- },
166
- };
167
-
168
- const provider = new AWSBedrockProvider(config);
169
- ```
170
-
171
- ### Using with Multiple Providers
172
-
173
- ```typescript
174
- import { AI } from '@aeye/ai';
175
- import { AWSBedrockProvider } from '@aeye/aws';
176
- import { OpenAIProvider } from '@aeye/openai';
177
-
178
- const aws = new AWSBedrockProvider({ region: 'us-east-1' });
179
- const openai = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! });
180
-
181
- const ai = AI.with()
182
- .providers({ aws, openai })
183
- .create({
184
- // Automatic model selection across all providers
185
- defaultMetadata: {
186
- required: ['chat', 'streaming'],
187
- weights: {
188
- cost: 0.5,
189
- speed: 0.3,
190
- quality: 0.2,
191
- },
192
- },
193
- });
194
-
195
- // AI instance will automatically select the best model across AWS and OpenAI
196
- const response = await ai.chat.get([
197
- { role: 'user', content: 'Hello!' }
198
- ]);
199
- ```
200
-
201
- ## Model IDs
202
-
203
- ### Anthropic Claude Models
204
-
205
- ```typescript
206
- // Claude 3.5
207
- 'anthropic.claude-3-5-sonnet-20240620-v1:0'
208
- 'anthropic.claude-3-5-sonnet-20241022-v2:0'
209
-
210
- // Claude 3
211
- 'anthropic.claude-3-opus-20240229-v1:0'
212
- 'anthropic.claude-3-sonnet-20240229-v1:0'
213
- 'anthropic.claude-3-haiku-20240307-v1:0'
214
-
215
- // Claude 2.x
216
- 'anthropic.claude-v2:1'
217
- 'anthropic.claude-v2'
218
- 'anthropic.claude-instant-v1'
219
- ```
220
-
221
- ### Meta Llama Models
222
-
223
- ```typescript
224
- 'meta.llama3-2-1b-instruct-v1:0'
225
- 'meta.llama3-2-3b-instruct-v1:0'
226
- 'meta.llama3-2-11b-instruct-v1:0'
227
- 'meta.llama3-2-90b-instruct-v1:0'
228
- 'meta.llama3-1-8b-instruct-v1:0'
229
- 'meta.llama3-1-70b-instruct-v1:0'
230
- 'meta.llama3-1-405b-instruct-v1:0'
231
- 'meta.llama3-8b-instruct-v1:0'
232
- 'meta.llama3-70b-instruct-v1:0'
233
- 'meta.llama2-13b-chat-v1'
234
- 'meta.llama2-70b-chat-v1'
235
- ```
236
-
237
- ### Mistral AI Models
238
-
239
- ```typescript
240
- 'mistral.mistral-7b-instruct-v0:2'
241
- 'mistral.mixtral-8x7b-instruct-v0:1'
242
- 'mistral.mistral-large-2402-v1:0'
243
- 'mistral.mistral-large-2407-v1:0'
244
- ```
245
-
246
- ### Cohere Models
247
-
248
- ```typescript
249
- 'cohere.command-text-v14'
250
- 'cohere.command-light-text-v14'
251
- 'cohere.command-r-v1:0'
252
- 'cohere.command-r-plus-v1:0'
253
- ```
254
-
255
- ### Stability AI Models
256
-
257
- ```typescript
258
- 'stability.stable-diffusion-xl-v1'
259
- 'stability.sd3-large-v1:0'
260
- ```
261
-
262
- ### Amazon Titan Models
263
-
264
- ```typescript
265
- // Embeddings
266
- 'amazon.titan-embed-text-v1'
267
- 'amazon.titan-embed-text-v2:0'
268
-
269
- // Image Generation
270
- 'amazon.titan-image-generator-v1'
271
- 'amazon.titan-image-generator-v2:0'
272
- ```
273
-
274
- ## Advanced Features
275
-
276
- ### Vision with Claude 3
277
-
278
- ```typescript
279
- const response = await ai.chat.get([
280
- {
281
- role: 'user',
282
- content: [
283
- { type: 'text', content: 'What do you see in this image?' },
284
- { type: 'image', content: 'https://example.com/image.jpg' },
285
- ],
286
- },
287
- ], {
288
- model: 'anthropic.claude-3-sonnet-20240229-v1:0',
289
- });
290
- ```
291
-
292
- ### Custom Request Parameters
293
-
294
- ```typescript
295
- const response = await ai.chat.get([
296
- { role: 'user', content: 'Hello!' }
297
- ], {
298
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
299
- temperature: 0.7,
300
- maxTokens: 2048,
301
- topP: 0.9,
302
- stop: ['Human:', 'Assistant:'],
303
- });
304
- ```
305
-
306
- ### Multi-Region Setup
307
-
308
- ```typescript
309
- // Primary region
310
- const awsEast = new AWSBedrockProvider({
311
- region: 'us-east-1',
312
- });
313
-
314
- // Fallback region
315
- const awsWest = new AWSBedrockProvider({
316
- region: 'us-west-2',
317
- });
318
-
319
- const ai = AI.with()
320
- .providers({ awsEast, awsWest })
321
- .create();
322
- ```
323
-
324
- ## Error Handling
325
-
326
- ```typescript
327
- import {
328
- AWSError,
329
- AWSAuthError,
330
- AWSRateLimitError,
331
- AWSQuotaError,
332
- AWSContextWindowError,
333
- } from '@aeye/aws';
334
-
335
- try {
336
- const response = await ai.chat.get([
337
- { role: 'user', content: 'Hello!' }
338
- ]);
339
- } catch (error) {
340
- if (error instanceof AWSAuthError) {
341
- console.error('Authentication failed. Check your AWS credentials.');
342
- } else if (error instanceof AWSRateLimitError) {
343
- console.error('Rate limit exceeded. Retry after:', error.retryAfter);
344
- } else if (error instanceof AWSQuotaError) {
345
- console.error('AWS quota exceeded. Request quota increase.');
346
- } else if (error instanceof AWSContextWindowError) {
347
- console.error('Input too long for model context window.');
348
- } else if (error instanceof AWSError) {
349
- console.error('AWS Bedrock error:', error.message);
350
- }
351
- }
352
- ```
353
-
354
- ## Health Check
355
-
356
- ```typescript
357
- const isHealthy = await aws.checkHealth();
358
- console.log('AWS Bedrock is accessible:', isHealthy);
359
- ```
360
-
361
- ## List Available Models
362
-
363
- ```typescript
364
- const models = await aws.listModels();
365
- console.log('Available models:', models.map(m => m.id));
366
-
367
- // Filter by capability
368
- const chatModels = models.filter(m => m.capabilities.has('chat'));
369
- const imageModels = models.filter(m => m.capabilities.has('image'));
370
- const embeddingModels = models.filter(m => m.capabilities.has('embedding'));
371
- ```
372
-
373
- ## Best Practices
374
-
375
- 1. **Use IAM Roles** - When running on AWS infrastructure (EC2, ECS, Lambda), use IAM roles instead of hardcoded credentials
376
- 2. **Region Selection** - Choose regions close to your users for lower latency
377
- 3. **Model Selection** - Use smaller models (Haiku, 7B) for faster, cheaper responses when appropriate
378
- 4. **Streaming** - Enable streaming for better user experience with long responses
379
- 5. **Error Handling** - Implement proper error handling and retry logic for production use
380
- 6. **Cost Management** - Monitor usage through AWS Cost Explorer and set up billing alerts
381
-
382
- ## Environment Variables
383
-
384
- ```bash
385
- # AWS credentials (if not using IAM roles)
386
- AWS_ACCESS_KEY_ID=your_access_key
387
- AWS_SECRET_ACCESS_KEY=your_secret_key
388
- AWS_SESSION_TOKEN=your_session_token # Optional
389
-
390
- # AWS region
391
- AWS_REGION=us-east-1
392
- ```
393
-
394
- ## Links
395
-
396
- - [AWS Bedrock Documentation](https://docs.aws.amazon.com/bedrock/)
397
- - [Model IDs Reference](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html)
398
- - [@aeye Framework](https://github.com/ClickerMonkey/aeye)
399
- - [AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v3/)
400
-
401
- ## License
402
-
403
- GPL-3.0 - See [LICENSE](../../LICENSE) file for details.
404
-
405
- ## Contributing
406
-
407
- Issues and pull requests are welcome! See the [main repository](https://github.com/ClickerMonkey/aeye) for contribution guidelines.
1
+ # @aeye/aws - AWS Bedrock Provider
2
+
3
+ AWS Bedrock integration for the [@aeye](https://github.com/ClickerMonkey/aeye) framework, providing seamless access to Claude, Llama, Mistral, Cohere, Stability AI, and Amazon Titan models.
4
+
5
+ ## Features
6
+
7
+ - 🤖 **Multi-Model Support** - Access to all AWS Bedrock foundation models
8
+ - 🔐 **Automatic Authentication** - Uses AWS SDK credential chain for seamless authentication
9
+ - 🌊 **Streaming** - Full streaming support for real-time responses
10
+ - 🧠 **Reasoning** - Claude adaptive and budgeted thinking, Nova and gpt-oss reasoning, with reasoning blocks replayed across turns
11
+ - 📐 **Structured Output** - Converse JSON-schema output and strict tools
12
+ - 💾 **Prompt Caching** - Cache points from `cacheBreakpoint`, with cache read/write usage
13
+ - 📄 **Documents, Images, Video** - Bytes or S3 locations
14
+ - 🎨 **Image Generation** - Stability AI models for image creation
15
+ - 📊 **Embeddings** - Amazon Titan embeddings for semantic search
16
+ - 🔧 **Type-Safe** - Full TypeScript support with type inference
17
+ - ⚡ **Regional Flexibility** - Deploy across any AWS region with Bedrock
18
+
19
+ ## Supported Models
20
+
21
+ ### Chat Models
22
+ - **Anthropic Claude** - Claude 3.x through 5.x
23
+ - **Amazon Nova** - Nova and Nova 2
24
+ - **OpenAI** - gpt-oss
25
+ - **Open-weight models** - DeepSeek, Qwen, Kimi, MiniMax, and more
26
+ - **Meta Llama** - Llama 2, Llama 3, Llama 3.1, Llama 3.2
27
+ - **Mistral AI** - Mistral 7B, Mixtral 8x7B, Mistral Large
28
+ - **Cohere** - Command, Command Light, Command R, Command R+
29
+ - **AI21 Labs** - Jurassic-2 models
30
+
31
+ ### Image Models
32
+ - **Stability AI** - Stable Diffusion XL, Stable Diffusion 3
33
+
34
+ ### Embedding Models
35
+ - **Amazon Titan** - Titan Text Embeddings v1 and v2
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ npm install @aeye/aws @aeye/ai @aeye/core zod
41
+ ```
42
+
43
+ ## Prerequisites
44
+
45
+ ### AWS Credentials
46
+
47
+ The provider uses the AWS SDK v3 credential chain to automatically discover credentials:
48
+
49
+ 1. **Environment variables** - `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`
50
+ 2. **Shared credentials file** - `~/.aws/credentials`
51
+ 3. **IAM roles** - When running on EC2, ECS, Lambda, etc.
52
+
53
+ ### AWS Bedrock Access
54
+
55
+ Ensure you have:
56
+ 1. Access to AWS Bedrock in your target region
57
+ 2. Permissions to invoke foundation models
58
+ 3. Model access enabled in the AWS Bedrock console
59
+
60
+ ## Quick Start
61
+
62
+ ### Basic Chat Completion
63
+
64
+ ```typescript
65
+ import { AI } from '@aeye/ai';
66
+ import { AWSBedrockProvider } from '@aeye/aws';
67
+
68
+ // Create provider (credentials picked up automatically)
69
+ const aws = new AWSBedrockProvider({
70
+ region: 'us-east-1',
71
+ });
72
+
73
+ // Create AI instance
74
+ const ai = AI.with()
75
+ .providers({ aws })
76
+ .create();
77
+
78
+ // Chat with Claude
79
+ const response = await ai.chat.get([
80
+ { role: 'user', content: 'What is AWS Bedrock?' }
81
+ ], {
82
+ model: 'anthropic.claude-3-sonnet-20240229-v1:0'
83
+ });
84
+
85
+ console.log(response.content);
86
+ ```
87
+
88
+ ### Streaming Responses
89
+
90
+ ```typescript
91
+ // Stream responses in real-time
92
+ for await (const chunk of ai.chat.stream([
93
+ { role: 'user', content: 'Write a poem about AI' }
94
+ ], {
95
+ model: 'anthropic.claude-3-haiku-20240307-v1:0'
96
+ })) {
97
+ if (chunk.content) {
98
+ process.stdout.write(chunk.content);
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Image Generation
104
+
105
+ ```typescript
106
+ import { AWSBedrockProvider } from '@aeye/aws';
107
+
108
+ const aws = new AWSBedrockProvider({
109
+ region: 'us-east-1',
110
+ defaultModels: {
111
+ imageGenerate: 'stability.stable-diffusion-xl-v1',
112
+ },
113
+ });
114
+
115
+ const ai = AI.with()
116
+ .providers({ aws })
117
+ .create();
118
+
119
+ const result = await ai.image.generate({
120
+ prompt: 'A serene mountain landscape at sunset',
121
+ size: { width: 1024, height: 1024 },
122
+ });
123
+
124
+ console.log('Image URL:', result.images[0].url);
125
+ ```
126
+
127
+ ### Text Embeddings
128
+
129
+ ```typescript
130
+ const aws = new AWSBedrockProvider({
131
+ region: 'us-east-1',
132
+ defaultModels: {
133
+ embedding: 'amazon.titan-embed-text-v1',
134
+ },
135
+ });
136
+
137
+ const ai = AI.with()
138
+ .providers({ aws })
139
+ .create();
140
+
141
+ const embeddings = await ai.embed.get({
142
+ input: 'AWS Bedrock is a fully managed service',
143
+ model: 'amazon.titan-embed-text-v1',
144
+ });
145
+
146
+ console.log('Embedding dimensions:', embeddings.embeddings[0].length);
147
+ ```
148
+
149
+ ## Configuration
150
+
151
+ ### Provider Configuration
152
+
153
+ ```typescript
154
+ import { AWSBedrockProvider, type AWSBedrockConfig } from '@aeye/aws';
155
+
156
+ const config: AWSBedrockConfig = {
157
+ // AWS region (defaults to AWS_REGION env var or 'us-east-1')
158
+ region: 'us-west-2',
159
+
160
+ // Optional: Explicit credentials (if not using default chain)
161
+ credentials: {
162
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
163
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
164
+ sessionToken: process.env.AWS_SESSION_TOKEN, // Optional
165
+ },
166
+
167
+ // Optional: Inference profile prefix. Without one, models served only
168
+ // through inference profiles use the region's geography (or global) profile
169
+ modelPrefix: 'us.',
170
+
171
+ // Optional: Latency-optimized inference, where the model offers it
172
+ latency: 'optimized',
173
+
174
+ // Optional: Guardrail applied to every chat request
175
+ guardrail: { guardrailIdentifier: 'gr-abc123', guardrailVersion: '1' },
176
+
177
+ // Optional: Default models for different capabilities
178
+ defaultModels: {
179
+ chat: 'anthropic.claude-3-sonnet-20240229-v1:0',
180
+ imageGenerate: 'stability.stable-diffusion-xl-v1',
181
+ embedding: 'amazon.titan-embed-text-v2:0',
182
+ },
183
+ };
184
+
185
+ const provider = new AWSBedrockProvider(config);
186
+ ```
187
+
188
+ ### Using with Multiple Providers
189
+
190
+ ```typescript
191
+ import { AI } from '@aeye/ai';
192
+ import { AWSBedrockProvider } from '@aeye/aws';
193
+ import { OpenAIProvider } from '@aeye/openai';
194
+
195
+ const aws = new AWSBedrockProvider({ region: 'us-east-1' });
196
+ const openai = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! });
197
+
198
+ const ai = AI.with()
199
+ .providers({ aws, openai })
200
+ .create({
201
+ // Automatic model selection across all providers
202
+ defaultMetadata: {
203
+ required: ['chat', 'streaming'],
204
+ weights: {
205
+ cost: 0.5,
206
+ speed: 0.3,
207
+ quality: 0.2,
208
+ },
209
+ },
210
+ });
211
+
212
+ // AI instance will automatically select the best model across AWS and OpenAI
213
+ const response = await ai.chat.get([
214
+ { role: 'user', content: 'Hello!' }
215
+ ]);
216
+ ```
217
+
218
+ ## Model IDs
219
+
220
+ ### Anthropic Claude Models
221
+
222
+ ```typescript
223
+ // Claude 3.5
224
+ 'anthropic.claude-3-5-sonnet-20240620-v1:0'
225
+ 'anthropic.claude-3-5-sonnet-20241022-v2:0'
226
+
227
+ // Claude 3
228
+ 'anthropic.claude-3-opus-20240229-v1:0'
229
+ 'anthropic.claude-3-sonnet-20240229-v1:0'
230
+ 'anthropic.claude-3-haiku-20240307-v1:0'
231
+
232
+ // Claude 2.x
233
+ 'anthropic.claude-v2:1'
234
+ 'anthropic.claude-v2'
235
+ 'anthropic.claude-instant-v1'
236
+ ```
237
+
238
+ ### Meta Llama Models
239
+
240
+ ```typescript
241
+ 'meta.llama3-2-1b-instruct-v1:0'
242
+ 'meta.llama3-2-3b-instruct-v1:0'
243
+ 'meta.llama3-2-11b-instruct-v1:0'
244
+ 'meta.llama3-2-90b-instruct-v1:0'
245
+ 'meta.llama3-1-8b-instruct-v1:0'
246
+ 'meta.llama3-1-70b-instruct-v1:0'
247
+ 'meta.llama3-1-405b-instruct-v1:0'
248
+ 'meta.llama3-8b-instruct-v1:0'
249
+ 'meta.llama3-70b-instruct-v1:0'
250
+ 'meta.llama2-13b-chat-v1'
251
+ 'meta.llama2-70b-chat-v1'
252
+ ```
253
+
254
+ ### Mistral AI Models
255
+
256
+ ```typescript
257
+ 'mistral.mistral-7b-instruct-v0:2'
258
+ 'mistral.mixtral-8x7b-instruct-v0:1'
259
+ 'mistral.mistral-large-2402-v1:0'
260
+ 'mistral.mistral-large-2407-v1:0'
261
+ ```
262
+
263
+ ### Cohere Models
264
+
265
+ ```typescript
266
+ 'cohere.command-text-v14'
267
+ 'cohere.command-light-text-v14'
268
+ 'cohere.command-r-v1:0'
269
+ 'cohere.command-r-plus-v1:0'
270
+ ```
271
+
272
+ ### Stability AI Models
273
+
274
+ ```typescript
275
+ 'stability.stable-diffusion-xl-v1'
276
+ 'stability.sd3-large-v1:0'
277
+ ```
278
+
279
+ ### Amazon Titan Models
280
+
281
+ ```typescript
282
+ // Embeddings
283
+ 'amazon.titan-embed-text-v1'
284
+ 'amazon.titan-embed-text-v2:0'
285
+
286
+ // Image Generation
287
+ 'amazon.titan-image-generator-v1'
288
+ 'amazon.titan-image-generator-v2:0'
289
+ ```
290
+
291
+ ## Advanced Features
292
+
293
+ ### Vision with Claude 3
294
+
295
+ ```typescript
296
+ const response = await ai.chat.get([
297
+ {
298
+ role: 'user',
299
+ content: [
300
+ { type: 'text', content: 'What do you see in this image?' },
301
+ { type: 'image', content: 'https://example.com/image.jpg' },
302
+ ],
303
+ },
304
+ ], {
305
+ model: 'anthropic.claude-3-sonnet-20240229-v1:0',
306
+ });
307
+ ```
308
+
309
+ ### Documents, Video, and S3
310
+
311
+ ```typescript
312
+ const response = await ai.chat.get([
313
+ {
314
+ role: 'user',
315
+ content: [
316
+ { type: 'text', content: 'Summarize the report and the clip.' },
317
+ { type: 'file', content: 's3://my-bucket/q3-report.pdf', name: 'Q3 report.pdf' },
318
+ { type: 'video', content: 's3://my-bucket/clip.mp4' },
319
+ ],
320
+ },
321
+ ], {
322
+ model: 'amazon.nova-pro-v1:0',
323
+ });
324
+ ```
325
+
326
+ `s3://` URIs are sent as S3 locations; other content is sent as bytes. The
327
+ format comes from `format`, the MIME type, or the file extension.
328
+
329
+ ### Reasoning
330
+
331
+ ```typescript
332
+ const response = await ai.chat.get([
333
+ { role: 'user', content: 'Prove that there are infinitely many primes.' },
334
+ ], {
335
+ model: 'anthropic.claude-opus-4-7',
336
+ reason: { effort: 'high' },
337
+ });
338
+
339
+ console.log(response.reasoning?.content);
340
+ ```
341
+
342
+ Claude 4.6+ thinks adaptively (`thinking.type: 'adaptive'` with
343
+ `outputConfig.effort`), earlier Claude takes a thinking budget, Nova 2 takes
344
+ `reasoningConfig`, and gpt-oss takes `reasoning_effort`. Reasoning blocks keep
345
+ their signatures and redacted content, and are sent back with the assistant
346
+ message on later turns, as Claude requires while it uses tools. Reasoning is
347
+ marked `provider: 'aws-bedrock'`, so OpenAI and OpenRouter don't replay it.
348
+
349
+ - Efforts are clamped to what the model accepts (Claude 4.6 gets `high` for `xhigh`).
350
+ - Claude can't think on a turn that forces a tool, so that turn is sent with
351
+ thinking disabled.
352
+ - Claude that always thinks (Opus 5.5, Sonnet 5.5, Fable) rejects both thinking
353
+ disabled and a forced tool choice: it is never sent `disabled`, and a forced
354
+ turn offers it only the forced tools with an automatic choice.
355
+
356
+ ### Structured Output
357
+
358
+ On Claude 4.5 and later, a tool or response schema goes strict (`strict: true`,
359
+ or `outputConfig.textFormat`) when it fits Anthropic's strict subset and
360
+ limits. Recursive schemas, open values and tuples, and requests past 24
361
+ optional or 16 union-typed parameters go non-strict instead, and a response
362
+ schema then goes in the prompt.
363
+
364
+ ### Prompt Caching
365
+
366
+ ```typescript
367
+ const response = await ai.chat.get([
368
+ { role: 'system', content: [{ type: 'text', content: longInstructions, cacheBreakpoint: true }] },
369
+ { role: 'user', content: 'First question' },
370
+ ], {
371
+ model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
372
+ });
373
+
374
+ console.log(response.usage?.text?.cached, response.usage?.text?.cacheWrite);
375
+ ```
376
+
377
+ Models without prompt caching (gpt-oss, Llama, DeepSeek, Nemotron, ...) reject
378
+ cache points, so they're left out for models whose registry pricing has no
379
+ cache reads.
380
+
381
+ ### Custom Request Parameters
382
+
383
+ ```typescript
384
+ const response = await ai.chat.get([
385
+ { role: 'user', content: 'Hello!' }
386
+ ], {
387
+ model: 'anthropic.claude-3-haiku-20240307-v1:0',
388
+ temperature: 0.7,
389
+ maxTokens: 2048,
390
+ topP: 0.9,
391
+ stop: ['Human:', 'Assistant:'],
392
+ serviceTier: 'flex', // Converse serviceTier (fast → priority)
393
+ metadata: { team: 'search' }, // Converse requestMetadata
394
+ extra: { top_k: 50 }, // additionalModelRequestFields
395
+ });
396
+ ```
397
+
398
+ ### Multi-Region Setup
399
+
400
+ ```typescript
401
+ // Primary region
402
+ const awsEast = new AWSBedrockProvider({
403
+ region: 'us-east-1',
404
+ });
405
+
406
+ // Fallback region
407
+ const awsWest = new AWSBedrockProvider({
408
+ region: 'us-west-2',
409
+ });
410
+
411
+ const ai = AI.with()
412
+ .providers({ awsEast, awsWest })
413
+ .create();
414
+ ```
415
+
416
+ ### Inference Profiles
417
+
418
+ Without a `modelPrefix`, a model the registry marks as served only through
419
+ inference profiles is called by the profile for the region's geography (`us.`,
420
+ `eu.`, `apac.`), or its `global.` profile. When Bedrock answers that a model's
421
+ "on-demand throughput isn't supported" in this region, the request is sent
422
+ again by profile, and that model is called by profile from then on.
423
+
424
+ ## Error Handling
425
+
426
+ ```typescript
427
+ import {
428
+ AWSError,
429
+ AWSAuthError,
430
+ AWSRateLimitError,
431
+ AWSQuotaError,
432
+ AWSContextWindowError,
433
+ } from '@aeye/aws';
434
+
435
+ try {
436
+ const response = await ai.chat.get([
437
+ { role: 'user', content: 'Hello!' }
438
+ ]);
439
+ } catch (error) {
440
+ if (error instanceof AWSAuthError) {
441
+ console.error('Authentication failed. Check your AWS credentials.');
442
+ } else if (error instanceof AWSRateLimitError) {
443
+ console.error('Rate limit exceeded. Retry after:', error.retryAfter);
444
+ } else if (error instanceof AWSQuotaError) {
445
+ console.error('AWS quota exceeded. Request quota increase.');
446
+ } else if (error instanceof AWSContextWindowError) {
447
+ console.error('Input too long for model context window.');
448
+ } else if (error instanceof AWSError) {
449
+ console.error('AWS Bedrock error:', error.message);
450
+ }
451
+ }
452
+ ```
453
+
454
+ `AccessDeniedException` (including a model the account can't use) throws
455
+ `AWSAuthError`; `ServiceUnavailableException` throws `AWSRateLimitError`; Claude's
456
+ "prompt is too long" and Nova's "Input Tokens Exceeded" throw `AWSContextWindowError`.
457
+
458
+ ## Health Check
459
+
460
+ ```typescript
461
+ const isHealthy = await aws.checkHealth();
462
+ console.log('AWS Bedrock is accessible:', isHealthy);
463
+ ```
464
+
465
+ ## List Available Models
466
+
467
+ ```typescript
468
+ const models = await aws.listModels();
469
+ console.log('Available models:', models.map(m => m.id));
470
+
471
+ // Filter by capability
472
+ const chatModels = models.filter(m => m.capabilities.has('chat'));
473
+ const imageModels = models.filter(m => m.capabilities.has('image'));
474
+ const embeddingModels = models.filter(m => m.capabilities.has('embedding'));
475
+ ```
476
+
477
+ ## Best Practices
478
+
479
+ 1. **Use IAM Roles** - When running on AWS infrastructure (EC2, ECS, Lambda), use IAM roles instead of hardcoded credentials
480
+ 2. **Region Selection** - Choose regions close to your users for lower latency
481
+ 3. **Model Selection** - Use smaller models (Haiku, 7B) for faster, cheaper responses when appropriate
482
+ 4. **Streaming** - Enable streaming for better user experience with long responses
483
+ 5. **Error Handling** - Implement proper error handling and retry logic for production use
484
+ 6. **Cost Management** - Monitor usage through AWS Cost Explorer and set up billing alerts
485
+
486
+ ## Environment Variables
487
+
488
+ ```bash
489
+ # AWS credentials (if not using IAM roles)
490
+ AWS_ACCESS_KEY_ID=your_access_key
491
+ AWS_SECRET_ACCESS_KEY=your_secret_key
492
+ AWS_SESSION_TOKEN=your_session_token # Optional
493
+
494
+ # AWS region
495
+ AWS_REGION=us-east-1
496
+ ```
497
+
498
+ ## Links
499
+
500
+ - [AWS Bedrock Documentation](https://docs.aws.amazon.com/bedrock/)
501
+ - [Model IDs Reference](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html)
502
+ - [@aeye Framework](https://github.com/ClickerMonkey/aeye)
503
+ - [AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v3/)
504
+
505
+ ## License
506
+
507
+ GPL-3.0 - See [LICENSE](../../LICENSE) file for details.
508
+
509
+ ## Contributing
510
+
511
+ Issues and pull requests are welcome! See the [main repository](https://github.com/ClickerMonkey/aeye) for contribution guidelines.