@ai-sdk/anthropic 3.0.21 → 3.0.22

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - 8ccf04b: Add `authToken` option to support `Authorization: Bearer` authentication as an alternative to `x-api-key` header authentication.
8
+
3
9
  ## 3.0.21
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -715,9 +715,16 @@ interface AnthropicProviderSettings {
715
715
  /**
716
716
  API key that is being send using the `x-api-key` header.
717
717
  It defaults to the `ANTHROPIC_API_KEY` environment variable.
718
+ Only one of `apiKey` or `authToken` is required.
718
719
  */
719
720
  apiKey?: string;
720
721
  /**
722
+ Auth token that is being sent using the `Authorization: Bearer` header.
723
+ It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
724
+ Only one of `apiKey` or `authToken` is required.
725
+ */
726
+ authToken?: string;
727
+ /**
721
728
  Custom headers to include in the requests.
722
729
  */
723
730
  headers?: Record<string, string>;
package/dist/index.d.ts CHANGED
@@ -715,9 +715,16 @@ interface AnthropicProviderSettings {
715
715
  /**
716
716
  API key that is being send using the `x-api-key` header.
717
717
  It defaults to the `ANTHROPIC_API_KEY` environment variable.
718
+ Only one of `apiKey` or `authToken` is required.
718
719
  */
719
720
  apiKey?: string;
720
721
  /**
722
+ Auth token that is being sent using the `Authorization: Bearer` header.
723
+ It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
724
+ Only one of `apiKey` or `authToken` is required.
725
+ */
726
+ authToken?: string;
727
+ /**
721
728
  Custom headers to include in the requests.
722
729
  */
723
730
  headers?: Record<string, string>;
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils22 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.21" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.22" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -4313,18 +4313,29 @@ function createAnthropic(options = {}) {
4313
4313
  })
4314
4314
  )) != null ? _a : "https://api.anthropic.com/v1";
4315
4315
  const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
4316
- const getHeaders = () => (0, import_provider_utils22.withUserAgentSuffix)(
4317
- {
4318
- "anthropic-version": "2023-06-01",
4316
+ if (options.apiKey && options.authToken) {
4317
+ throw new import_provider4.InvalidArgumentError({
4318
+ argument: "apiKey/authToken",
4319
+ message: "Both apiKey and authToken were provided. Please use only one authentication method."
4320
+ });
4321
+ }
4322
+ const getHeaders = () => {
4323
+ const authHeaders = options.authToken ? { Authorization: `Bearer ${options.authToken}` } : {
4319
4324
  "x-api-key": (0, import_provider_utils22.loadApiKey)({
4320
4325
  apiKey: options.apiKey,
4321
4326
  environmentVariableName: "ANTHROPIC_API_KEY",
4322
4327
  description: "Anthropic"
4323
- }),
4324
- ...options.headers
4325
- },
4326
- `ai-sdk/anthropic/${VERSION}`
4327
- );
4328
+ })
4329
+ };
4330
+ return (0, import_provider_utils22.withUserAgentSuffix)(
4331
+ {
4332
+ "anthropic-version": "2023-06-01",
4333
+ ...authHeaders,
4334
+ ...options.headers
4335
+ },
4336
+ `ai-sdk/anthropic/${VERSION}`
4337
+ );
4338
+ };
4328
4339
  const createChatModel = (modelId) => {
4329
4340
  var _a2;
4330
4341
  return new AnthropicMessagesLanguageModel(modelId, {