@ai-sdk/anthropic 2.0.29 → 2.0.31

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,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.31
4
+
5
+ ### Patch Changes
6
+
7
+ - b73ba90: feat(provider/anthropic): default and limit maxTokens based on model
8
+
9
+ ## 2.0.30
10
+
11
+ ### Patch Changes
12
+
13
+ - 650287f: chore: add model ID for Haiku 4.5
14
+
3
15
  ## 2.0.29
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
- type AnthropicMessagesModelId = 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
6
+ type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
7
7
  declare const anthropicProviderOptions: z.ZodObject<{
8
8
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
9
9
  thinking: z.ZodOptional<z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
- type AnthropicMessagesModelId = 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
6
+ type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {});
7
7
  declare const anthropicProviderOptions: z.ZodObject<{
8
8
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
9
9
  thinking: z.ZodOptional<z.ZodObject<{
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.29" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.31" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1636,8 +1636,7 @@ var AnthropicMessagesLanguageModel = class {
1636
1636
  }
1637
1637
  async getArgs({
1638
1638
  prompt,
1639
- maxOutputTokens = 4096,
1640
- // 4096: max model output tokens TODO update default in v5
1639
+ maxOutputTokens,
1641
1640
  temperature,
1642
1641
  topP,
1643
1642
  topK,
@@ -1703,11 +1702,13 @@ var AnthropicMessagesLanguageModel = class {
1703
1702
  });
1704
1703
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
1705
1704
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
1705
+ const maxOutputTokensForModel = getMaxOutputTokensForModel(this.modelId);
1706
+ const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1706
1707
  const baseArgs = {
1707
1708
  // model id:
1708
1709
  model: this.modelId,
1709
1710
  // standardized settings:
1710
- max_tokens: maxOutputTokens,
1711
+ max_tokens: maxTokens,
1711
1712
  temperature,
1712
1713
  top_k: topK,
1713
1714
  top_p: topP,
@@ -1750,7 +1751,17 @@ var AnthropicMessagesLanguageModel = class {
1750
1751
  details: "topP is not supported when thinking is enabled"
1751
1752
  });
1752
1753
  }
1753
- baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
1754
+ baseArgs.max_tokens = maxTokens + thinkingBudget;
1755
+ }
1756
+ if (baseArgs.max_tokens > maxOutputTokensForModel) {
1757
+ if (maxOutputTokens != null) {
1758
+ warnings.push({
1759
+ type: "unsupported-setting",
1760
+ setting: "maxOutputTokens",
1761
+ details: `${maxTokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
1762
+ });
1763
+ }
1764
+ baseArgs.max_tokens = maxOutputTokensForModel;
1754
1765
  }
1755
1766
  const {
1756
1767
  tools: anthropicTools2,
@@ -2530,6 +2541,17 @@ var AnthropicMessagesLanguageModel = class {
2530
2541
  };
2531
2542
  }
2532
2543
  };
2544
+ function getMaxOutputTokensForModel(modelId) {
2545
+ if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
2546
+ return 64e3;
2547
+ } else if (modelId.includes("claude-opus-4-")) {
2548
+ return 32e3;
2549
+ } else if (modelId.includes("claude-3-5-haiku")) {
2550
+ return 8192;
2551
+ } else {
2552
+ return 4096;
2553
+ }
2554
+ }
2533
2555
 
2534
2556
  // src/tool/bash_20241022.ts
2535
2557
  var import_provider_utils12 = require("@ai-sdk/provider-utils");