@aeye/aws 0.4.0 → 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,479 +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
- - 🧠 **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.
347
-
348
- ### Prompt Caching
349
-
350
- ```typescript
351
- const response = await ai.chat.get([
352
- { role: 'system', content: [{ type: 'text', content: longInstructions, cacheBreakpoint: true }] },
353
- { role: 'user', content: 'First question' },
354
- ], {
355
- model: 'anthropic.claude-sonnet-4-5-20250929-v1:0',
356
- });
357
-
358
- console.log(response.usage?.text?.cached, response.usage?.text?.cacheWrite);
359
- ```
360
-
361
- ### Custom Request Parameters
362
-
363
- ```typescript
364
- const response = await ai.chat.get([
365
- { role: 'user', content: 'Hello!' }
366
- ], {
367
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
368
- temperature: 0.7,
369
- maxTokens: 2048,
370
- topP: 0.9,
371
- stop: ['Human:', 'Assistant:'],
372
- serviceTier: 'flex', // Converse serviceTier (fast → priority)
373
- metadata: { team: 'search' }, // Converse requestMetadata
374
- extra: { top_k: 50 }, // additionalModelRequestFields
375
- });
376
- ```
377
-
378
- ### Multi-Region Setup
379
-
380
- ```typescript
381
- // Primary region
382
- const awsEast = new AWSBedrockProvider({
383
- region: 'us-east-1',
384
- });
385
-
386
- // Fallback region
387
- const awsWest = new AWSBedrockProvider({
388
- region: 'us-west-2',
389
- });
390
-
391
- const ai = AI.with()
392
- .providers({ awsEast, awsWest })
393
- .create();
394
- ```
395
-
396
- ## Error Handling
397
-
398
- ```typescript
399
- import {
400
- AWSError,
401
- AWSAuthError,
402
- AWSRateLimitError,
403
- AWSQuotaError,
404
- AWSContextWindowError,
405
- } from '@aeye/aws';
406
-
407
- try {
408
- const response = await ai.chat.get([
409
- { role: 'user', content: 'Hello!' }
410
- ]);
411
- } catch (error) {
412
- if (error instanceof AWSAuthError) {
413
- console.error('Authentication failed. Check your AWS credentials.');
414
- } else if (error instanceof AWSRateLimitError) {
415
- console.error('Rate limit exceeded. Retry after:', error.retryAfter);
416
- } else if (error instanceof AWSQuotaError) {
417
- console.error('AWS quota exceeded. Request quota increase.');
418
- } else if (error instanceof AWSContextWindowError) {
419
- console.error('Input too long for model context window.');
420
- } else if (error instanceof AWSError) {
421
- console.error('AWS Bedrock error:', error.message);
422
- }
423
- }
424
- ```
425
-
426
- ## Health Check
427
-
428
- ```typescript
429
- const isHealthy = await aws.checkHealth();
430
- console.log('AWS Bedrock is accessible:', isHealthy);
431
- ```
432
-
433
- ## List Available Models
434
-
435
- ```typescript
436
- const models = await aws.listModels();
437
- console.log('Available models:', models.map(m => m.id));
438
-
439
- // Filter by capability
440
- const chatModels = models.filter(m => m.capabilities.has('chat'));
441
- const imageModels = models.filter(m => m.capabilities.has('image'));
442
- const embeddingModels = models.filter(m => m.capabilities.has('embedding'));
443
- ```
444
-
445
- ## Best Practices
446
-
447
- 1. **Use IAM Roles** - When running on AWS infrastructure (EC2, ECS, Lambda), use IAM roles instead of hardcoded credentials
448
- 2. **Region Selection** - Choose regions close to your users for lower latency
449
- 3. **Model Selection** - Use smaller models (Haiku, 7B) for faster, cheaper responses when appropriate
450
- 4. **Streaming** - Enable streaming for better user experience with long responses
451
- 5. **Error Handling** - Implement proper error handling and retry logic for production use
452
- 6. **Cost Management** - Monitor usage through AWS Cost Explorer and set up billing alerts
453
-
454
- ## Environment Variables
455
-
456
- ```bash
457
- # AWS credentials (if not using IAM roles)
458
- AWS_ACCESS_KEY_ID=your_access_key
459
- AWS_SECRET_ACCESS_KEY=your_secret_key
460
- AWS_SESSION_TOKEN=your_session_token # Optional
461
-
462
- # AWS region
463
- AWS_REGION=us-east-1
464
- ```
465
-
466
- ## Links
467
-
468
- - [AWS Bedrock Documentation](https://docs.aws.amazon.com/bedrock/)
469
- - [Model IDs Reference](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html)
470
- - [@aeye Framework](https://github.com/ClickerMonkey/aeye)
471
- - [AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v3/)
472
-
473
- ## License
474
-
475
- GPL-3.0 - See [LICENSE](../../LICENSE) file for details.
476
-
477
- ## Contributing
478
-
479
- 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.