@ai-sdk/anthropic-aws 0.0.0 → 1.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @ai-sdk/anthropic-aws
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d61a788]
8
+ - @ai-sdk/anthropic@3.0.79
9
+
10
+ ## 1.0.0
11
+
12
+ ### Major Changes
13
+
14
+ - 4dd238c: feat (provider/anthropic-aws): new @ai-sdk/anthropic-aws provider (v1.0.0)
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # AI SDK - Claude Platform on AWS Provider
2
+
3
+ The **[Claude Platform on AWS provider](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic-aws)** for the [AI SDK](https://ai-sdk.dev/docs)
4
+ gives you access to the Anthropic Messages API hosted in AWS at
5
+ `aws-external-anthropic.{region}.api.aws`, authenticated with AWS SigV4 or an
6
+ AWS-provisioned API key.
7
+
8
+ Same wire format and feature set as `@ai-sdk/anthropic` — model IDs, streaming,
9
+ prompt caching, tool use, computer use, and `anthropic-beta` headers all match
10
+ the first-party Claude API.
11
+
12
+ ## Setup
13
+
14
+ ```bash
15
+ npm install @ai-sdk/anthropic-aws
16
+ ```
17
+
18
+ ## Provider Instance
19
+
20
+ ```ts
21
+ import { createAnthropicAws } from '@ai-sdk/anthropic-aws';
22
+
23
+ // SigV4 — picks up AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN
24
+ const anthropicAws = createAnthropicAws({
25
+ region: 'us-west-2',
26
+ workspaceId: 'wrkspc_…',
27
+ });
28
+ ```
29
+
30
+ ## Example
31
+
32
+ ```ts
33
+ import { createAnthropicAws } from '@ai-sdk/anthropic-aws';
34
+ import { generateText } from 'ai';
35
+
36
+ const anthropicAws = createAnthropicAws();
37
+
38
+ const { text } = await generateText({
39
+ model: anthropicAws('claude-sonnet-4-6'),
40
+ prompt: 'Invent a new holiday and describe its traditions.',
41
+ });
42
+ ```
43
+
44
+ ## Documentation
45
+
46
+ Please check out the **[Claude Platform on AWS provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic-aws)** for more information.
@@ -0,0 +1,94 @@
1
+ import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { AnthropicMessagesModelId, anthropicTools } from '@ai-sdk/anthropic/internal';
4
+
5
+ interface AnthropicAwsCredentials {
6
+ region: string;
7
+ accessKeyId: string;
8
+ secretAccessKey: string;
9
+ sessionToken?: string;
10
+ }
11
+
12
+ interface AnthropicAwsProvider extends ProviderV3 {
13
+ /**
14
+ * Creates a model for text generation.
15
+ */
16
+ (modelId: AnthropicMessagesModelId): LanguageModelV3;
17
+ /**
18
+ * Creates a model for text generation.
19
+ */
20
+ languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
21
+ /**
22
+ * @deprecated Use `embeddingModel` instead.
23
+ */
24
+ textEmbeddingModel(modelId: string): never;
25
+ tools: typeof anthropicTools;
26
+ }
27
+ interface AnthropicAwsProviderSettings {
28
+ /**
29
+ * The AWS region to use for Claude Platform on AWS. Defaults to the value of the
30
+ * `AWS_REGION` environment variable. Required — no fallback default.
31
+ */
32
+ region?: string;
33
+ /**
34
+ * The Anthropic workspace ID for this AWS account. Sent on every request via the
35
+ * `anthropic-workspace-id` header. Defaults to the value of the
36
+ * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.
37
+ */
38
+ workspaceId?: string;
39
+ /**
40
+ * API key for authenticating requests via the `x-api-key` header.
41
+ * When provided, this will be used instead of AWS SigV4 authentication.
42
+ * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.
43
+ */
44
+ apiKey?: string;
45
+ /**
46
+ * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the
47
+ * `AWS_ACCESS_KEY_ID` environment variable.
48
+ */
49
+ accessKeyId?: string;
50
+ /**
51
+ * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the
52
+ * `AWS_SECRET_ACCESS_KEY` environment variable.
53
+ */
54
+ secretAccessKey?: string;
55
+ /**
56
+ * The AWS session token to use for SigV4 authentication. Defaults to the value of the
57
+ * `AWS_SESSION_TOKEN` environment variable.
58
+ */
59
+ sessionToken?: string;
60
+ /**
61
+ * Base URL for the Claude Platform on AWS API calls.
62
+ */
63
+ baseURL?: string;
64
+ /**
65
+ * Custom headers to include in the requests.
66
+ */
67
+ headers?: Record<string, string | undefined>;
68
+ /**
69
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
70
+ * or to provide a custom fetch implementation for e.g. testing.
71
+ */
72
+ fetch?: FetchFunction;
73
+ /**
74
+ * The AWS credential provider to use to get dynamic credentials similar to the
75
+ * AWS SDK. Setting a provider here will cause its credential values to be used
76
+ * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.
77
+ */
78
+ credentialProvider?: () => PromiseLike<Omit<AnthropicAwsCredentials, 'region'>>;
79
+ generateId?: () => string;
80
+ }
81
+ /**
82
+ * Create a Claude Platform on AWS provider instance.
83
+ * This provider uses the Anthropic Messages API hosted in AWS, authenticated
84
+ * with AWS SigV4 or an AWS-provisioned API key.
85
+ */
86
+ declare function createAnthropicAws(options?: AnthropicAwsProviderSettings): AnthropicAwsProvider;
87
+ /**
88
+ * Default Claude Platform on AWS provider instance.
89
+ */
90
+ declare const anthropicAws: AnthropicAwsProvider;
91
+
92
+ declare const VERSION: string;
93
+
94
+ export { type AnthropicAwsCredentials, type AnthropicAwsProvider, type AnthropicAwsProviderSettings, VERSION, anthropicAws, createAnthropicAws };
@@ -0,0 +1,94 @@
1
+ import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { AnthropicMessagesModelId, anthropicTools } from '@ai-sdk/anthropic/internal';
4
+
5
+ interface AnthropicAwsCredentials {
6
+ region: string;
7
+ accessKeyId: string;
8
+ secretAccessKey: string;
9
+ sessionToken?: string;
10
+ }
11
+
12
+ interface AnthropicAwsProvider extends ProviderV3 {
13
+ /**
14
+ * Creates a model for text generation.
15
+ */
16
+ (modelId: AnthropicMessagesModelId): LanguageModelV3;
17
+ /**
18
+ * Creates a model for text generation.
19
+ */
20
+ languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
21
+ /**
22
+ * @deprecated Use `embeddingModel` instead.
23
+ */
24
+ textEmbeddingModel(modelId: string): never;
25
+ tools: typeof anthropicTools;
26
+ }
27
+ interface AnthropicAwsProviderSettings {
28
+ /**
29
+ * The AWS region to use for Claude Platform on AWS. Defaults to the value of the
30
+ * `AWS_REGION` environment variable. Required — no fallback default.
31
+ */
32
+ region?: string;
33
+ /**
34
+ * The Anthropic workspace ID for this AWS account. Sent on every request via the
35
+ * `anthropic-workspace-id` header. Defaults to the value of the
36
+ * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.
37
+ */
38
+ workspaceId?: string;
39
+ /**
40
+ * API key for authenticating requests via the `x-api-key` header.
41
+ * When provided, this will be used instead of AWS SigV4 authentication.
42
+ * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.
43
+ */
44
+ apiKey?: string;
45
+ /**
46
+ * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the
47
+ * `AWS_ACCESS_KEY_ID` environment variable.
48
+ */
49
+ accessKeyId?: string;
50
+ /**
51
+ * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the
52
+ * `AWS_SECRET_ACCESS_KEY` environment variable.
53
+ */
54
+ secretAccessKey?: string;
55
+ /**
56
+ * The AWS session token to use for SigV4 authentication. Defaults to the value of the
57
+ * `AWS_SESSION_TOKEN` environment variable.
58
+ */
59
+ sessionToken?: string;
60
+ /**
61
+ * Base URL for the Claude Platform on AWS API calls.
62
+ */
63
+ baseURL?: string;
64
+ /**
65
+ * Custom headers to include in the requests.
66
+ */
67
+ headers?: Record<string, string | undefined>;
68
+ /**
69
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
70
+ * or to provide a custom fetch implementation for e.g. testing.
71
+ */
72
+ fetch?: FetchFunction;
73
+ /**
74
+ * The AWS credential provider to use to get dynamic credentials similar to the
75
+ * AWS SDK. Setting a provider here will cause its credential values to be used
76
+ * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.
77
+ */
78
+ credentialProvider?: () => PromiseLike<Omit<AnthropicAwsCredentials, 'region'>>;
79
+ generateId?: () => string;
80
+ }
81
+ /**
82
+ * Create a Claude Platform on AWS provider instance.
83
+ * This provider uses the Anthropic Messages API hosted in AWS, authenticated
84
+ * with AWS SigV4 or an AWS-provisioned API key.
85
+ */
86
+ declare function createAnthropicAws(options?: AnthropicAwsProviderSettings): AnthropicAwsProvider;
87
+ /**
88
+ * Default Claude Platform on AWS provider instance.
89
+ */
90
+ declare const anthropicAws: AnthropicAwsProvider;
91
+
92
+ declare const VERSION: string;
93
+
94
+ export { type AnthropicAwsCredentials, type AnthropicAwsProvider, type AnthropicAwsProviderSettings, VERSION, anthropicAws, createAnthropicAws };
package/dist/index.js ADDED
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ VERSION: () => VERSION,
24
+ anthropicAws: () => anthropicAws,
25
+ createAnthropicAws: () => createAnthropicAws
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/anthropic-aws-provider.ts
30
+ var import_provider = require("@ai-sdk/provider");
31
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
32
+ var import_internal = require("@ai-sdk/anthropic/internal");
33
+
34
+ // src/anthropic-aws-fetch.ts
35
+ var import_provider_utils = require("@ai-sdk/provider-utils");
36
+ var import_aws4fetch = require("aws4fetch");
37
+
38
+ // src/version.ts
39
+ var VERSION = true ? "1.0.1" : "0.0.0-test";
40
+
41
+ // src/anthropic-aws-fetch.ts
42
+ function createSigV4FetchFunction(getCredentials, fetch) {
43
+ return async (input, init) => {
44
+ var _a, _b;
45
+ const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
46
+ const request = input instanceof Request ? input : void 0;
47
+ const originalHeaders = (0, import_provider_utils.combineHeaders)(
48
+ (0, import_provider_utils.normalizeHeaders)(request == null ? void 0 : request.headers),
49
+ (0, import_provider_utils.normalizeHeaders)(init == null ? void 0 : init.headers)
50
+ );
51
+ const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
52
+ originalHeaders,
53
+ `ai-sdk/anthropic-aws/${VERSION}`,
54
+ (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
55
+ );
56
+ let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
57
+ if (effectiveBody === void 0 && request && request.body !== null) {
58
+ try {
59
+ effectiveBody = await request.clone().text();
60
+ } catch (e) {
61
+ }
62
+ }
63
+ const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
64
+ if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
65
+ return effectiveFetch(input, {
66
+ ...init,
67
+ headers: headersWithUserAgent
68
+ });
69
+ }
70
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
71
+ const body = prepareBodyString(effectiveBody);
72
+ const credentials = await getCredentials();
73
+ const signer = new import_aws4fetch.AwsV4Signer({
74
+ url,
75
+ method: "POST",
76
+ headers: Object.entries(headersWithUserAgent),
77
+ body,
78
+ region: credentials.region,
79
+ accessKeyId: credentials.accessKeyId,
80
+ secretAccessKey: credentials.secretAccessKey,
81
+ sessionToken: credentials.sessionToken,
82
+ service: "aws-external-anthropic"
83
+ });
84
+ const signingResult = await signer.sign();
85
+ const signedHeaders = (0, import_provider_utils.normalizeHeaders)(signingResult.headers);
86
+ const combinedHeaders = (0, import_provider_utils.combineHeaders)(headersWithUserAgent, signedHeaders);
87
+ return effectiveFetch(input, {
88
+ ...init,
89
+ body,
90
+ headers: combinedHeaders
91
+ });
92
+ };
93
+ }
94
+ function prepareBodyString(body) {
95
+ if (typeof body === "string") {
96
+ return body;
97
+ } else if (body instanceof Uint8Array) {
98
+ return new TextDecoder().decode(body);
99
+ } else if (body instanceof ArrayBuffer) {
100
+ return new TextDecoder().decode(new Uint8Array(body));
101
+ } else {
102
+ return JSON.stringify(body);
103
+ }
104
+ }
105
+ function createApiKeyFetchFunction(apiKey, fetch) {
106
+ return async (input, init) => {
107
+ const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
108
+ const originalHeaders = (0, import_provider_utils.normalizeHeaders)(init == null ? void 0 : init.headers);
109
+ const headersWithUserAgent = (0, import_provider_utils.withUserAgentSuffix)(
110
+ originalHeaders,
111
+ `ai-sdk/anthropic-aws/${VERSION}`,
112
+ (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
113
+ );
114
+ const finalHeaders = (0, import_provider_utils.combineHeaders)(headersWithUserAgent, {
115
+ "x-api-key": apiKey
116
+ });
117
+ return effectiveFetch(input, {
118
+ ...init,
119
+ headers: finalHeaders
120
+ });
121
+ };
122
+ }
123
+
124
+ // src/anthropic-aws-provider.ts
125
+ function createAnthropicAws(options = {}) {
126
+ const apiKey = (0, import_provider_utils2.loadOptionalSetting)({
127
+ settingValue: options.apiKey,
128
+ environmentVariableName: "ANTHROPIC_AWS_API_KEY"
129
+ });
130
+ const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
131
+ const region = (0, import_provider_utils2.loadSetting)({
132
+ settingValue: options.region,
133
+ settingName: "region",
134
+ environmentVariableName: "AWS_REGION",
135
+ description: "AWS region"
136
+ });
137
+ if (options.credentialProvider) {
138
+ try {
139
+ return {
140
+ ...await options.credentialProvider(),
141
+ region
142
+ };
143
+ } catch (error) {
144
+ const errorMessage = error instanceof Error ? error.message : String(error);
145
+ throw new Error(
146
+ `AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
147
+ );
148
+ }
149
+ }
150
+ try {
151
+ return {
152
+ region,
153
+ accessKeyId: (0, import_provider_utils2.loadSetting)({
154
+ settingValue: options.accessKeyId,
155
+ settingName: "accessKeyId",
156
+ environmentVariableName: "AWS_ACCESS_KEY_ID",
157
+ description: "AWS access key ID"
158
+ }),
159
+ secretAccessKey: (0, import_provider_utils2.loadSetting)({
160
+ settingValue: options.secretAccessKey,
161
+ settingName: "secretAccessKey",
162
+ environmentVariableName: "AWS_SECRET_ACCESS_KEY",
163
+ description: "AWS secret access key"
164
+ }),
165
+ sessionToken: (0, import_provider_utils2.loadOptionalSetting)({
166
+ settingValue: options.sessionToken,
167
+ environmentVariableName: "AWS_SESSION_TOKEN"
168
+ })
169
+ };
170
+ } catch (error) {
171
+ const errorMessage = error instanceof Error ? error.message : String(error);
172
+ if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
173
+ throw new Error(
174
+ `AWS SigV4 authentication requires AWS credentials. Please provide either:
175
+ 1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
176
+ 2. Provide accessKeyId and secretAccessKey in options
177
+ 3. Use a credentialProvider function
178
+ 4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option
179
+ Original error: ${errorMessage}`
180
+ );
181
+ }
182
+ if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
183
+ throw new Error(
184
+ `AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
185
+ Original error: ${errorMessage}`
186
+ );
187
+ }
188
+ throw error;
189
+ }
190
+ }, options.fetch);
191
+ const getBaseURL = () => {
192
+ var _a;
193
+ return (_a = (0, import_provider_utils2.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://aws-external-anthropic.${(0, import_provider_utils2.loadSetting)({
194
+ settingValue: options.region,
195
+ settingName: "region",
196
+ environmentVariableName: "AWS_REGION",
197
+ description: "AWS region"
198
+ })}.api.aws/v1`;
199
+ };
200
+ const getHeaders = () => ({
201
+ "anthropic-version": "2023-06-01",
202
+ "anthropic-workspace-id": (0, import_provider_utils2.loadSetting)({
203
+ settingValue: options.workspaceId,
204
+ settingName: "workspaceId",
205
+ environmentVariableName: "ANTHROPIC_AWS_WORKSPACE_ID",
206
+ description: "Anthropic AWS workspace ID"
207
+ }),
208
+ ...options.headers
209
+ });
210
+ const createChatModel = (modelId) => new import_internal.AnthropicMessagesLanguageModel(modelId, {
211
+ provider: "anthropic-aws.messages",
212
+ baseURL: getBaseURL(),
213
+ headers: getHeaders,
214
+ fetch: fetchFunction,
215
+ generateId: options.generateId,
216
+ supportedUrls: () => ({
217
+ "image/*": [/^https?:\/\/.*$/],
218
+ "application/pdf": [/^https?:\/\/.*$/]
219
+ })
220
+ });
221
+ const provider = function(modelId) {
222
+ if (new.target) {
223
+ throw new Error(
224
+ "The Anthropic AWS model function cannot be called with the new keyword."
225
+ );
226
+ }
227
+ return createChatModel(modelId);
228
+ };
229
+ provider.specificationVersion = "v3";
230
+ provider.languageModel = createChatModel;
231
+ provider.chat = createChatModel;
232
+ provider.messages = createChatModel;
233
+ provider.embeddingModel = (modelId) => {
234
+ throw new import_provider.NoSuchModelError({ modelId, modelType: "embeddingModel" });
235
+ };
236
+ provider.textEmbeddingModel = provider.embeddingModel;
237
+ provider.imageModel = (modelId) => {
238
+ throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
239
+ };
240
+ provider.tools = import_internal.anthropicTools;
241
+ return provider;
242
+ }
243
+ var anthropicAws = createAnthropicAws();
244
+ // Annotate the CommonJS export names for ESM import in node:
245
+ 0 && (module.exports = {
246
+ VERSION,
247
+ anthropicAws,
248
+ createAnthropicAws
249
+ });
250
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/anthropic-aws-provider.ts","../src/anthropic-aws-fetch.ts","../src/version.ts"],"sourcesContent":["export { anthropicAws, createAnthropicAws } from './anthropic-aws-provider';\nexport type {\n AnthropicAwsProvider,\n AnthropicAwsProviderSettings,\n} from './anthropic-aws-provider';\nexport type { AnthropicAwsCredentials } from './anthropic-aws-fetch';\nexport { VERSION } from './version';\n","import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n AnthropicMessagesLanguageModel,\n anthropicTools,\n type AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AnthropicAwsCredentials,\n} from './anthropic-aws-fetch';\n\nexport interface AnthropicAwsProvider extends ProviderV3 {\n /**\n * Creates a model for text generation.\n */\n (modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n\n tools: typeof anthropicTools;\n}\n\nexport interface AnthropicAwsProviderSettings {\n /**\n * The AWS region to use for Claude Platform on AWS. Defaults to the value of the\n * `AWS_REGION` environment variable. Required — no fallback default.\n */\n region?: string;\n\n /**\n * The Anthropic workspace ID for this AWS account. Sent on every request via the\n * `anthropic-workspace-id` header. Defaults to the value of the\n * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.\n */\n workspaceId?: string;\n\n /**\n * API key for authenticating requests via the `x-api-key` header.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Claude Platform on AWS API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use to get dynamic credentials similar to the\n * AWS SDK. Setting a provider here will cause its credential values to be used\n * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AnthropicAwsCredentials, 'region'>\n >;\n\n generateId?: () => string;\n}\n\n/**\n * Create a Claude Platform on AWS provider instance.\n * This provider uses the Anthropic Messages API hosted in AWS, authenticated\n * with AWS SigV4 or an AWS-provisioned API key.\n */\nexport function createAnthropicAws(\n options: AnthropicAwsProviderSettings = {},\n): AnthropicAwsProvider {\n const apiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'ANTHROPIC_AWS_API_KEY',\n });\n\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n }, options.fetch);\n\n const getBaseURL = (): string =>\n withoutTrailingSlash(options.baseURL) ??\n `https://aws-external-anthropic.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/v1`;\n\n const getHeaders = (): Record<string, string | undefined> => ({\n 'anthropic-version': '2023-06-01',\n 'anthropic-workspace-id': loadSetting({\n settingValue: options.workspaceId,\n settingName: 'workspaceId',\n environmentVariableName: 'ANTHROPIC_AWS_WORKSPACE_ID',\n description: 'Anthropic AWS workspace ID',\n }),\n ...options.headers,\n });\n\n const createChatModel = (modelId: AnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'anthropic-aws.messages',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n generateId: options.generateId,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n 'application/pdf': [/^https?:\\/\\/.*$/],\n }),\n });\n\n const provider = function (modelId: AnthropicMessagesModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic AWS model function cannot be called with the new keyword.',\n );\n }\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n\n/**\n * Default Claude Platform on AWS provider instance.\n */\nexport const anthropicAws = createAnthropicAws();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AnthropicAwsCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for\n * Claude Platform on AWS.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AnthropicAwsCredentials\n | PromiseLike<AnthropicAwsCredentials>,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'aws-external-anthropic',\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies x-api-key header authentication.\n *\n * @param apiKey - The API key to use for x-api-key header authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds the x-api-key header to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n 'x-api-key': apiKey,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAIO;AACP,IAAAA,yBAKO;AACP,sBAIO;;;ACfP,4BAMO;AACP,uBAA4B;;;ACLrB,IAAM,UACX,OACI,UACA;;;ADoBC,SAAS,yBACd,gBAGA,OACe;AACf,SAAO,OACL,OACA,SACsB;AAlC1B;AAmCI,UAAM,iBAAiB,wBAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,sBAAkB;AAAA,UACtB,wCAAiB,mCAAS,OAAO;AAAA,UACjC,wCAAiB,6BAAM,OAAO;AAAA,IAChC;AACA,UAAM,2BAAuB;AAAA,MAC3B;AAAA,MACA,wBAAwB,OAAO;AAAA,UAC/B,sDAA+B;AAAA,IACjC;AAEA,QAAI,iBAAsC,kCAAM,SAAN,YAAc;AACxD,QAAI,kBAAkB,UAAa,WAAW,QAAQ,SAAS,MAAM;AACnE,UAAI;AACF,wBAAgB,MAAM,QAAQ,MAAM,EAAE,KAAK;AAAA,MAC7C,SAAQ;AAAA,MAAC;AAAA,IACX;AAEA,UAAM,mBAAkB,kCAAM,WAAN,YAAgB,mCAAS;AAEjD,SAAI,mDAAiB,mBAAkB,UAAU,CAAC,eAAe;AAC/D,aAAO,eAAe,OAAO;AAAA,QAC3B,GAAG;AAAA,QACH,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAEA,UAAM,MACJ,OAAO,UAAU,WACb,QACA,iBAAiB,MACf,MAAM,OACN,MAAM;AAEd,UAAM,OAAO,kBAAkB,aAAa;AAC5C,UAAM,cAAc,MAAM,eAAe;AACzC,UAAM,SAAS,IAAI,6BAAY;AAAA,MAC7B;AAAA,MACA,QAAQ;AAAA,MACR,SAAS,OAAO,QAAQ,oBAAoB;AAAA,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