@ai-sdk/anthropic 3.0.21 → 3.0.23

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/index.d.mts +7 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.js +20 -9
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +21 -9
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +9 -5
  9. package/src/anthropic-provider.ts +32 -7
  10. package/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt +0 -248
  11. package/src/__fixtures__/anthropic-code-execution-20250825.1.json +0 -70
  12. package/src/__fixtures__/anthropic-code-execution-20250825.2.chunks.txt +0 -984
  13. package/src/__fixtures__/anthropic-code-execution-20250825.2.json +0 -111
  14. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.chunks.txt +0 -691
  15. package/src/__fixtures__/anthropic-code-execution-20250825.pptx-skill.json +0 -1801
  16. package/src/__fixtures__/anthropic-json-other-tool.1.chunks.txt +0 -13
  17. package/src/__fixtures__/anthropic-json-other-tool.1.json +0 -26
  18. package/src/__fixtures__/anthropic-json-output-format.1.chunks.txt +0 -120
  19. package/src/__fixtures__/anthropic-json-output-format.1.json +0 -25
  20. package/src/__fixtures__/anthropic-json-tool.1.chunks.txt +0 -9
  21. package/src/__fixtures__/anthropic-json-tool.1.json +0 -37
  22. package/src/__fixtures__/anthropic-json-tool.2.chunks.txt +0 -14
  23. package/src/__fixtures__/anthropic-mcp.1.chunks.txt +0 -17
  24. package/src/__fixtures__/anthropic-mcp.1.json +0 -39
  25. package/src/__fixtures__/anthropic-memory-20250818.1.json +0 -28
  26. package/src/__fixtures__/anthropic-message-delta-input-tokens.chunks.txt +0 -8
  27. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.chunks.txt +0 -278
  28. package/src/__fixtures__/anthropic-programmatic-tool-calling.1.json +0 -106
  29. package/src/__fixtures__/anthropic-tool-no-args.chunks.txt +0 -13
  30. package/src/__fixtures__/anthropic-tool-no-args.json +0 -31
  31. package/src/__fixtures__/anthropic-tool-search-bm25.1.chunks.txt +0 -47
  32. package/src/__fixtures__/anthropic-tool-search-bm25.1.json +0 -67
  33. package/src/__fixtures__/anthropic-tool-search-deferred-bm25.2.json +0 -65
  34. package/src/__fixtures__/anthropic-tool-search-deferred-bm25.chunks.txt +0 -115
  35. package/src/__fixtures__/anthropic-tool-search-deferred-regex.2.json +0 -69
  36. package/src/__fixtures__/anthropic-tool-search-deferred-regex.chunks.txt +0 -119
  37. package/src/__fixtures__/anthropic-tool-search-regex.1.chunks.txt +0 -51
  38. package/src/__fixtures__/anthropic-tool-search-regex.1.json +0 -65
  39. package/src/__fixtures__/anthropic-web-fetch-tool.1.chunks.txt +0 -64
  40. package/src/__fixtures__/anthropic-web-fetch-tool.1.json +0 -54
  41. package/src/__fixtures__/anthropic-web-fetch-tool.2.json +0 -56
  42. package/src/__fixtures__/anthropic-web-fetch-tool.error.json +0 -46
  43. package/src/__fixtures__/anthropic-web-search-tool.1.chunks.txt +0 -120
  44. package/src/__fixtures__/anthropic-web-search-tool.1.json +0 -181
  45. package/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +0 -16719
  46. package/src/anthropic-error.test.ts +0 -42
  47. package/src/anthropic-messages-language-model.test.ts +0 -7368
  48. package/src/anthropic-prepare-tools.test.ts +0 -1219
  49. package/src/anthropic-provider.test.ts +0 -162
  50. package/src/convert-to-anthropic-messages-prompt.test.ts +0 -2902
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/anthropic-provider.ts
2
2
  import {
3
+ InvalidArgumentError,
3
4
  NoSuchModelError
4
5
  } from "@ai-sdk/provider";
5
6
  import {
@@ -11,7 +12,7 @@ import {
11
12
  } from "@ai-sdk/provider-utils";
12
13
 
13
14
  // src/version.ts
14
- var VERSION = true ? "3.0.21" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.23" : "0.0.0-test";
15
16
 
16
17
  // src/anthropic-messages-language-model.ts
17
18
  import {
@@ -4372,18 +4373,29 @@ function createAnthropic(options = {}) {
4372
4373
  })
4373
4374
  )) != null ? _a : "https://api.anthropic.com/v1";
4374
4375
  const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
4375
- const getHeaders = () => withUserAgentSuffix(
4376
- {
4377
- "anthropic-version": "2023-06-01",
4376
+ if (options.apiKey && options.authToken) {
4377
+ throw new InvalidArgumentError({
4378
+ argument: "apiKey/authToken",
4379
+ message: "Both apiKey and authToken were provided. Please use only one authentication method."
4380
+ });
4381
+ }
4382
+ const getHeaders = () => {
4383
+ const authHeaders = options.authToken ? { Authorization: `Bearer ${options.authToken}` } : {
4378
4384
  "x-api-key": loadApiKey({
4379
4385
  apiKey: options.apiKey,
4380
4386
  environmentVariableName: "ANTHROPIC_API_KEY",
4381
4387
  description: "Anthropic"
4382
- }),
4383
- ...options.headers
4384
- },
4385
- `ai-sdk/anthropic/${VERSION}`
4386
- );
4388
+ })
4389
+ };
4390
+ return withUserAgentSuffix(
4391
+ {
4392
+ "anthropic-version": "2023-06-01",
4393
+ ...authHeaders,
4394
+ ...options.headers
4395
+ },
4396
+ `ai-sdk/anthropic/${VERSION}`
4397
+ );
4398
+ };
4387
4399
  const createChatModel = (modelId) => {
4388
4400
  var _a2;
4389
4401
  return new AnthropicMessagesLanguageModel(modelId, {