@anthropic-ai/sdk 0.33.1 → 0.35.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 (69) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +8 -2
  3. package/core.d.ts.map +1 -1
  4. package/core.js +10 -1
  5. package/core.js.map +1 -1
  6. package/core.mjs +10 -1
  7. package/core.mjs.map +1 -1
  8. package/index.d.mts +6 -6
  9. package/index.d.ts +6 -6
  10. package/index.d.ts.map +1 -1
  11. package/lib/BetaMessageStream.d.ts +111 -0
  12. package/lib/BetaMessageStream.d.ts.map +1 -0
  13. package/lib/BetaMessageStream.js +487 -0
  14. package/lib/BetaMessageStream.js.map +1 -0
  15. package/lib/BetaMessageStream.mjs +483 -0
  16. package/lib/BetaMessageStream.mjs.map +1 -0
  17. package/lib/MessageStream.d.ts +18 -2
  18. package/lib/MessageStream.d.ts.map +1 -1
  19. package/lib/MessageStream.js +35 -7
  20. package/lib/MessageStream.js.map +1 -1
  21. package/lib/MessageStream.mjs +35 -7
  22. package/lib/MessageStream.mjs.map +1 -1
  23. package/package.json +1 -1
  24. package/resources/beta/messages/batches.d.ts +26 -1
  25. package/resources/beta/messages/batches.d.ts.map +1 -1
  26. package/resources/beta/messages/batches.js +14 -0
  27. package/resources/beta/messages/batches.js.map +1 -1
  28. package/resources/beta/messages/batches.mjs +14 -0
  29. package/resources/beta/messages/batches.mjs.map +1 -1
  30. package/resources/beta/messages/index.d.ts +2 -2
  31. package/resources/beta/messages/index.d.ts.map +1 -1
  32. package/resources/beta/messages/index.js.map +1 -1
  33. package/resources/beta/messages/index.mjs.map +1 -1
  34. package/resources/beta/messages/messages.d.ts +8 -2
  35. package/resources/beta/messages/messages.d.ts.map +1 -1
  36. package/resources/beta/messages/messages.js +20 -0
  37. package/resources/beta/messages/messages.js.map +1 -1
  38. package/resources/beta/messages/messages.mjs +20 -0
  39. package/resources/beta/messages/messages.mjs.map +1 -1
  40. package/resources/messages/batches.d.ts +19 -1
  41. package/resources/messages/batches.d.ts.map +1 -1
  42. package/resources/messages/batches.js +16 -1
  43. package/resources/messages/batches.js.map +1 -1
  44. package/resources/messages/batches.mjs +16 -1
  45. package/resources/messages/batches.mjs.map +1 -1
  46. package/resources/messages/index.d.ts +1 -1
  47. package/resources/messages/index.d.ts.map +1 -1
  48. package/resources/messages/index.js.map +1 -1
  49. package/resources/messages/index.mjs.map +1 -1
  50. package/resources/messages/messages.d.ts +2 -2
  51. package/resources/messages/messages.d.ts.map +1 -1
  52. package/resources/messages/messages.js +3 -0
  53. package/resources/messages/messages.js.map +1 -1
  54. package/resources/messages/messages.mjs +3 -0
  55. package/resources/messages/messages.mjs.map +1 -1
  56. package/src/core.ts +11 -1
  57. package/src/index.ts +6 -6
  58. package/src/lib/BetaMessageStream.ts +593 -0
  59. package/src/lib/MessageStream.ts +44 -12
  60. package/src/resources/beta/messages/batches.ts +53 -0
  61. package/src/resources/beta/messages/index.ts +3 -0
  62. package/src/resources/beta/messages/messages.ts +37 -0
  63. package/src/resources/messages/batches.ts +32 -1
  64. package/src/resources/messages/index.ts +1 -0
  65. package/src/resources/messages/messages.ts +7 -4
  66. package/src/version.ts +1 -1
  67. package/version.d.ts +1 -1
  68. package/version.js +1 -1
  69. package/version.mjs +1 -1
@@ -85,6 +85,35 @@ export class Batches extends APIResource {
85
85
  });
86
86
  }
87
87
 
88
+ /**
89
+ * This endpoint is idempotent and can be used to poll for Message Batch
90
+ * completion. To access the results of a Message Batch, make a request to the
91
+ * `results_url` field in the response.
92
+ */
93
+ delete(
94
+ messageBatchId: string,
95
+ params?: BatchDeleteParams,
96
+ options?: Core.RequestOptions,
97
+ ): Core.APIPromise<BetaDeletedMessageBatch>;
98
+ delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<BetaDeletedMessageBatch>;
99
+ delete(
100
+ messageBatchId: string,
101
+ params: BatchDeleteParams | Core.RequestOptions = {},
102
+ options?: Core.RequestOptions,
103
+ ): Core.APIPromise<BetaDeletedMessageBatch> {
104
+ if (isRequestOptions(params)) {
105
+ return this.delete(messageBatchId, {}, params);
106
+ }
107
+ const { betas } = params;
108
+ return this._client.delete(`/v1/messages/batches/${messageBatchId}?beta=true`, {
109
+ ...options,
110
+ headers: {
111
+ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
112
+ ...options?.headers,
113
+ },
114
+ });
115
+ }
116
+
88
117
  /**
89
118
  * Batches may be canceled any time before processing ends. Once cancellation is
90
119
  * initiated, the batch enters a `canceling` state, at which time the system may
@@ -158,6 +187,7 @@ export class Batches extends APIResource {
158
187
  ...options,
159
188
  headers: {
160
189
  'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
190
+ Accept: 'application/binary',
161
191
  ...options?.headers,
162
192
  },
163
193
  __binaryResponse: true,
@@ -168,6 +198,20 @@ export class Batches extends APIResource {
168
198
 
169
199
  export class BetaMessageBatchesPage extends Page<BetaMessageBatch> {}
170
200
 
201
+ export interface BetaDeletedMessageBatch {
202
+ /**
203
+ * ID of the Message Batch.
204
+ */
205
+ id: string;
206
+
207
+ /**
208
+ * Deleted object type.
209
+ *
210
+ * For Message Batches, this is always `"message_batch_deleted"`.
211
+ */
212
+ type: 'message_batch_deleted';
213
+ }
214
+
171
215
  export interface BetaMessageBatch {
172
216
  /**
173
217
  * Unique object identifier.
@@ -374,6 +418,13 @@ export interface BatchListParams extends PageParams {
374
418
  betas?: Array<BetaAPI.AnthropicBeta>;
375
419
  }
376
420
 
421
+ export interface BatchDeleteParams {
422
+ /**
423
+ * Optional header to specify the beta version(s) you want to use.
424
+ */
425
+ betas?: Array<BetaAPI.AnthropicBeta>;
426
+ }
427
+
377
428
  export interface BatchCancelParams {
378
429
  /**
379
430
  * Optional header to specify the beta version(s) you want to use.
@@ -392,6 +443,7 @@ Batches.BetaMessageBatchesPage = BetaMessageBatchesPage;
392
443
 
393
444
  export declare namespace Batches {
394
445
  export {
446
+ type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
395
447
  type BetaMessageBatch as BetaMessageBatch,
396
448
  type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
397
449
  type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
@@ -404,6 +456,7 @@ export declare namespace Batches {
404
456
  type BatchCreateParams as BatchCreateParams,
405
457
  type BatchRetrieveParams as BatchRetrieveParams,
406
458
  type BatchListParams as BatchListParams,
459
+ type BatchDeleteParams as BatchDeleteParams,
407
460
  type BatchCancelParams as BatchCancelParams,
408
461
  type BatchResultsParams as BatchResultsParams,
409
462
  };
@@ -3,6 +3,7 @@
3
3
  export {
4
4
  BetaMessageBatchesPage,
5
5
  Batches,
6
+ type BetaDeletedMessageBatch,
6
7
  type BetaMessageBatch,
7
8
  type BetaMessageBatchCanceledResult,
8
9
  type BetaMessageBatchErroredResult,
@@ -14,6 +15,7 @@ export {
14
15
  type BatchCreateParams,
15
16
  type BatchRetrieveParams,
16
17
  type BatchListParams,
18
+ type BatchDeleteParams,
17
19
  type BatchCancelParams,
18
20
  type BatchResultsParams,
19
21
  } from "./batches.js";
@@ -58,4 +60,5 @@ export {
58
60
  type MessageCreateParamsNonStreaming,
59
61
  type MessageCreateParamsStreaming,
60
62
  type MessageCountTokensParams,
63
+ type BetaMessageStreamParams,
61
64
  } from "./messages.js";
@@ -10,10 +10,12 @@ import * as BatchesAPI from "./batches.js";
10
10
  import {
11
11
  BatchCancelParams,
12
12
  BatchCreateParams,
13
+ BatchDeleteParams,
13
14
  BatchListParams,
14
15
  BatchResultsParams,
15
16
  BatchRetrieveParams,
16
17
  Batches,
18
+ BetaDeletedMessageBatch,
17
19
  BetaMessageBatch,
18
20
  BetaMessageBatchCanceledResult,
19
21
  BetaMessageBatchErroredResult,
@@ -25,6 +27,21 @@ import {
25
27
  BetaMessageBatchesPage,
26
28
  } from "./batches.js";
27
29
  import { Stream } from "../../../streaming.js";
30
+ import { BetaMessageStream } from "../../../lib/BetaMessageStream.js";
31
+ import type { Model } from "../../messages/messages.js";
32
+
33
+ const DEPRECATED_MODELS: {
34
+ [K in Model]?: string;
35
+ } = {
36
+ 'claude-1.3': 'November 6th, 2024',
37
+ 'claude-1.3-100k': 'November 6th, 2024',
38
+ 'claude-instant-1.1': 'November 6th, 2024',
39
+ 'claude-instant-1.1-100k': 'November 6th, 2024',
40
+ 'claude-instant-1.2': 'November 6th, 2024',
41
+ 'claude-3-sonnet-20240229': 'July 21st, 2025',
42
+ 'claude-2.1': 'July 21st, 2025',
43
+ 'claude-2.0': 'July 21st, 2025',
44
+ };
28
45
 
29
46
  export class Messages extends APIResource {
30
47
  batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
@@ -50,6 +67,15 @@ export class Messages extends APIResource {
50
67
  options?: Core.RequestOptions,
51
68
  ): APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>> {
52
69
  const { betas, ...body } = params;
70
+
71
+ if (body.model in DEPRECATED_MODELS) {
72
+ console.warn(
73
+ `The model '${body.model}' is deprecated and will reach end-of-life on ${
74
+ DEPRECATED_MODELS[body.model]
75
+ }\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`,
76
+ );
77
+ }
78
+
53
79
  return this._client.post('/v1/messages?beta=true', {
54
80
  body,
55
81
  timeout: (this._client as any)._options.timeout ?? 600000,
@@ -62,6 +88,13 @@ export class Messages extends APIResource {
62
88
  }) as APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>>;
63
89
  }
64
90
 
91
+ /**
92
+ * Create a Message stream
93
+ */
94
+ stream(body: BetaMessageStreamParams, options?: Core.RequestOptions): BetaMessageStream {
95
+ return BetaMessageStream.createMessage(this, body, options);
96
+ }
97
+
65
98
  /**
66
99
  * Count the number of tokens in a Message.
67
100
  *
@@ -84,6 +117,8 @@ export class Messages extends APIResource {
84
117
  }
85
118
  }
86
119
 
120
+ export type BetaMessageStreamParams = MessageCreateParamsBase;
121
+
87
122
  export interface BetaBase64PDFBlock {
88
123
  source: BetaBase64PDFSource;
89
124
 
@@ -1115,6 +1150,7 @@ export declare namespace Messages {
1115
1150
 
1116
1151
  export {
1117
1152
  Batches as Batches,
1153
+ type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
1118
1154
  type BetaMessageBatch as BetaMessageBatch,
1119
1155
  type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
1120
1156
  type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
@@ -1127,6 +1163,7 @@ export declare namespace Messages {
1127
1163
  type BatchCreateParams as BatchCreateParams,
1128
1164
  type BatchRetrieveParams as BatchRetrieveParams,
1129
1165
  type BatchListParams as BatchListParams,
1166
+ type BatchDeleteParams as BatchDeleteParams,
1130
1167
  type BatchCancelParams as BatchCancelParams,
1131
1168
  type BatchResultsParams as BatchResultsParams,
1132
1169
  };
@@ -49,6 +49,15 @@ export class Batches extends APIResource {
49
49
  return this._client.getAPIList('/v1/messages/batches', MessageBatchesPage, { query, ...options });
50
50
  }
51
51
 
52
+ /**
53
+ * This endpoint is idempotent and can be used to poll for Message Batch
54
+ * completion. To access the results of a Message Batch, make a request to the
55
+ * `results_url` field in the response.
56
+ */
57
+ delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<DeletedMessageBatch> {
58
+ return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options);
59
+ }
60
+
52
61
  /**
53
62
  * Batches may be canceled any time before processing ends. Once cancellation is
54
63
  * initiated, the batch enters a `canceling` state, at which time the system may
@@ -83,13 +92,34 @@ export class Batches extends APIResource {
83
92
  }
84
93
 
85
94
  return this._client
86
- .get(batch.results_url, { ...options, __binaryResponse: true })
95
+ .get(batch.results_url, {
96
+ ...options,
97
+ headers: {
98
+ Accept: 'application/binary',
99
+ ...options?.headers,
100
+ },
101
+ __binaryResponse: true,
102
+ })
87
103
  ._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
88
104
  }
89
105
  }
90
106
 
91
107
  export class MessageBatchesPage extends Page<MessageBatch> {}
92
108
 
109
+ export interface DeletedMessageBatch {
110
+ /**
111
+ * ID of the Message Batch.
112
+ */
113
+ id: string;
114
+
115
+ /**
116
+ * Deleted object type.
117
+ *
118
+ * For Message Batches, this is always `"message_batch_deleted"`.
119
+ */
120
+ type: 'message_batch_deleted';
121
+ }
122
+
93
123
  export interface MessageBatch {
94
124
  /**
95
125
  * Unique object identifier.
@@ -283,6 +313,7 @@ Batches.MessageBatchesPage = MessageBatchesPage;
283
313
 
284
314
  export declare namespace Batches {
285
315
  export {
316
+ type DeletedMessageBatch as DeletedMessageBatch,
286
317
  type MessageBatch as MessageBatch,
287
318
  type MessageBatchCanceledResult as MessageBatchCanceledResult,
288
319
  type MessageBatchErroredResult as MessageBatchErroredResult,
@@ -3,6 +3,7 @@
3
3
  export {
4
4
  MessageBatchesPage,
5
5
  Batches,
6
+ type DeletedMessageBatch,
6
7
  type MessageBatch,
7
8
  type MessageBatchCanceledResult,
8
9
  type MessageBatchErroredResult,
@@ -9,6 +9,7 @@ import {
9
9
  BatchCreateParams,
10
10
  BatchListParams,
11
11
  Batches,
12
+ DeletedMessageBatch,
12
13
  MessageBatch,
13
14
  MessageBatchCanceledResult,
14
15
  MessageBatchErroredResult,
@@ -308,16 +309,17 @@ export type Model =
308
309
  | 'claude-2.1'
309
310
  | 'claude-2.0';
310
311
 
311
- type DeprecatedModelsType = {
312
+ const DEPRECATED_MODELS: {
312
313
  [K in Model]?: string;
313
- };
314
-
315
- const DEPRECATED_MODELS: DeprecatedModelsType = {
314
+ } = {
316
315
  'claude-1.3': 'November 6th, 2024',
317
316
  'claude-1.3-100k': 'November 6th, 2024',
318
317
  'claude-instant-1.1': 'November 6th, 2024',
319
318
  'claude-instant-1.1-100k': 'November 6th, 2024',
320
319
  'claude-instant-1.2': 'November 6th, 2024',
320
+ 'claude-3-sonnet-20240229': 'July 21st, 2025',
321
+ 'claude-2.1': 'July 21st, 2025',
322
+ 'claude-2.0': 'July 21st, 2025',
321
323
  };
322
324
 
323
325
  export interface RawContentBlockDeltaEvent {
@@ -1114,6 +1116,7 @@ export declare namespace Messages {
1114
1116
 
1115
1117
  export {
1116
1118
  Batches as Batches,
1119
+ type DeletedMessageBatch as DeletedMessageBatch,
1117
1120
  type MessageBatch as MessageBatch,
1118
1121
  type MessageBatchCanceledResult as MessageBatchCanceledResult,
1119
1122
  type MessageBatchErroredResult as MessageBatchErroredResult,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.33.1'; // x-release-please-version
1
+ export const VERSION = '0.35.0'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.33.1";
1
+ export declare const VERSION = "0.35.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.33.1'; // x-release-please-version
4
+ exports.VERSION = '0.35.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.33.1'; // x-release-please-version
1
+ export const VERSION = '0.35.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map