@anthropic-ai/sdk 0.68.0 → 0.69.0

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 (110) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/helpers/beta/json-schema.d.mts +12 -0
  3. package/helpers/beta/json-schema.d.mts.map +1 -1
  4. package/helpers/beta/json-schema.d.ts +12 -0
  5. package/helpers/beta/json-schema.d.ts.map +1 -1
  6. package/helpers/beta/json-schema.js +34 -0
  7. package/helpers/beta/json-schema.js.map +1 -1
  8. package/helpers/beta/json-schema.mjs +33 -0
  9. package/helpers/beta/json-schema.mjs.map +1 -1
  10. package/helpers/beta/zod.d.mts +13 -2
  11. package/helpers/beta/zod.d.mts.map +1 -1
  12. package/helpers/beta/zod.d.ts +13 -2
  13. package/helpers/beta/zod.d.ts.map +1 -1
  14. package/helpers/beta/zod.js +30 -1
  15. package/helpers/beta/zod.js.map +1 -1
  16. package/helpers/beta/zod.mjs +29 -1
  17. package/helpers/beta/zod.mjs.map +1 -1
  18. package/internal/utils/values.d.mts +1 -0
  19. package/internal/utils/values.d.mts.map +1 -1
  20. package/internal/utils/values.d.ts +1 -0
  21. package/internal/utils/values.d.ts.map +1 -1
  22. package/internal/utils/values.js +8 -1
  23. package/internal/utils/values.js.map +1 -1
  24. package/internal/utils/values.mjs +6 -0
  25. package/internal/utils/values.mjs.map +1 -1
  26. package/lib/BetaMessageStream.d.mts +11 -9
  27. package/lib/BetaMessageStream.d.mts.map +1 -1
  28. package/lib/BetaMessageStream.d.ts +11 -9
  29. package/lib/BetaMessageStream.d.ts.map +1 -1
  30. package/lib/BetaMessageStream.js +14 -9
  31. package/lib/BetaMessageStream.js.map +1 -1
  32. package/lib/BetaMessageStream.mjs +14 -9
  33. package/lib/BetaMessageStream.mjs.map +1 -1
  34. package/lib/beta-parser.d.mts +22 -0
  35. package/lib/beta-parser.d.mts.map +1 -0
  36. package/lib/beta-parser.d.ts +22 -0
  37. package/lib/beta-parser.d.ts.map +1 -0
  38. package/lib/beta-parser.js +59 -0
  39. package/lib/beta-parser.js.map +1 -0
  40. package/lib/beta-parser.mjs +55 -0
  41. package/lib/beta-parser.mjs.map +1 -0
  42. package/lib/transform-json-schema.d.mts +3 -0
  43. package/lib/transform-json-schema.d.mts.map +1 -0
  44. package/lib/transform-json-schema.d.ts +3 -0
  45. package/lib/transform-json-schema.d.ts.map +1 -0
  46. package/lib/transform-json-schema.js +114 -0
  47. package/lib/transform-json-schema.js.map +1 -0
  48. package/lib/transform-json-schema.mjs +111 -0
  49. package/lib/transform-json-schema.mjs.map +1 -0
  50. package/package.json +1 -1
  51. package/resources/beta/beta.d.mts +2 -2
  52. package/resources/beta/beta.d.mts.map +1 -1
  53. package/resources/beta/beta.d.ts +2 -2
  54. package/resources/beta/beta.d.ts.map +1 -1
  55. package/resources/beta/beta.js.map +1 -1
  56. package/resources/beta/beta.mjs.map +1 -1
  57. package/resources/beta/index.d.mts +1 -1
  58. package/resources/beta/index.d.mts.map +1 -1
  59. package/resources/beta/index.d.ts +1 -1
  60. package/resources/beta/index.d.ts.map +1 -1
  61. package/resources/beta/index.js.map +1 -1
  62. package/resources/beta/index.mjs.map +1 -1
  63. package/resources/beta/messages/batches.d.mts +6 -6
  64. package/resources/beta/messages/batches.d.ts +6 -6
  65. package/resources/beta/messages/batches.js +6 -6
  66. package/resources/beta/messages/batches.mjs +6 -6
  67. package/resources/beta/messages/index.d.mts +1 -1
  68. package/resources/beta/messages/index.d.mts.map +1 -1
  69. package/resources/beta/messages/index.d.ts +1 -1
  70. package/resources/beta/messages/index.d.ts.map +1 -1
  71. package/resources/beta/messages/index.js.map +1 -1
  72. package/resources/beta/messages/index.mjs.map +1 -1
  73. package/resources/beta/messages/messages.d.mts +60 -10
  74. package/resources/beta/messages/messages.d.mts.map +1 -1
  75. package/resources/beta/messages/messages.d.ts +60 -10
  76. package/resources/beta/messages/messages.d.ts.map +1 -1
  77. package/resources/beta/messages/messages.js +31 -4
  78. package/resources/beta/messages/messages.js.map +1 -1
  79. package/resources/beta/messages/messages.mjs +31 -4
  80. package/resources/beta/messages/messages.mjs.map +1 -1
  81. package/resources/messages/batches.d.mts +6 -6
  82. package/resources/messages/batches.d.ts +6 -6
  83. package/resources/messages/batches.js +6 -6
  84. package/resources/messages/batches.mjs +6 -6
  85. package/resources/messages/messages.d.mts +3 -2
  86. package/resources/messages/messages.d.mts.map +1 -1
  87. package/resources/messages/messages.d.ts +3 -2
  88. package/resources/messages/messages.d.ts.map +1 -1
  89. package/resources/messages/messages.js +1 -1
  90. package/resources/messages/messages.js.map +1 -1
  91. package/resources/messages/messages.mjs +1 -1
  92. package/resources/messages/messages.mjs.map +1 -1
  93. package/src/helpers/beta/json-schema.ts +43 -0
  94. package/src/helpers/beta/zod.ts +40 -3
  95. package/src/internal/utils/values.ts +7 -0
  96. package/src/lib/BetaMessageStream.ts +32 -25
  97. package/src/lib/beta-parser.ts +105 -0
  98. package/src/lib/transform-json-schema.ts +124 -0
  99. package/src/resources/beta/beta.ts +2 -0
  100. package/src/resources/beta/index.ts +1 -0
  101. package/src/resources/beta/messages/batches.ts +6 -6
  102. package/src/resources/beta/messages/index.ts +1 -0
  103. package/src/resources/beta/messages/messages.ts +108 -18
  104. package/src/resources/messages/batches.ts +6 -6
  105. package/src/resources/messages/messages.ts +3 -2
  106. package/src/version.ts +1 -1
  107. package/version.d.mts +1 -1
  108. package/version.d.ts +1 -1
  109. package/version.js +1 -1
  110. package/version.mjs +1 -1
@@ -1,9 +1,26 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
+ import { Anthropic } from '../../../client';
4
+ import { APIPromise } from '../../../core/api-promise';
3
5
  import { APIResource } from '../../../core/resource';
4
- import * as MessagesMessagesAPI from './messages';
5
- import * as BetaAPI from '../beta';
6
+ import { Stream } from '../../../core/streaming';
7
+ import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
8
+ import { buildHeaders } from '../../../internal/headers';
9
+ import { RequestOptions } from '../../../internal/request-options';
10
+ import {
11
+ parseBetaMessage,
12
+ type ExtractParsedContentFromBetaParams,
13
+ type ParsedBetaMessage,
14
+ } from '../../../lib/beta-parser';
15
+ import { BetaMessageStream } from '../../../lib/BetaMessageStream';
16
+ import {
17
+ BetaToolRunner,
18
+ BetaToolRunnerParams,
19
+ BetaToolRunnerRequestOptions,
20
+ } from '../../../lib/tools/BetaToolRunner';
21
+ import type { Model } from '../../messages/messages';
6
22
  import * as MessagesAPI from '../../messages/messages';
23
+ import * as BetaAPI from '../beta';
7
24
  import * as BatchesAPI from './batches';
8
25
  import {
9
26
  BatchCancelParams,
@@ -24,19 +41,7 @@ import {
24
41
  BetaMessageBatchSucceededResult,
25
42
  BetaMessageBatchesPage,
26
43
  } from './batches';
27
- import { APIPromise } from '../../../core/api-promise';
28
- import { Stream } from '../../../core/streaming';
29
- import { buildHeaders } from '../../../internal/headers';
30
- import { RequestOptions } from '../../../internal/request-options';
31
- import type { Model } from '../../messages/messages';
32
- import { BetaMessageStream } from '../../../lib/BetaMessageStream';
33
- import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
34
- import {
35
- BetaToolRunner,
36
- BetaToolRunnerParams,
37
- BetaToolRunnerRequestOptions,
38
- } from '../../../lib/tools/BetaToolRunner';
39
- import { Anthropic } from '../../../client';
44
+ import * as MessagesMessagesAPI from './messages';
40
45
 
41
46
  const DEPRECATED_MODELS: {
42
47
  [K in Model]?: string;
@@ -64,7 +69,8 @@ export class Messages extends APIResource {
64
69
  * The Messages API can be used for either single queries or stateless multi-turn
65
70
  * conversations.
66
71
  *
67
- * Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
72
+ * Learn more about the Messages API in our
73
+ * [user guide](https://docs.claude.com/en/docs/initial-setup)
68
74
  *
69
75
  * @example
70
76
  * ```ts
@@ -115,10 +121,46 @@ export class Messages extends APIResource {
115
121
  }) as APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>>;
116
122
  }
117
123
 
124
+ /**
125
+ * Send a structured list of input messages with text and/or image content, along with an expected `output_format` and
126
+ * the response will be automatically parsed and available in the `parsed` property of the message.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const message = await client.beta.messages.parse({
131
+ * model: 'claude-3-5-sonnet-20241022',
132
+ * max_tokens: 1024,
133
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
134
+ * output_format: zodOutputFormat(z.object({ answer: z.number() }), 'math'),
135
+ * });
136
+ *
137
+ * console.log(message.parsed?.answer); // 4
138
+ * ```
139
+ */
140
+ parse<Params extends MessageCreateParamsNonStreaming>(
141
+ params: Params,
142
+ options?: RequestOptions,
143
+ ): APIPromise<ParsedBetaMessage<ExtractParsedContentFromBetaParams<Params>>> {
144
+ options = {
145
+ ...options,
146
+ headers: buildHeaders([
147
+ { 'anthropic-beta': [...(params.betas ?? []), 'structured-outputs-2025-09-17'].toString() },
148
+ options?.headers,
149
+ ]),
150
+ };
151
+
152
+ return this.create(params, options).then((message) => parseBetaMessage(message, params)) as APIPromise<
153
+ ParsedBetaMessage<ExtractParsedContentFromBetaParams<Params>>
154
+ >;
155
+ }
156
+
118
157
  /**
119
158
  * Create a Message stream
120
159
  */
121
- stream(body: BetaMessageStreamParams, options?: RequestOptions): BetaMessageStream {
160
+ stream<Params extends BetaMessageStreamParams>(
161
+ body: Params,
162
+ options?: RequestOptions,
163
+ ): BetaMessageStream<ExtractParsedContentFromBetaParams<Params>> {
122
164
  return BetaMessageStream.createMessage(this, body, options);
123
165
  }
124
166
 
@@ -129,7 +171,7 @@ export class Messages extends APIResource {
129
171
  * including tools, images, and documents, without creating it.
130
172
  *
131
173
  * Learn more about token counting in our
132
- * [user guide](/en/docs/build-with-claude/token-counting)
174
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
133
175
  *
134
176
  * @example
135
177
  * ```ts
@@ -587,6 +629,8 @@ export interface BetaCodeExecutionTool20250522 {
587
629
  * Create a cache control breakpoint at this content block.
588
630
  */
589
631
  cache_control?: BetaCacheControlEphemeral | null;
632
+
633
+ strict?: boolean;
590
634
  }
591
635
 
592
636
  export interface BetaCodeExecutionTool20250825 {
@@ -603,6 +647,8 @@ export interface BetaCodeExecutionTool20250825 {
603
647
  * Create a cache control breakpoint at this content block.
604
648
  */
605
649
  cache_control?: BetaCacheControlEphemeral | null;
650
+
651
+ strict?: boolean;
606
652
  }
607
653
 
608
654
  export interface BetaCodeExecutionToolResultBlock {
@@ -838,6 +884,15 @@ export interface BetaInputTokensTrigger {
838
884
  value: number;
839
885
  }
840
886
 
887
+ export interface BetaJSONOutputFormat {
888
+ /**
889
+ * The JSON schema of the format
890
+ */
891
+ schema: { [key: string]: unknown };
892
+
893
+ type: 'json_schema';
894
+ }
895
+
841
896
  export interface BetaMCPToolResultBlock {
842
897
  content: string | Array<BetaTextBlock>;
843
898
 
@@ -900,6 +955,8 @@ export interface BetaMemoryTool20250818 {
900
955
  * Create a cache control breakpoint at this content block.
901
956
  */
902
957
  cache_control?: BetaCacheControlEphemeral | null;
958
+
959
+ strict?: boolean;
903
960
  }
904
961
 
905
962
  export type BetaMemoryTool20250818Command =
@@ -1754,6 +1811,8 @@ export interface BetaTool {
1754
1811
  */
1755
1812
  description?: string;
1756
1813
 
1814
+ strict?: boolean;
1815
+
1757
1816
  type?: 'custom' | null;
1758
1817
  }
1759
1818
 
@@ -1789,6 +1848,8 @@ export interface BetaToolBash20241022 {
1789
1848
  * Create a cache control breakpoint at this content block.
1790
1849
  */
1791
1850
  cache_control?: BetaCacheControlEphemeral | null;
1851
+
1852
+ strict?: boolean;
1792
1853
  }
1793
1854
 
1794
1855
  export interface BetaToolBash20250124 {
@@ -1805,6 +1866,8 @@ export interface BetaToolBash20250124 {
1805
1866
  * Create a cache control breakpoint at this content block.
1806
1867
  */
1807
1868
  cache_control?: BetaCacheControlEphemeral | null;
1869
+
1870
+ strict?: boolean;
1808
1871
  }
1809
1872
 
1810
1873
  /**
@@ -1899,6 +1962,8 @@ export interface BetaToolComputerUse20241022 {
1899
1962
  * The X11 display number (e.g. 0, 1) for the display.
1900
1963
  */
1901
1964
  display_number?: number | null;
1965
+
1966
+ strict?: boolean;
1902
1967
  }
1903
1968
 
1904
1969
  export interface BetaToolComputerUse20250124 {
@@ -1930,6 +1995,8 @@ export interface BetaToolComputerUse20250124 {
1930
1995
  * The X11 display number (e.g. 0, 1) for the display.
1931
1996
  */
1932
1997
  display_number?: number | null;
1998
+
1999
+ strict?: boolean;
1933
2000
  }
1934
2001
 
1935
2002
  export interface BetaToolResultBlockParam {
@@ -1965,6 +2032,8 @@ export interface BetaToolTextEditor20241022 {
1965
2032
  * Create a cache control breakpoint at this content block.
1966
2033
  */
1967
2034
  cache_control?: BetaCacheControlEphemeral | null;
2035
+
2036
+ strict?: boolean;
1968
2037
  }
1969
2038
 
1970
2039
  export interface BetaToolTextEditor20250124 {
@@ -1981,6 +2050,8 @@ export interface BetaToolTextEditor20250124 {
1981
2050
  * Create a cache control breakpoint at this content block.
1982
2051
  */
1983
2052
  cache_control?: BetaCacheControlEphemeral | null;
2053
+
2054
+ strict?: boolean;
1984
2055
  }
1985
2056
 
1986
2057
  export interface BetaToolTextEditor20250429 {
@@ -1997,6 +2068,8 @@ export interface BetaToolTextEditor20250429 {
1997
2068
  * Create a cache control breakpoint at this content block.
1998
2069
  */
1999
2070
  cache_control?: BetaCacheControlEphemeral | null;
2071
+
2072
+ strict?: boolean;
2000
2073
  }
2001
2074
 
2002
2075
  export interface BetaToolTextEditor20250728 {
@@ -2019,6 +2092,8 @@ export interface BetaToolTextEditor20250728 {
2019
2092
  * defaults to displaying the full file.
2020
2093
  */
2021
2094
  max_characters?: number | null;
2095
+
2096
+ strict?: boolean;
2022
2097
  }
2023
2098
 
2024
2099
  export type BetaToolUnion =
@@ -2196,6 +2271,8 @@ export interface BetaWebFetchTool20250910 {
2196
2271
  * Maximum number of times the tool can be used in the API request.
2197
2272
  */
2198
2273
  max_uses?: number | null;
2274
+
2275
+ strict?: boolean;
2199
2276
  }
2200
2277
 
2201
2278
  export interface BetaWebFetchToolResultBlock {
@@ -2297,6 +2374,8 @@ export interface BetaWebSearchTool20250305 {
2297
2374
  */
2298
2375
  max_uses?: number | null;
2299
2376
 
2377
+ strict?: boolean;
2378
+
2300
2379
  /**
2301
2380
  * Parameters for the user's location. Used to provide more relevant search
2302
2381
  * results.
@@ -2502,6 +2581,11 @@ export interface MessageCreateParamsBase {
2502
2581
  */
2503
2582
  metadata?: BetaMetadata;
2504
2583
 
2584
+ /**
2585
+ * Body param: A schema to specify Claude's output format in responses.
2586
+ */
2587
+ output_format?: BetaJSONOutputFormat | null;
2588
+
2505
2589
  /**
2506
2590
  * Body param: Determines whether to use priority capacity (if available) or
2507
2591
  * standard capacity for this request.
@@ -2796,6 +2880,11 @@ export interface MessageCountTokensParams {
2796
2880
  */
2797
2881
  mcp_servers?: Array<BetaRequestMCPServerURLDefinition>;
2798
2882
 
2883
+ /**
2884
+ * Body param: A schema to specify Claude's output format in responses.
2885
+ */
2886
+ output_format?: BetaJSONOutputFormat | null;
2887
+
2799
2888
  /**
2800
2889
  * Body param: System prompt.
2801
2890
  *
@@ -2993,6 +3082,7 @@ export declare namespace Messages {
2993
3082
  type BetaInputJSONDelta as BetaInputJSONDelta,
2994
3083
  type BetaInputTokensClearAtLeast as BetaInputTokensClearAtLeast,
2995
3084
  type BetaInputTokensTrigger as BetaInputTokensTrigger,
3085
+ type BetaJSONOutputFormat as BetaJSONOutputFormat,
2996
3086
  type BetaMCPToolResultBlock as BetaMCPToolResultBlock,
2997
3087
  type BetaMCPToolUseBlock as BetaMCPToolUseBlock,
2998
3088
  type BetaMCPToolUseBlockParam as BetaMCPToolUseBlockParam,
@@ -20,7 +20,7 @@ export class Batches extends APIResource {
20
20
  * can take up to 24 hours to complete.
21
21
  *
22
22
  * Learn more about the Message Batches API in our
23
- * [user guide](/en/docs/build-with-claude/batch-processing)
23
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
24
24
  *
25
25
  * @example
26
26
  * ```ts
@@ -50,7 +50,7 @@ export class Batches extends APIResource {
50
50
  * `results_url` field in the response.
51
51
  *
52
52
  * Learn more about the Message Batches API in our
53
- * [user guide](/en/docs/build-with-claude/batch-processing)
53
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
54
54
  *
55
55
  * @example
56
56
  * ```ts
@@ -68,7 +68,7 @@ export class Batches extends APIResource {
68
68
  * returned first.
69
69
  *
70
70
  * Learn more about the Message Batches API in our
71
- * [user guide](/en/docs/build-with-claude/batch-processing)
71
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
72
72
  *
73
73
  * @example
74
74
  * ```ts
@@ -92,7 +92,7 @@ export class Batches extends APIResource {
92
92
  * like to delete an in-progress batch, you must first cancel it.
93
93
  *
94
94
  * Learn more about the Message Batches API in our
95
- * [user guide](/en/docs/build-with-claude/batch-processing)
95
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
96
96
  *
97
97
  * @example
98
98
  * ```ts
@@ -116,7 +116,7 @@ export class Batches extends APIResource {
116
116
  * non-interruptible.
117
117
  *
118
118
  * Learn more about the Message Batches API in our
119
- * [user guide](/en/docs/build-with-claude/batch-processing)
119
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
120
120
  *
121
121
  * @example
122
122
  * ```ts
@@ -137,7 +137,7 @@ export class Batches extends APIResource {
137
137
  * requests. Use the `custom_id` field to match results to requests.
138
138
  *
139
139
  * Learn more about the Message Batches API in our
140
- * [user guide](/en/docs/build-with-claude/batch-processing)
140
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
141
141
  *
142
142
  * @example
143
143
  * ```ts
@@ -35,7 +35,8 @@ export class Messages extends APIResource {
35
35
  * The Messages API can be used for either single queries or stateless multi-turn
36
36
  * conversations.
37
37
  *
38
- * Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
38
+ * Learn more about the Messages API in our
39
+ * [user guide](https://docs.claude.com/en/docs/initial-setup)
39
40
  *
40
41
  * @example
41
42
  * ```ts
@@ -93,7 +94,7 @@ export class Messages extends APIResource {
93
94
  * including tools, images, and documents, without creating it.
94
95
  *
95
96
  * Learn more about token counting in our
96
- * [user guide](/en/docs/build-with-claude/token-counting)
97
+ * [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
97
98
  *
98
99
  * @example
99
100
  * ```ts
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.68.0'; // x-release-please-version
1
+ export const VERSION = '0.69.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.68.0";
1
+ export declare const VERSION = "0.69.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.68.0";
1
+ export declare const VERSION = "0.69.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.68.0'; // x-release-please-version
4
+ exports.VERSION = '0.69.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.68.0'; // x-release-please-version
1
+ export const VERSION = '0.69.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map