@ai-sdk/anthropic 2.0.33 → 2.0.35

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.35
4
+
5
+ ### Patch Changes
6
+
7
+ - 1091a20: support ANTHROPIC_BASE_URL
8
+
9
+ ## 2.0.34
10
+
11
+ ### Patch Changes
12
+
13
+ - 65f2628: feat(provider/anthropic): expose container from response in provider metadata
14
+
3
15
  ## 2.0.33
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,8 +1,47 @@
1
+ import { JSONObject, ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
1
2
  import { z } from 'zod/v4';
2
- 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
+ interface AnthropicMessageMetadata {
7
+ usage: JSONObject;
8
+ cacheCreationInputTokens: number | null;
9
+ stopSequence: string | null;
10
+ /**
11
+ * Information about the container used in this request.
12
+ *
13
+ * This will be non-null if a container tool (e.g., code execution) was used.
14
+ * Information about the container used in the request (for the code execution tool).
15
+ */
16
+ container: {
17
+ /**
18
+ * The time at which the container will expire (RFC3339 timestamp).
19
+ */
20
+ expiresAt: string;
21
+ /**
22
+ * Identifier for the container used in this request.
23
+ */
24
+ id: string;
25
+ /**
26
+ * Skills loaded in the container.
27
+ */
28
+ skills: Array<{
29
+ /**
30
+ * Type of skill: either 'anthropic' (built-in) or 'custom' (user-defined).
31
+ */
32
+ type: 'anthropic' | 'custom';
33
+ /**
34
+ * Skill ID (1-64 characters).
35
+ */
36
+ skillId: string;
37
+ /**
38
+ * Skill version or 'latest' for most recent version (1-64 characters).
39
+ */
40
+ version: string;
41
+ }> | null;
42
+ } | null;
43
+ }
44
+
6
45
  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
46
  declare const anthropicProviderOptions: z.ZodObject<{
8
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
@@ -504,4 +543,4 @@ declare const anthropic: AnthropicProvider;
504
543
 
505
544
  declare const VERSION: string;
506
545
 
507
- export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
546
+ export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,47 @@
1
+ import { JSONObject, ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
1
2
  import { z } from 'zod/v4';
2
- 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
+ interface AnthropicMessageMetadata {
7
+ usage: JSONObject;
8
+ cacheCreationInputTokens: number | null;
9
+ stopSequence: string | null;
10
+ /**
11
+ * Information about the container used in this request.
12
+ *
13
+ * This will be non-null if a container tool (e.g., code execution) was used.
14
+ * Information about the container used in the request (for the code execution tool).
15
+ */
16
+ container: {
17
+ /**
18
+ * The time at which the container will expire (RFC3339 timestamp).
19
+ */
20
+ expiresAt: string;
21
+ /**
22
+ * Identifier for the container used in this request.
23
+ */
24
+ id: string;
25
+ /**
26
+ * Skills loaded in the container.
27
+ */
28
+ skills: Array<{
29
+ /**
30
+ * Type of skill: either 'anthropic' (built-in) or 'custom' (user-defined).
31
+ */
32
+ type: 'anthropic' | 'custom';
33
+ /**
34
+ * Skill ID (1-64 characters).
35
+ */
36
+ skillId: string;
37
+ /**
38
+ * Skill version or 'latest' for most recent version (1-64 characters).
39
+ */
40
+ version: string;
41
+ }> | null;
42
+ } | null;
43
+ }
44
+
6
45
  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
46
  declare const anthropicProviderOptions: z.ZodObject<{
8
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
@@ -504,4 +543,4 @@ declare const anthropic: AnthropicProvider;
504
543
 
505
544
  declare const VERSION: string;
506
545
 
507
- export { type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
546
+ export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, VERSION, anthropic, createAnthropic };
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.33" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.35" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -245,7 +245,18 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
245
245
  output_tokens: import_v42.z.number(),
246
246
  cache_creation_input_tokens: import_v42.z.number().nullish(),
247
247
  cache_read_input_tokens: import_v42.z.number().nullish()
248
- })
248
+ }),
249
+ container: import_v42.z.object({
250
+ expires_at: import_v42.z.string(),
251
+ id: import_v42.z.string(),
252
+ skills: import_v42.z.array(
253
+ import_v42.z.object({
254
+ type: import_v42.z.union([import_v42.z.literal("anthropic"), import_v42.z.literal("custom")]),
255
+ skill_id: import_v42.z.string(),
256
+ version: import_v42.z.string()
257
+ })
258
+ ).nullish()
259
+ }).nullish()
249
260
  })
250
261
  )
251
262
  );
@@ -475,7 +486,21 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
475
486
  type: import_v42.z.literal("message_delta"),
476
487
  delta: import_v42.z.object({
477
488
  stop_reason: import_v42.z.string().nullish(),
478
- stop_sequence: import_v42.z.string().nullish()
489
+ stop_sequence: import_v42.z.string().nullish(),
490
+ container: import_v42.z.object({
491
+ expires_at: import_v42.z.string(),
492
+ id: import_v42.z.string(),
493
+ skills: import_v42.z.array(
494
+ import_v42.z.object({
495
+ type: import_v42.z.union([
496
+ import_v42.z.literal("anthropic"),
497
+ import_v42.z.literal("custom")
498
+ ]),
499
+ skill_id: import_v42.z.string(),
500
+ version: import_v42.z.string()
501
+ })
502
+ ).nullish()
503
+ }).nullish()
479
504
  }),
480
505
  usage: import_v42.z.looseObject({
481
506
  output_tokens: import_v42.z.number(),
@@ -1952,7 +1977,7 @@ var AnthropicMessagesLanguageModel = class {
1952
1977
  });
1953
1978
  }
1954
1979
  async doGenerate(options) {
1955
- var _a, _b, _c, _d, _e, _f;
1980
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1956
1981
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1957
1982
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1958
1983
  const {
@@ -2203,7 +2228,16 @@ var AnthropicMessagesLanguageModel = class {
2203
2228
  anthropic: {
2204
2229
  usage: response.usage,
2205
2230
  cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
2206
- stopSequence: (_f = response.stop_sequence) != null ? _f : null
2231
+ stopSequence: (_f = response.stop_sequence) != null ? _f : null,
2232
+ container: response.container ? {
2233
+ expiresAt: response.container.expires_at,
2234
+ id: response.container.id,
2235
+ skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
2236
+ type: skill.type,
2237
+ skillId: skill.skill_id,
2238
+ version: skill.version
2239
+ }))) != null ? _h : null
2240
+ } : null
2207
2241
  }
2208
2242
  }
2209
2243
  };
@@ -2233,6 +2267,7 @@ var AnthropicMessagesLanguageModel = class {
2233
2267
  let rawUsage = void 0;
2234
2268
  let cacheCreationInputTokens = null;
2235
2269
  let stopSequence = null;
2270
+ let container = null;
2236
2271
  let blockType = void 0;
2237
2272
  const generateId3 = this.generateId;
2238
2273
  return {
@@ -2242,7 +2277,7 @@ var AnthropicMessagesLanguageModel = class {
2242
2277
  controller.enqueue({ type: "stream-start", warnings });
2243
2278
  },
2244
2279
  transform(chunk, controller) {
2245
- var _a, _b, _c, _d, _e, _f, _g, _h;
2280
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2246
2281
  if (options.includeRawChunks) {
2247
2282
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2248
2283
  }
@@ -2623,6 +2658,15 @@ var AnthropicMessagesLanguageModel = class {
2623
2658
  isJsonResponseFromTool: usesJsonResponseTool
2624
2659
  });
2625
2660
  stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
2661
+ container = value.delta.container != null ? {
2662
+ expiresAt: value.delta.container.expires_at,
2663
+ id: value.delta.container.id,
2664
+ skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
2665
+ type: skill.type,
2666
+ skillId: skill.skill_id,
2667
+ version: skill.version
2668
+ }))) != null ? _j : null
2669
+ } : null;
2626
2670
  rawUsage = {
2627
2671
  ...rawUsage,
2628
2672
  ...value.usage
@@ -2638,7 +2682,8 @@ var AnthropicMessagesLanguageModel = class {
2638
2682
  anthropic: {
2639
2683
  usage: rawUsage != null ? rawUsage : null,
2640
2684
  cacheCreationInputTokens,
2641
- stopSequence
2685
+ stopSequence,
2686
+ container
2642
2687
  }
2643
2688
  }
2644
2689
  });
@@ -3042,7 +3087,12 @@ var anthropicTools = {
3042
3087
  // src/anthropic-provider.ts
3043
3088
  function createAnthropic(options = {}) {
3044
3089
  var _a;
3045
- const baseURL = (_a = (0, import_provider_utils20.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
3090
+ const baseURL = (_a = (0, import_provider_utils20.withoutTrailingSlash)(
3091
+ (0, import_provider_utils20.loadOptionalSetting)({
3092
+ settingValue: options.baseURL,
3093
+ environmentVariableName: "ANTHROPIC_BASE_URL"
3094
+ })
3095
+ )) != null ? _a : "https://api.anthropic.com/v1";
3046
3096
  const getHeaders = () => (0, import_provider_utils20.withUserAgentSuffix)(
3047
3097
  {
3048
3098
  "anthropic-version": "2023-06-01",