@anthropic-ai/aws-sdk 0.2.0 → 0.2.4
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 +35 -0
- package/client.d.mts +21 -6
- package/client.d.mts.map +1 -1
- package/client.d.ts +21 -6
- package/client.d.ts.map +1 -1
- package/client.js +54 -14
- package/client.js.map +1 -1
- package/client.mjs +54 -14
- package/client.mjs.map +1 -1
- package/package.json +3 -1
- package/src/client.ts +79 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.4 (2026-04-07)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [aws-sdk-v0.2.3...aws-sdk-v0.2.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/aws-sdk-v0.2.3...aws-sdk-v0.2.4)
|
|
6
|
+
|
|
7
|
+
### Chores
|
|
8
|
+
|
|
9
|
+
* **internal:** version bump ([eb97e85](https://github.com/anthropics/anthropic-sdk-typescript/commit/eb97e8577279fb150582297d2a0924a297185c3c))
|
|
10
|
+
* **internal:** version bump ([8ebaf61](https://github.com/anthropics/anthropic-sdk-typescript/commit/8ebaf616d2e5c6aebc153f19a403dde41ab5a9f1))
|
|
11
|
+
|
|
12
|
+
## 0.2.3 (2026-04-07)
|
|
13
|
+
|
|
14
|
+
Full Changelog: [aws-sdk-v0.2.2...aws-sdk-v0.2.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/aws-sdk-v0.2.2...aws-sdk-v0.2.3)
|
|
15
|
+
|
|
16
|
+
### Chores
|
|
17
|
+
|
|
18
|
+
* **internal:** version bump ([eb97e85](https://github.com/anthropics/anthropic-sdk-typescript/commit/eb97e8577279fb150582297d2a0924a297185c3c))
|
|
19
|
+
* **internal:** version bump ([8ebaf61](https://github.com/anthropics/anthropic-sdk-typescript/commit/8ebaf616d2e5c6aebc153f19a403dde41ab5a9f1))
|
|
20
|
+
|
|
21
|
+
## 0.2.2 (2026-04-07)
|
|
22
|
+
|
|
23
|
+
Full Changelog: [aws-sdk-v0.2.1...aws-sdk-v0.2.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/aws-sdk-v0.2.1...aws-sdk-v0.2.2)
|
|
24
|
+
|
|
25
|
+
### Chores
|
|
26
|
+
|
|
27
|
+
* **internal:** version bump ([eb97e85](https://github.com/anthropics/anthropic-sdk-typescript/commit/eb97e8577279fb150582297d2a0924a297185c3c))
|
|
28
|
+
* **internal:** version bump ([8ebaf61](https://github.com/anthropics/anthropic-sdk-typescript/commit/8ebaf616d2e5c6aebc153f19a403dde41ab5a9f1))
|
|
29
|
+
|
|
30
|
+
## 0.2.1 (2026-04-03)
|
|
31
|
+
|
|
32
|
+
Full Changelog: [aws-sdk-v0.2.0...aws-sdk-v0.2.1](https://github.com/anthropics/anthropic-sdk-typescript/compare/aws-sdk-v0.2.0...aws-sdk-v0.2.1)
|
|
33
|
+
|
|
34
|
+
### Chores
|
|
35
|
+
|
|
36
|
+
* **client:** internal updates ([3d64763](https://github.com/anthropics/anthropic-sdk-typescript/commit/3d6476315480508cff8462a5b4523944579dbd32))
|
|
37
|
+
|
|
3
38
|
## 0.2.0 (2026-04-01)
|
|
4
39
|
|
|
5
40
|
Full Changelog: [aws-sdk-v0.1.0...aws-sdk-v0.2.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/aws-sdk-v0.1.0...aws-sdk-v0.2.0)
|
package/client.d.mts
CHANGED
|
@@ -8,7 +8,13 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* AWS region for the API gateway.
|
|
10
10
|
*
|
|
11
|
-
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
11
|
+
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
12
|
+
* `AWS_DEFAULT_REGION` env var > region from the AWS shared config file
|
|
13
|
+
* (`~/.aws/config`) for the given `awsProfile` (or `[default]`).
|
|
14
|
+
*
|
|
15
|
+
* When resolution falls through to the config file, the region is loaded
|
|
16
|
+
* asynchronously. It will be available after `await client.ready` or the
|
|
17
|
+
* first request; until then `awsRegion` and `baseURL` are `undefined`.
|
|
12
18
|
*/
|
|
13
19
|
awsRegion?: string | undefined;
|
|
14
20
|
/**
|
|
@@ -36,10 +42,11 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
36
42
|
*/
|
|
37
43
|
awsSessionToken?: string | null | undefined;
|
|
38
44
|
/**
|
|
39
|
-
* AWS named profile for credential resolution.
|
|
45
|
+
* AWS named profile for credential and region resolution.
|
|
40
46
|
*
|
|
41
|
-
* When set, credentials are loaded from the AWS credential chain
|
|
42
|
-
*
|
|
47
|
+
* When set, credentials are loaded from the AWS credential chain using this
|
|
48
|
+
* profile, and the profile's `region` from `~/.aws/config` is used as a
|
|
49
|
+
* fallback when no region is provided via arg or environment variable.
|
|
43
50
|
*/
|
|
44
51
|
awsProfile?: string | undefined;
|
|
45
52
|
/**
|
|
@@ -72,6 +79,12 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
72
79
|
providerChainResolver: (() => Promise<AwsCredentialIdentityProvider>) | null;
|
|
73
80
|
workspaceId: string | undefined;
|
|
74
81
|
skipAuth: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Resolves once the client is fully configured (region and base URL
|
|
84
|
+
* resolved). Rejects if region resolution fails. Await this to fail fast on
|
|
85
|
+
* misconfiguration instead of waiting for the first request.
|
|
86
|
+
*/
|
|
87
|
+
readonly ready: Promise<void>;
|
|
75
88
|
private _useSigV4;
|
|
76
89
|
/**
|
|
77
90
|
* API Client for interfacing with the Anthropic AWS API.
|
|
@@ -84,8 +97,8 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
84
97
|
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
85
98
|
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
86
99
|
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
87
|
-
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential resolution.
|
|
88
|
-
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env
|
|
100
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
101
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
89
102
|
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
90
103
|
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `anthropic-workspace-id` header. Resolved by precedence: arg > `ANTHROPIC_AWS_WORKSPACE_ID` env var.
|
|
91
104
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_AWS_BASE_URL'] ?? https://aws-external-anthropic.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
@@ -99,6 +112,8 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
99
112
|
* @param {boolean} [opts.skipAuth=false] - Skip authentication for requests. This is useful when you have a gateway or proxy that handles authentication on your behalf.
|
|
100
113
|
*/
|
|
101
114
|
constructor({ awsRegion, baseURL, apiKey, awsAccessKey, awsSecretAccessKey, awsSessionToken, awsProfile, providerChainResolver, workspaceId, skipAuth, ...opts }?: AwsClientOptions);
|
|
115
|
+
private _resolveRegionFromConfig;
|
|
116
|
+
protected prepareOptions(options: FinalRequestOptions): Promise<void>;
|
|
102
117
|
protected authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined>;
|
|
103
118
|
protected validateHeaders(): void;
|
|
104
119
|
protected prepareRequest(request: FinalizedRequestInit, { url, options }: {
|
package/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","sourceRoot":"","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AAE,MAAM,GAAG,SAAS,CAAC;IAC9B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,qBAAqB,EAAE,CAAC,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC,GAAG,IAAI,CAAC;IAC7E,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAS;IAE1B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9B,OAAO,CAAC,SAAS,CAAU;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;gBACS,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,YAAmB,EACnB,kBAAyB,EACzB,eAAsB,EACtB,UAAU,EACV,qBAA4B,EAC5B,WAAW,EACX,QAAgB,EAChB,GAAG,IAAI,EACR,GAAE,gBAAqB;IA6ExB,OAAO,CAAC,wBAAwB;cAeP,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;cAK3D,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;cAclF,eAAe,IAAI,IAAI;cAIjB,cAAc,CACrC,OAAO,EAAE,oBAAoB,EAC7B,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAC9D,OAAO,CAAC,IAAI,CAAC;CAsBjB"}
|
package/client.d.ts
CHANGED
|
@@ -8,7 +8,13 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* AWS region for the API gateway.
|
|
10
10
|
*
|
|
11
|
-
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
11
|
+
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
12
|
+
* `AWS_DEFAULT_REGION` env var > region from the AWS shared config file
|
|
13
|
+
* (`~/.aws/config`) for the given `awsProfile` (or `[default]`).
|
|
14
|
+
*
|
|
15
|
+
* When resolution falls through to the config file, the region is loaded
|
|
16
|
+
* asynchronously. It will be available after `await client.ready` or the
|
|
17
|
+
* first request; until then `awsRegion` and `baseURL` are `undefined`.
|
|
12
18
|
*/
|
|
13
19
|
awsRegion?: string | undefined;
|
|
14
20
|
/**
|
|
@@ -36,10 +42,11 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
36
42
|
*/
|
|
37
43
|
awsSessionToken?: string | null | undefined;
|
|
38
44
|
/**
|
|
39
|
-
* AWS named profile for credential resolution.
|
|
45
|
+
* AWS named profile for credential and region resolution.
|
|
40
46
|
*
|
|
41
|
-
* When set, credentials are loaded from the AWS credential chain
|
|
42
|
-
*
|
|
47
|
+
* When set, credentials are loaded from the AWS credential chain using this
|
|
48
|
+
* profile, and the profile's `region` from `~/.aws/config` is used as a
|
|
49
|
+
* fallback when no region is provided via arg or environment variable.
|
|
43
50
|
*/
|
|
44
51
|
awsProfile?: string | undefined;
|
|
45
52
|
/**
|
|
@@ -72,6 +79,12 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
72
79
|
providerChainResolver: (() => Promise<AwsCredentialIdentityProvider>) | null;
|
|
73
80
|
workspaceId: string | undefined;
|
|
74
81
|
skipAuth: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Resolves once the client is fully configured (region and base URL
|
|
84
|
+
* resolved). Rejects if region resolution fails. Await this to fail fast on
|
|
85
|
+
* misconfiguration instead of waiting for the first request.
|
|
86
|
+
*/
|
|
87
|
+
readonly ready: Promise<void>;
|
|
75
88
|
private _useSigV4;
|
|
76
89
|
/**
|
|
77
90
|
* API Client for interfacing with the Anthropic AWS API.
|
|
@@ -84,8 +97,8 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
84
97
|
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
85
98
|
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
86
99
|
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
87
|
-
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential resolution.
|
|
88
|
-
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env
|
|
100
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
101
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
89
102
|
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
90
103
|
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `anthropic-workspace-id` header. Resolved by precedence: arg > `ANTHROPIC_AWS_WORKSPACE_ID` env var.
|
|
91
104
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_AWS_BASE_URL'] ?? https://aws-external-anthropic.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
@@ -99,6 +112,8 @@ export declare class AnthropicAws extends Anthropic {
|
|
|
99
112
|
* @param {boolean} [opts.skipAuth=false] - Skip authentication for requests. This is useful when you have a gateway or proxy that handles authentication on your behalf.
|
|
100
113
|
*/
|
|
101
114
|
constructor({ awsRegion, baseURL, apiKey, awsAccessKey, awsSecretAccessKey, awsSessionToken, awsProfile, providerChainResolver, workspaceId, skipAuth, ...opts }?: AwsClientOptions);
|
|
115
|
+
private _resolveRegionFromConfig;
|
|
116
|
+
protected prepareOptions(options: FinalRequestOptions): Promise<void>;
|
|
102
117
|
protected authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined>;
|
|
103
118
|
protected validateHeaders(): void;
|
|
104
119
|
protected prepareRequest(request: FinalizedRequestInit, { url, options }: {
|
package/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,eAAe,EAAE;OAIxB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OACjD,EAAE,6BAA6B,EAAE,MAAM,eAAe;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,eAAe,EAAE;OAIxB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OACjD,EAAE,6BAA6B,EAAE,MAAM,eAAe;OAItD,EAAE,mBAAmB,EAAE;OACvB,EAAE,oBAAoB,EAAE;AAI/B,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAEzC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAE/C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAE5C;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEhC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,6BAA6B,CAAC,CAAC,GAAG,IAAI,CAAC;IAE9E;;;;OAIG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;CAsBjB"}
|
package/client.js
CHANGED
|
@@ -40,8 +40,13 @@ const utils_1 = require("./internal/utils.js");
|
|
|
40
40
|
const client_1 = require("@anthropic-ai/sdk/client");
|
|
41
41
|
var client_2 = require("@anthropic-ai/sdk/client");
|
|
42
42
|
Object.defineProperty(exports, "BaseAnthropic", { enumerable: true, get: function () { return client_2.BaseAnthropic; } });
|
|
43
|
+
const node_config_provider_1 = require("@smithy/node-config-provider");
|
|
44
|
+
const config_resolver_1 = require("@smithy/config-resolver");
|
|
43
45
|
const auth_1 = require("./core/auth.js");
|
|
44
46
|
const DEFAULT_SERVICE_NAME = 'aws-external-anthropic';
|
|
47
|
+
const noRegionError = () => new Errors.AnthropicError('No AWS region or base URL found. Set `awsRegion` in the constructor, the `AWS_REGION` / `AWS_DEFAULT_REGION` ' +
|
|
48
|
+
'environment variable, configure a `region` for your profile in `~/.aws/config`, or provide a `baseURL` / ' +
|
|
49
|
+
'`ANTHROPIC_AWS_BASE_URL` environment variable.');
|
|
45
50
|
/** API Client for interfacing with the Anthropic AWS API. */
|
|
46
51
|
class AnthropicAws extends client_1.Anthropic {
|
|
47
52
|
/**
|
|
@@ -55,8 +60,8 @@ class AnthropicAws extends client_1.Anthropic {
|
|
|
55
60
|
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
56
61
|
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
57
62
|
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
58
|
-
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential resolution.
|
|
59
|
-
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env
|
|
63
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
64
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
60
65
|
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
61
66
|
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `anthropic-workspace-id` header. Resolved by precedence: arg > `ANTHROPIC_AWS_WORKSPACE_ID` env var.
|
|
62
67
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_AWS_BASE_URL'] ?? https://aws-external-anthropic.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
@@ -70,13 +75,22 @@ class AnthropicAws extends client_1.Anthropic {
|
|
|
70
75
|
* @param {boolean} [opts.skipAuth=false] - Skip authentication for requests. This is useful when you have a gateway or proxy that handles authentication on your behalf.
|
|
71
76
|
*/
|
|
72
77
|
constructor({ awsRegion, baseURL, apiKey, awsAccessKey = null, awsSecretAccessKey = null, awsSessionToken = null, awsProfile, providerChainResolver = null, workspaceId, skipAuth = false, ...opts } = {}) {
|
|
73
|
-
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env > ~/.aws/config (async).
|
|
79
|
+
// The first three are resolved here; config-file fallback is kicked off below and
|
|
80
|
+
// awaited on `ready` / first request.
|
|
81
|
+
const syncRegion = awsRegion ?? (0, utils_1.readEnv)('AWS_REGION') ?? (0, utils_1.readEnv)('AWS_DEFAULT_REGION');
|
|
82
|
+
const explicitBaseURL = baseURL ?? (0, utils_1.readEnv)('ANTHROPIC_AWS_BASE_URL');
|
|
83
|
+
let resolvedBaseURL;
|
|
84
|
+
if (explicitBaseURL) {
|
|
85
|
+
resolvedBaseURL = explicitBaseURL;
|
|
86
|
+
}
|
|
87
|
+
else if (syncRegion) {
|
|
88
|
+
resolvedBaseURL = `https://aws-external-anthropic.${syncRegion}.api.aws`;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// No region known yet (or skipAuth) — will be resolved async from ~/.aws/config,
|
|
92
|
+
// or is not needed at all.
|
|
93
|
+
resolvedBaseURL = undefined;
|
|
80
94
|
}
|
|
81
95
|
// Precedence-based auth resolution:
|
|
82
96
|
// 1. apiKey constructor arg
|
|
@@ -109,7 +123,7 @@ class AnthropicAws extends client_1.Anthropic {
|
|
|
109
123
|
defaultHeaders: (0, headers_1.buildHeaders)([{ 'anthropic-workspace-id': resolvedWorkspaceId }, opts.defaultHeaders]),
|
|
110
124
|
});
|
|
111
125
|
this.skipAuth = false;
|
|
112
|
-
this.awsRegion =
|
|
126
|
+
this.awsRegion = syncRegion;
|
|
113
127
|
this.awsAccessKey = awsAccessKey;
|
|
114
128
|
this.awsSecretAccessKey = awsSecretAccessKey;
|
|
115
129
|
this.awsSessionToken = awsSessionToken;
|
|
@@ -118,6 +132,32 @@ class AnthropicAws extends client_1.Anthropic {
|
|
|
118
132
|
this.workspaceId = resolvedWorkspaceId;
|
|
119
133
|
this.skipAuth = skipAuth;
|
|
120
134
|
this._useSigV4 = resolvedApiKey == null;
|
|
135
|
+
if (syncRegion || explicitBaseURL || skipAuth) {
|
|
136
|
+
this.ready = Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.ready = this._resolveRegionFromConfig(awsProfile).then((region) => {
|
|
140
|
+
this.awsRegion = region;
|
|
141
|
+
this.baseURL = `https://aws-external-anthropic.${region}.api.aws`;
|
|
142
|
+
});
|
|
143
|
+
// Suppress unhandledRejection; the error surfaces via `await ready` or the first request.
|
|
144
|
+
this.ready.catch(() => { });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_resolveRegionFromConfig(profile) {
|
|
148
|
+
return (0, node_config_provider_1.loadConfig)({
|
|
149
|
+
...config_resolver_1.NODE_REGION_CONFIG_OPTIONS,
|
|
150
|
+
default: () => {
|
|
151
|
+
throw noRegionError();
|
|
152
|
+
},
|
|
153
|
+
}, {
|
|
154
|
+
...config_resolver_1.NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
155
|
+
...(profile && { profile }),
|
|
156
|
+
})();
|
|
157
|
+
}
|
|
158
|
+
async prepareOptions(options) {
|
|
159
|
+
await super.prepareOptions(options);
|
|
160
|
+
await this.ready;
|
|
121
161
|
}
|
|
122
162
|
async authHeaders(opts) {
|
|
123
163
|
if (this.skipAuth) {
|
|
@@ -137,13 +177,13 @@ class AnthropicAws extends client_1.Anthropic {
|
|
|
137
177
|
if (this.skipAuth || !this._useSigV4) {
|
|
138
178
|
return;
|
|
139
179
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
throw
|
|
180
|
+
if (!this.awsRegion) {
|
|
181
|
+
// Only reachable when an explicit baseURL was provided without a region.
|
|
182
|
+
throw noRegionError();
|
|
143
183
|
}
|
|
144
184
|
const headers = await (0, auth_1.getAuthHeaders)(request, {
|
|
145
185
|
url,
|
|
146
|
-
regionName,
|
|
186
|
+
regionName: this.awsRegion,
|
|
147
187
|
serviceName: DEFAULT_SERVICE_NAME,
|
|
148
188
|
awsAccessKey: this.awsAccessKey,
|
|
149
189
|
awsSecretAccessKey: this.awsSecretAccessKey,
|
package/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAkD;AAClD,wDAAuC;AACvC,+CAA2C;AAC3C,qDAAoE;AACpE,mDAAyD;AAAhD,uGAAA,aAAa,OAAA;AAEtB,yCAA6C;AAI7C,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAkD;AAClD,wDAAuC;AACvC,+CAA2C;AAC3C,qDAAo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,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,8CAA8C;YAC9C,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,iFAAiF;QACjF,OAAO,SAAS,CAAC;IACnB,CAAC;IAEkB,eAAe;QAChC,mEAAmE;IACrE,CAAC;IAEkB,KAAK,CAAC,cAAc,CACrC,OAA6B,EAC7B,EAAE,GAAG,EAAE,OAAO,EAAiD;QAE/D,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,yEAAyE;YACzE,MAAM,aAAa,EAAE,CAAC;QACxB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAc,EAAC,OAAO,EAAE;YAC5C,GAAG;YACH,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,WAAW,EAAE,oBAAoB;YACjC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SAClD,CAAC,CAAC;QACH,OAAO,CAAC,OAAO,GAAG,IAAA,sBAAY,EAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACpE,CAAC;CACF;AApMD,oCAoMC"}
|
package/client.mjs
CHANGED
|
@@ -3,8 +3,13 @@ import * as Errors from "./core/error.mjs";
|
|
|
3
3
|
import { readEnv } from "./internal/utils.mjs";
|
|
4
4
|
import { Anthropic } from '@anthropic-ai/sdk/client';
|
|
5
5
|
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
6
|
+
import { loadConfig } from '@smithy/node-config-provider';
|
|
7
|
+
import { NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS } from '@smithy/config-resolver';
|
|
6
8
|
import { getAuthHeaders } from "./core/auth.mjs";
|
|
7
9
|
const DEFAULT_SERVICE_NAME = 'aws-external-anthropic';
|
|
10
|
+
const noRegionError = () => new Errors.AnthropicError('No AWS region or base URL found. Set `awsRegion` in the constructor, the `AWS_REGION` / `AWS_DEFAULT_REGION` ' +
|
|
11
|
+
'environment variable, configure a `region` for your profile in `~/.aws/config`, or provide a `baseURL` / ' +
|
|
12
|
+
'`ANTHROPIC_AWS_BASE_URL` environment variable.');
|
|
8
13
|
/** API Client for interfacing with the Anthropic AWS API. */
|
|
9
14
|
export class AnthropicAws extends Anthropic {
|
|
10
15
|
/**
|
|
@@ -18,8 +23,8 @@ export class AnthropicAws extends Anthropic {
|
|
|
18
23
|
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
19
24
|
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
20
25
|
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
21
|
-
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential resolution.
|
|
22
|
-
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env
|
|
26
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
27
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
23
28
|
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
24
29
|
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `anthropic-workspace-id` header. Resolved by precedence: arg > `ANTHROPIC_AWS_WORKSPACE_ID` env var.
|
|
25
30
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_AWS_BASE_URL'] ?? https://aws-external-anthropic.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
@@ -33,13 +38,22 @@ export class AnthropicAws extends Anthropic {
|
|
|
33
38
|
* @param {boolean} [opts.skipAuth=false] - Skip authentication for requests. This is useful when you have a gateway or proxy that handles authentication on your behalf.
|
|
34
39
|
*/
|
|
35
40
|
constructor({ awsRegion, baseURL, apiKey, awsAccessKey = null, awsSecretAccessKey = null, awsSessionToken = null, awsProfile, providerChainResolver = null, workspaceId, skipAuth = false, ...opts } = {}) {
|
|
36
|
-
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env > ~/.aws/config (async).
|
|
42
|
+
// The first three are resolved here; config-file fallback is kicked off below and
|
|
43
|
+
// awaited on `ready` / first request.
|
|
44
|
+
const syncRegion = awsRegion ?? readEnv('AWS_REGION') ?? readEnv('AWS_DEFAULT_REGION');
|
|
45
|
+
const explicitBaseURL = baseURL ?? readEnv('ANTHROPIC_AWS_BASE_URL');
|
|
46
|
+
let resolvedBaseURL;
|
|
47
|
+
if (explicitBaseURL) {
|
|
48
|
+
resolvedBaseURL = explicitBaseURL;
|
|
49
|
+
}
|
|
50
|
+
else if (syncRegion) {
|
|
51
|
+
resolvedBaseURL = `https://aws-external-anthropic.${syncRegion}.api.aws`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// No region known yet (or skipAuth) — will be resolved async from ~/.aws/config,
|
|
55
|
+
// or is not needed at all.
|
|
56
|
+
resolvedBaseURL = undefined;
|
|
43
57
|
}
|
|
44
58
|
// Precedence-based auth resolution:
|
|
45
59
|
// 1. apiKey constructor arg
|
|
@@ -72,7 +86,7 @@ export class AnthropicAws extends Anthropic {
|
|
|
72
86
|
defaultHeaders: buildHeaders([{ 'anthropic-workspace-id': resolvedWorkspaceId }, opts.defaultHeaders]),
|
|
73
87
|
});
|
|
74
88
|
this.skipAuth = false;
|
|
75
|
-
this.awsRegion =
|
|
89
|
+
this.awsRegion = syncRegion;
|
|
76
90
|
this.awsAccessKey = awsAccessKey;
|
|
77
91
|
this.awsSecretAccessKey = awsSecretAccessKey;
|
|
78
92
|
this.awsSessionToken = awsSessionToken;
|
|
@@ -81,6 +95,32 @@ export class AnthropicAws extends Anthropic {
|
|
|
81
95
|
this.workspaceId = resolvedWorkspaceId;
|
|
82
96
|
this.skipAuth = skipAuth;
|
|
83
97
|
this._useSigV4 = resolvedApiKey == null;
|
|
98
|
+
if (syncRegion || explicitBaseURL || skipAuth) {
|
|
99
|
+
this.ready = Promise.resolve();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.ready = this._resolveRegionFromConfig(awsProfile).then((region) => {
|
|
103
|
+
this.awsRegion = region;
|
|
104
|
+
this.baseURL = `https://aws-external-anthropic.${region}.api.aws`;
|
|
105
|
+
});
|
|
106
|
+
// Suppress unhandledRejection; the error surfaces via `await ready` or the first request.
|
|
107
|
+
this.ready.catch(() => { });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
_resolveRegionFromConfig(profile) {
|
|
111
|
+
return loadConfig({
|
|
112
|
+
...NODE_REGION_CONFIG_OPTIONS,
|
|
113
|
+
default: () => {
|
|
114
|
+
throw noRegionError();
|
|
115
|
+
},
|
|
116
|
+
}, {
|
|
117
|
+
...NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
118
|
+
...(profile && { profile }),
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
async prepareOptions(options) {
|
|
122
|
+
await super.prepareOptions(options);
|
|
123
|
+
await this.ready;
|
|
84
124
|
}
|
|
85
125
|
async authHeaders(opts) {
|
|
86
126
|
if (this.skipAuth) {
|
|
@@ -100,13 +140,13 @@ export class AnthropicAws extends Anthropic {
|
|
|
100
140
|
if (this.skipAuth || !this._useSigV4) {
|
|
101
141
|
return;
|
|
102
142
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
throw
|
|
143
|
+
if (!this.awsRegion) {
|
|
144
|
+
// Only reachable when an explicit baseURL was provided without a region.
|
|
145
|
+
throw noRegionError();
|
|
106
146
|
}
|
|
107
147
|
const headers = await getAuthHeaders(request, {
|
|
108
148
|
url,
|
|
109
|
-
regionName,
|
|
149
|
+
regionName: this.awsRegion,
|
|
110
150
|
serviceName: DEFAULT_SERVICE_NAME,
|
|
111
151
|
awsAccessKey: this.awsAccessKey,
|
|
112
152
|
awsSecretAccessKey: this.awsSecretAccessKey,
|
package/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OACO,EAAE,YAAY,EAAE;OAChB,KAAK,MAAM;OACX,EAAE,OAAO,EAAE;OACX,EAAE,SAAS,EAAiB,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAEjD,EAAE,cAAc,EAAE;AAIzB,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.mjs","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OACO,EAAE,YAAY,EAAE;OAChB,KAAK,MAAM;OACX,EAAE,OAAO,EAAE;OACX,EAAE,SAAS,EAAiB,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAEjD,EAAE,UAAU,EAAE,MAAM,8BAA8B;OAClD,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,MAAM,yBAAyB;OAC9F,EAAE,cAAc,EAAE;AAIzB,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AA4EtD,MAAM,aAAa,GAAG,GAAG,EAAE,CACzB,IAAI,MAAM,CAAC,cAAc,CACvB,+GAA+G;IAC7G,2GAA2G;IAC3G,gDAAgD,CACnD,CAAC;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,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,yEAAyE;YACzE,MAAM,aAAa,EAAE,CAAC;QACxB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE;YAC5C,GAAG;YACH,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,WAAW,EAAE,oBAAoB;YACjC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SAClD,CAAC,CAAC;QACH,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACpE,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anthropic-ai/aws-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "The official TypeScript library for the Anthropic AWS API",
|
|
5
5
|
"author": "Anthropic <support@anthropic.com>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"@anthropic-ai/sdk": ">=0.50.3 <1",
|
|
26
26
|
"@aws-crypto/sha256-js": "^4.0.0",
|
|
27
27
|
"@aws-sdk/credential-providers": "^3.796.0",
|
|
28
|
+
"@smithy/config-resolver": "^4.1.4",
|
|
28
29
|
"@smithy/fetch-http-handler": "^5.0.4",
|
|
30
|
+
"@smithy/node-config-provider": "^4.1.3",
|
|
29
31
|
"@smithy/protocol-http": "^3.0.6",
|
|
30
32
|
"@smithy/signature-v4": "^3.1.1",
|
|
31
33
|
"@smithy/types": "^2.3.4"
|
package/src/client.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { readEnv } from './internal/utils';
|
|
|
5
5
|
import { Anthropic, ClientOptions } from '@anthropic-ai/sdk/client';
|
|
6
6
|
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
7
7
|
import { AwsCredentialIdentityProvider } from '@smithy/types';
|
|
8
|
+
import { loadConfig } from '@smithy/node-config-provider';
|
|
9
|
+
import { NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS } from '@smithy/config-resolver';
|
|
8
10
|
import { getAuthHeaders } from './core/auth';
|
|
9
11
|
import { FinalRequestOptions } from './internal/request-options';
|
|
10
12
|
import { FinalizedRequestInit } from './internal/types';
|
|
@@ -15,7 +17,13 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
15
17
|
/**
|
|
16
18
|
* AWS region for the API gateway.
|
|
17
19
|
*
|
|
18
|
-
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
20
|
+
* Resolved by precedence: `awsRegion` arg > `AWS_REGION` env var >
|
|
21
|
+
* `AWS_DEFAULT_REGION` env var > region from the AWS shared config file
|
|
22
|
+
* (`~/.aws/config`) for the given `awsProfile` (or `[default]`).
|
|
23
|
+
*
|
|
24
|
+
* When resolution falls through to the config file, the region is loaded
|
|
25
|
+
* asynchronously. It will be available after `await client.ready` or the
|
|
26
|
+
* first request; until then `awsRegion` and `baseURL` are `undefined`.
|
|
19
27
|
*/
|
|
20
28
|
awsRegion?: string | undefined;
|
|
21
29
|
|
|
@@ -48,10 +56,11 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
48
56
|
awsSessionToken?: string | null | undefined;
|
|
49
57
|
|
|
50
58
|
/**
|
|
51
|
-
* AWS named profile for credential resolution.
|
|
59
|
+
* AWS named profile for credential and region resolution.
|
|
52
60
|
*
|
|
53
|
-
* When set, credentials are loaded from the AWS credential chain
|
|
54
|
-
*
|
|
61
|
+
* When set, credentials are loaded from the AWS credential chain using this
|
|
62
|
+
* profile, and the profile's `region` from `~/.aws/config` is used as a
|
|
63
|
+
* fallback when no region is provided via arg or environment variable.
|
|
55
64
|
*/
|
|
56
65
|
awsProfile?: string | undefined;
|
|
57
66
|
|
|
@@ -78,6 +87,13 @@ export interface AwsClientOptions extends ClientOptions {
|
|
|
78
87
|
skipAuth?: boolean;
|
|
79
88
|
}
|
|
80
89
|
|
|
90
|
+
const noRegionError = () =>
|
|
91
|
+
new Errors.AnthropicError(
|
|
92
|
+
'No AWS region or base URL found. Set `awsRegion` in the constructor, the `AWS_REGION` / `AWS_DEFAULT_REGION` ' +
|
|
93
|
+
'environment variable, configure a `region` for your profile in `~/.aws/config`, or provide a `baseURL` / ' +
|
|
94
|
+
'`ANTHROPIC_AWS_BASE_URL` environment variable.',
|
|
95
|
+
);
|
|
96
|
+
|
|
81
97
|
/** API Client for interfacing with the Anthropic AWS API. */
|
|
82
98
|
export class AnthropicAws extends Anthropic {
|
|
83
99
|
awsRegion: string | undefined;
|
|
@@ -89,6 +105,13 @@ export class AnthropicAws extends Anthropic {
|
|
|
89
105
|
workspaceId: string | undefined;
|
|
90
106
|
skipAuth: boolean = false;
|
|
91
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Resolves once the client is fully configured (region and base URL
|
|
110
|
+
* resolved). Rejects if region resolution fails. Await this to fail fast on
|
|
111
|
+
* misconfiguration instead of waiting for the first request.
|
|
112
|
+
*/
|
|
113
|
+
readonly ready: Promise<void>;
|
|
114
|
+
|
|
92
115
|
private _useSigV4: boolean;
|
|
93
116
|
|
|
94
117
|
/**
|
|
@@ -102,8 +125,8 @@ export class AnthropicAws extends Anthropic {
|
|
|
102
125
|
* @param {string | null | undefined} [opts.awsAccessKey] - AWS access key ID for SigV4 authentication.
|
|
103
126
|
* @param {string | null | undefined} [opts.awsSecretAccessKey] - AWS secret access key for SigV4 authentication.
|
|
104
127
|
* @param {string | null | undefined} [opts.awsSessionToken] - AWS session token for temporary credentials.
|
|
105
|
-
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential resolution.
|
|
106
|
-
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env
|
|
128
|
+
* @param {string | undefined} [opts.awsProfile] - AWS named profile for credential and region resolution.
|
|
129
|
+
* @param {string | undefined} [opts.awsRegion] - AWS region. Resolved by precedence: arg > `AWS_REGION` env > `AWS_DEFAULT_REGION` env > `~/.aws/config`.
|
|
107
130
|
* @param {(() => Promise<AwsCredentialIdentityProvider>) | null} [opts.providerChainResolver] - Custom provider chain resolver for AWS credentials.
|
|
108
131
|
* @param {string | undefined} [opts.workspaceId] - Workspace ID sent as `anthropic-workspace-id` header. Resolved by precedence: arg > `ANTHROPIC_AWS_WORKSPACE_ID` env var.
|
|
109
132
|
* @param {string} [opts.baseURL=process.env['ANTHROPIC_AWS_BASE_URL'] ?? https://aws-external-anthropic.{awsRegion}.api.aws] - Override the default base URL for the API.
|
|
@@ -129,18 +152,21 @@ export class AnthropicAws extends Anthropic {
|
|
|
129
152
|
skipAuth = false,
|
|
130
153
|
...opts
|
|
131
154
|
}: AwsClientOptions = {}) {
|
|
132
|
-
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
baseURL ??
|
|
137
|
-
readEnv('ANTHROPIC_AWS_BASE_URL') ??
|
|
138
|
-
(resolvedRegion ? `https://aws-external-anthropic.${resolvedRegion}.api.aws` : undefined);
|
|
155
|
+
// Region resolution: arg > AWS_REGION env > AWS_DEFAULT_REGION env > ~/.aws/config (async).
|
|
156
|
+
// The first three are resolved here; config-file fallback is kicked off below and
|
|
157
|
+
// awaited on `ready` / first request.
|
|
158
|
+
const syncRegion = awsRegion ?? readEnv('AWS_REGION') ?? readEnv('AWS_DEFAULT_REGION');
|
|
139
159
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
160
|
+
const explicitBaseURL = baseURL ?? readEnv('ANTHROPIC_AWS_BASE_URL');
|
|
161
|
+
let resolvedBaseURL: string | undefined;
|
|
162
|
+
if (explicitBaseURL) {
|
|
163
|
+
resolvedBaseURL = explicitBaseURL;
|
|
164
|
+
} else if (syncRegion) {
|
|
165
|
+
resolvedBaseURL = `https://aws-external-anthropic.${syncRegion}.api.aws`;
|
|
166
|
+
} else {
|
|
167
|
+
// No region known yet (or skipAuth) — will be resolved async from ~/.aws/config,
|
|
168
|
+
// or is not needed at all.
|
|
169
|
+
resolvedBaseURL = undefined;
|
|
144
170
|
}
|
|
145
171
|
|
|
146
172
|
// Precedence-based auth resolution:
|
|
@@ -180,7 +206,7 @@ export class AnthropicAws extends Anthropic {
|
|
|
180
206
|
defaultHeaders: buildHeaders([{ 'anthropic-workspace-id': resolvedWorkspaceId }, opts.defaultHeaders]),
|
|
181
207
|
});
|
|
182
208
|
|
|
183
|
-
this.awsRegion =
|
|
209
|
+
this.awsRegion = syncRegion;
|
|
184
210
|
this.awsAccessKey = awsAccessKey;
|
|
185
211
|
this.awsSecretAccessKey = awsSecretAccessKey;
|
|
186
212
|
this.awsSessionToken = awsSessionToken;
|
|
@@ -189,6 +215,37 @@ export class AnthropicAws extends Anthropic {
|
|
|
189
215
|
this.workspaceId = resolvedWorkspaceId;
|
|
190
216
|
this.skipAuth = skipAuth;
|
|
191
217
|
this._useSigV4 = resolvedApiKey == null;
|
|
218
|
+
|
|
219
|
+
if (syncRegion || explicitBaseURL || skipAuth) {
|
|
220
|
+
this.ready = Promise.resolve();
|
|
221
|
+
} else {
|
|
222
|
+
this.ready = this._resolveRegionFromConfig(awsProfile).then((region: string) => {
|
|
223
|
+
this.awsRegion = region;
|
|
224
|
+
this.baseURL = `https://aws-external-anthropic.${region}.api.aws`;
|
|
225
|
+
});
|
|
226
|
+
// Suppress unhandledRejection; the error surfaces via `await ready` or the first request.
|
|
227
|
+
this.ready.catch(() => {});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private _resolveRegionFromConfig(profile: string | undefined): Promise<string> {
|
|
232
|
+
return loadConfig(
|
|
233
|
+
{
|
|
234
|
+
...NODE_REGION_CONFIG_OPTIONS,
|
|
235
|
+
default: () => {
|
|
236
|
+
throw noRegionError();
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
...NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
241
|
+
...(profile && { profile }),
|
|
242
|
+
},
|
|
243
|
+
)();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
protected override async prepareOptions(options: FinalRequestOptions): Promise<void> {
|
|
247
|
+
await super.prepareOptions(options);
|
|
248
|
+
await this.ready;
|
|
192
249
|
}
|
|
193
250
|
|
|
194
251
|
protected override async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
@@ -217,16 +274,14 @@ export class AnthropicAws extends Anthropic {
|
|
|
217
274
|
return;
|
|
218
275
|
}
|
|
219
276
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
throw
|
|
223
|
-
'No AWS region found. Set `awsRegion` in the constructor or the `AWS_REGION` / `AWS_DEFAULT_REGION` environment variable.',
|
|
224
|
-
);
|
|
277
|
+
if (!this.awsRegion) {
|
|
278
|
+
// Only reachable when an explicit baseURL was provided without a region.
|
|
279
|
+
throw noRegionError();
|
|
225
280
|
}
|
|
226
281
|
|
|
227
282
|
const headers = await getAuthHeaders(request, {
|
|
228
283
|
url,
|
|
229
|
-
regionName,
|
|
284
|
+
regionName: this.awsRegion,
|
|
230
285
|
serviceName: DEFAULT_SERVICE_NAME,
|
|
231
286
|
awsAccessKey: this.awsAccessKey,
|
|
232
287
|
awsSecretAccessKey: this.awsSecretAccessKey,
|