@anthropic-ai/sdk 0.55.1 → 0.57.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 (82) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +24 -24
  3. package/client.d.mts +7 -5
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +7 -5
  6. package/client.d.ts.map +1 -1
  7. package/client.js +15 -12
  8. package/client.js.map +1 -1
  9. package/client.mjs +15 -12
  10. package/client.mjs.map +1 -1
  11. package/core/streaming.d.mts +5 -3
  12. package/core/streaming.d.mts.map +1 -1
  13. package/core/streaming.d.ts +5 -3
  14. package/core/streaming.d.ts.map +1 -1
  15. package/core/streaming.js +18 -12
  16. package/core/streaming.js.map +1 -1
  17. package/core/streaming.mjs +18 -12
  18. package/core/streaming.mjs.map +1 -1
  19. package/internal/request-options.d.mts +42 -0
  20. package/internal/request-options.d.mts.map +1 -1
  21. package/internal/request-options.d.ts +42 -0
  22. package/internal/request-options.d.ts.map +1 -1
  23. package/internal/request-options.js.map +1 -1
  24. package/internal/request-options.mjs.map +1 -1
  25. package/package.json +1 -1
  26. package/resources/beta/beta.d.mts +2 -2
  27. package/resources/beta/beta.d.mts.map +1 -1
  28. package/resources/beta/beta.d.ts +2 -2
  29. package/resources/beta/beta.d.ts.map +1 -1
  30. package/resources/beta/beta.js.map +1 -1
  31. package/resources/beta/beta.mjs.map +1 -1
  32. package/resources/beta/index.d.mts +1 -1
  33. package/resources/beta/index.d.mts.map +1 -1
  34. package/resources/beta/index.d.ts +1 -1
  35. package/resources/beta/index.d.ts.map +1 -1
  36. package/resources/beta/index.js.map +1 -1
  37. package/resources/beta/index.mjs.map +1 -1
  38. package/resources/beta/messages/batches.d.mts +1 -1
  39. package/resources/beta/messages/batches.d.ts +1 -1
  40. package/resources/beta/messages/batches.js +1 -1
  41. package/resources/beta/messages/batches.mjs +1 -1
  42. package/resources/beta/messages/index.d.mts +1 -1
  43. package/resources/beta/messages/index.d.mts.map +1 -1
  44. package/resources/beta/messages/index.d.ts +1 -1
  45. package/resources/beta/messages/index.d.ts.map +1 -1
  46. package/resources/beta/messages/index.js.map +1 -1
  47. package/resources/beta/messages/index.mjs.map +1 -1
  48. package/resources/beta/messages/messages.d.mts +58 -13
  49. package/resources/beta/messages/messages.d.mts.map +1 -1
  50. package/resources/beta/messages/messages.d.ts +58 -13
  51. package/resources/beta/messages/messages.d.ts.map +1 -1
  52. package/resources/beta/messages/messages.js +1 -0
  53. package/resources/beta/messages/messages.js.map +1 -1
  54. package/resources/beta/messages/messages.mjs +1 -0
  55. package/resources/beta/messages/messages.mjs.map +1 -1
  56. package/resources/messages/batches.d.mts +1 -1
  57. package/resources/messages/batches.d.ts +1 -1
  58. package/resources/messages/batches.js +1 -1
  59. package/resources/messages/batches.mjs +1 -1
  60. package/resources/messages/messages.d.mts +22 -6
  61. package/resources/messages/messages.d.mts.map +1 -1
  62. package/resources/messages/messages.d.ts +22 -6
  63. package/resources/messages/messages.d.ts.map +1 -1
  64. package/resources/messages/messages.js +1 -0
  65. package/resources/messages/messages.js.map +1 -1
  66. package/resources/messages/messages.mjs +1 -0
  67. package/resources/messages/messages.mjs.map +1 -1
  68. package/src/client.ts +19 -14
  69. package/src/core/streaming.ts +24 -10
  70. package/src/internal/request-options.ts +53 -0
  71. package/src/resources/beta/beta.ts +6 -0
  72. package/src/resources/beta/index.ts +3 -0
  73. package/src/resources/beta/messages/batches.ts +1 -1
  74. package/src/resources/beta/messages/index.ts +3 -0
  75. package/src/resources/beta/messages/messages.ts +102 -29
  76. package/src/resources/messages/batches.ts +1 -1
  77. package/src/resources/messages/messages.ts +31 -14
  78. package/src/version.ts +1 -1
  79. package/version.d.mts +1 -1
  80. package/version.d.ts +1 -1
  81. package/version.js +1 -1
  82. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -172,6 +172,8 @@ export interface ClientOptions {
172
172
  *
173
173
  * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
174
174
  * much longer than this timeout before the promise succeeds or fails.
175
+ *
176
+ * @unit milliseconds
175
177
  */
176
178
  timeout?: number | undefined;
177
179
  /**
@@ -309,7 +311,7 @@ export class BaseAnthropic {
309
311
  * Create a new client instance re-using the same options given to the current client with optional overriding.
310
312
  */
311
313
  withOptions(options: Partial<ClientOptions>): this {
312
- return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
314
+ const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
313
315
  ...this._options,
314
316
  baseURL: this.baseURL,
315
317
  maxRetries: this.maxRetries,
@@ -322,6 +324,7 @@ export class BaseAnthropic {
322
324
  authToken: this.authToken,
323
325
  ...options,
324
326
  });
327
+ return client;
325
328
  }
326
329
 
327
330
  /**
@@ -355,18 +358,18 @@ export class BaseAnthropic {
355
358
  );
356
359
  }
357
360
 
358
- protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
359
- return buildHeaders([this.apiKeyAuth(opts), this.bearerAuth(opts)]);
361
+ protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
362
+ return buildHeaders([await this.apiKeyAuth(opts), await this.bearerAuth(opts)]);
360
363
  }
361
364
 
362
- protected apiKeyAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
365
+ protected async apiKeyAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
363
366
  if (this.apiKey == null) {
364
367
  return undefined;
365
368
  }
366
369
  return buildHeaders([{ 'X-Api-Key': this.apiKey }]);
367
370
  }
368
371
 
369
- protected bearerAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
372
+ protected async bearerAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
370
373
  if (this.authToken == null) {
371
374
  return undefined;
372
375
  }
@@ -513,7 +516,9 @@ export class BaseAnthropic {
513
516
 
514
517
  await this.prepareOptions(options);
515
518
 
516
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
519
+ const { req, url, timeout } = await this.buildRequest(options, {
520
+ retryCount: maxRetries - retriesRemaining,
521
+ });
517
522
 
518
523
  await this.prepareRequest(req, { url, options });
519
524
 
@@ -595,7 +600,7 @@ export class BaseAnthropic {
595
600
  } with status ${response.status} in ${headersTime - startTime}ms`;
596
601
 
597
602
  if (!response.ok) {
598
- const shouldRetry = this.shouldRetry(response);
603
+ const shouldRetry = await this.shouldRetry(response);
599
604
  if (retriesRemaining && shouldRetry) {
600
605
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
601
606
 
@@ -713,7 +718,7 @@ export class BaseAnthropic {
713
718
  }
714
719
  }
715
720
 
716
- private shouldRetry(response: Response): boolean {
721
+ private async shouldRetry(response: Response): Promise<boolean> {
717
722
  // Note this is not a standard header.
718
723
  const shouldRetryHeader = response.headers.get('x-should-retry');
719
724
 
@@ -804,10 +809,10 @@ export class BaseAnthropic {
804
809
  return defaultTime;
805
810
  }
806
811
 
807
- buildRequest(
812
+ async buildRequest(
808
813
  inputOptions: FinalRequestOptions,
809
814
  { retryCount = 0 }: { retryCount?: number } = {},
810
- ): { req: FinalizedRequestInit; url: string; timeout: number } {
815
+ ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
811
816
  const options = { ...inputOptions };
812
817
  const { method, path, query, defaultBaseURL } = options;
813
818
 
@@ -815,7 +820,7 @@ export class BaseAnthropic {
815
820
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
816
821
  options.timeout = options.timeout ?? this.timeout;
817
822
  const { bodyHeaders, body } = this.buildBody({ options });
818
- const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
823
+ const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
819
824
 
820
825
  const req: FinalizedRequestInit = {
821
826
  method,
@@ -831,7 +836,7 @@ export class BaseAnthropic {
831
836
  return { req, url, timeout: options.timeout };
832
837
  }
833
838
 
834
- private buildHeaders({
839
+ private async buildHeaders({
835
840
  options,
836
841
  method,
837
842
  bodyHeaders,
@@ -841,7 +846,7 @@ export class BaseAnthropic {
841
846
  method: HTTPMethod;
842
847
  bodyHeaders: HeadersLike;
843
848
  retryCount: number;
844
- }): Headers {
849
+ }): Promise<Headers> {
845
850
  let idempotencyHeaders: HeadersLike = {};
846
851
  if (this.idempotencyHeader && method !== 'get') {
847
852
  if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
@@ -861,7 +866,7 @@ export class BaseAnthropic {
861
866
  : undefined),
862
867
  'anthropic-version': '2023-06-01',
863
868
  },
864
- this.authHeaders(options),
869
+ await this.authHeaders(options),
865
870
  this._options.defaultHeaders,
866
871
  bodyHeaders,
867
872
  options.headers,
@@ -6,6 +6,8 @@ import { ReadableStreamToAsyncIterable } from '../internal/shims';
6
6
  import { isAbortError } from '../internal/errors';
7
7
  import { safeJSON } from '../internal/utils/values';
8
8
  import { encodeUTF8 } from '../internal/utils/bytes';
9
+ import { loggerFor } from '../internal/utils/log';
10
+ import type { BaseAnthropic } from '../client';
9
11
 
10
12
  import { APIError } from './error';
11
13
 
@@ -19,16 +21,24 @@ export type ServerSentEvent = {
19
21
 
20
22
  export class Stream<Item> implements AsyncIterable<Item> {
21
23
  controller: AbortController;
24
+ #client: BaseAnthropic | undefined;
22
25
 
23
26
  constructor(
24
27
  private iterator: () => AsyncIterator<Item>,
25
28
  controller: AbortController,
29
+ client?: BaseAnthropic,
26
30
  ) {
27
31
  this.controller = controller;
32
+ this.#client = client;
28
33
  }
29
34
 
30
- static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item> {
35
+ static fromSSEResponse<Item>(
36
+ response: Response,
37
+ controller: AbortController,
38
+ client?: BaseAnthropic,
39
+ ): Stream<Item> {
31
40
  let consumed = false;
41
+ const logger = client ? loggerFor(client) : console;
32
42
 
33
43
  async function* iterator(): AsyncIterator<Item, any, undefined> {
34
44
  if (consumed) {
@@ -42,8 +52,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
42
52
  try {
43
53
  yield JSON.parse(sse.data);
44
54
  } catch (e) {
45
- console.error(`Could not parse message into JSON:`, sse.data);
46
- console.error(`From chunk:`, sse.raw);
55
+ logger.error(`Could not parse message into JSON:`, sse.data);
56
+ logger.error(`From chunk:`, sse.raw);
47
57
  throw e;
48
58
  }
49
59
  }
@@ -59,8 +69,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
59
69
  try {
60
70
  yield JSON.parse(sse.data);
61
71
  } catch (e) {
62
- console.error(`Could not parse message into JSON:`, sse.data);
63
- console.error(`From chunk:`, sse.raw);
72
+ logger.error(`Could not parse message into JSON:`, sse.data);
73
+ logger.error(`From chunk:`, sse.raw);
64
74
  throw e;
65
75
  }
66
76
  }
@@ -84,14 +94,18 @@ export class Stream<Item> implements AsyncIterable<Item> {
84
94
  }
85
95
  }
86
96
 
87
- return new Stream(iterator, controller);
97
+ return new Stream(iterator, controller, client);
88
98
  }
89
99
 
90
100
  /**
91
101
  * Generates a Stream from a newline-separated ReadableStream
92
102
  * where each item is a JSON value.
93
103
  */
94
- static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item> {
104
+ static fromReadableStream<Item>(
105
+ readableStream: ReadableStream,
106
+ controller: AbortController,
107
+ client?: BaseAnthropic,
108
+ ): Stream<Item> {
95
109
  let consumed = false;
96
110
 
97
111
  async function* iterLines(): AsyncGenerator<string, void, unknown> {
@@ -131,7 +145,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
131
145
  }
132
146
  }
133
147
 
134
- return new Stream(iterator, controller);
148
+ return new Stream(iterator, controller, client);
135
149
  }
136
150
 
137
151
  [Symbol.asyncIterator](): AsyncIterator<Item> {
@@ -161,8 +175,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
161
175
  };
162
176
 
163
177
  return [
164
- new Stream(() => teeIterator(left), this.controller),
165
- new Stream(() => teeIterator(right), this.controller),
178
+ new Stream(() => teeIterator(left), this.controller, this.#client),
179
+ new Stream(() => teeIterator(right), this.controller, this.#client),
166
180
  ];
167
181
  }
168
182
 
@@ -10,17 +10,70 @@ import { type HeadersLike } from './headers';
10
10
  export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
11
11
 
12
12
  export type RequestOptions = {
13
+ /**
14
+ * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
15
+ */
13
16
  method?: HTTPMethod;
17
+
18
+ /**
19
+ * The URL path for the request.
20
+ *
21
+ * @example "/v1/foo"
22
+ */
14
23
  path?: string;
24
+
25
+ /**
26
+ * Query parameters to include in the request URL.
27
+ */
15
28
  query?: object | undefined | null;
29
+
30
+ /**
31
+ * The request body. Can be a string, JSON object, FormData, or other supported types.
32
+ */
16
33
  body?: unknown;
34
+
35
+ /**
36
+ * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
37
+ */
17
38
  headers?: HeadersLike;
39
+
40
+ /**
41
+ * The maximum number of times that the client will retry a request in case of a
42
+ * temporary failure, like a network error or a 5XX error from the server.
43
+ *
44
+ * @default 2
45
+ */
18
46
  maxRetries?: number;
47
+
19
48
  stream?: boolean | undefined;
49
+
50
+ /**
51
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
52
+ * from the server before timing out a single request.
53
+ *
54
+ * @unit milliseconds
55
+ */
20
56
  timeout?: number;
57
+
58
+ /**
59
+ * Additional `RequestInit` options to be passed to the underlying `fetch` call.
60
+ * These options will be merged with the client's default fetch options.
61
+ */
21
62
  fetchOptions?: MergedRequestInit;
63
+
64
+ /**
65
+ * An AbortSignal that can be used to cancel the request.
66
+ */
22
67
  signal?: AbortSignal | undefined | null;
68
+
69
+ /**
70
+ * A unique key for this request to enable idempotency.
71
+ */
23
72
  idempotencyKey?: string;
73
+
74
+ /**
75
+ * Override the default base URL for this specific request.
76
+ */
24
77
  defaultBaseURL?: string | undefined;
25
78
 
26
79
  __binaryResponse?: boolean | undefined;
@@ -28,6 +28,8 @@ import {
28
28
  BetaCitationContentBlockLocationParam,
29
29
  BetaCitationPageLocation,
30
30
  BetaCitationPageLocationParam,
31
+ BetaCitationSearchResultLocation,
32
+ BetaCitationSearchResultLocationParam,
31
33
  BetaCitationWebSearchResultLocationParam,
32
34
  BetaCitationsConfigParam,
33
35
  BetaCitationsDelta,
@@ -78,6 +80,7 @@ import {
78
80
  BetaRequestMCPServerToolConfiguration,
79
81
  BetaRequestMCPServerURLDefinition,
80
82
  BetaRequestMCPToolResultBlockParam,
83
+ BetaSearchResultBlockParam,
81
84
  BetaServerToolUsage,
82
85
  BetaServerToolUseBlock,
83
86
  BetaServerToolUseBlockParam,
@@ -265,6 +268,8 @@ export declare namespace Beta {
265
268
  type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
266
269
  type BetaCitationPageLocation as BetaCitationPageLocation,
267
270
  type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
271
+ type BetaCitationSearchResultLocation as BetaCitationSearchResultLocation,
272
+ type BetaCitationSearchResultLocationParam as BetaCitationSearchResultLocationParam,
268
273
  type BetaCitationWebSearchResultLocationParam as BetaCitationWebSearchResultLocationParam,
269
274
  type BetaCitationsConfigParam as BetaCitationsConfigParam,
270
275
  type BetaCitationsDelta as BetaCitationsDelta,
@@ -315,6 +320,7 @@ export declare namespace Beta {
315
320
  type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
316
321
  type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
317
322
  type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
323
+ type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
318
324
  type BetaServerToolUsage as BetaServerToolUsage,
319
325
  type BetaServerToolUseBlock as BetaServerToolUseBlock,
320
326
  type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
@@ -38,6 +38,8 @@ export {
38
38
  type BetaCitationContentBlockLocationParam,
39
39
  type BetaCitationPageLocation,
40
40
  type BetaCitationPageLocationParam,
41
+ type BetaCitationSearchResultLocation,
42
+ type BetaCitationSearchResultLocationParam,
41
43
  type BetaCitationWebSearchResultLocationParam,
42
44
  type BetaCitationsConfigParam,
43
45
  type BetaCitationsDelta,
@@ -88,6 +90,7 @@ export {
88
90
  type BetaRequestMCPServerToolConfiguration,
89
91
  type BetaRequestMCPServerURLDefinition,
90
92
  type BetaRequestMCPToolResultBlockParam,
93
+ type BetaSearchResultBlockParam,
91
94
  type BetaServerToolUsage,
92
95
  type BetaServerToolUseBlock,
93
96
  type BetaServerToolUseBlockParam,
@@ -34,7 +34,7 @@ export class Batches extends APIResource {
34
34
  * messages: [
35
35
  * { content: 'Hello, world', role: 'user' },
36
36
  * ],
37
- * model: 'claude-3-7-sonnet-20250219',
37
+ * model: 'claude-sonnet-4-20250514',
38
38
  * },
39
39
  * },
40
40
  * ],
@@ -31,6 +31,8 @@ export {
31
31
  type BetaCitationContentBlockLocationParam,
32
32
  type BetaCitationPageLocation,
33
33
  type BetaCitationPageLocationParam,
34
+ type BetaCitationSearchResultLocation,
35
+ type BetaCitationSearchResultLocationParam,
34
36
  type BetaCitationWebSearchResultLocationParam,
35
37
  type BetaCitationsConfigParam,
36
38
  type BetaCitationsDelta,
@@ -81,6 +83,7 @@ export {
81
83
  type BetaRequestMCPServerToolConfiguration,
82
84
  type BetaRequestMCPServerURLDefinition,
83
85
  type BetaRequestMCPToolResultBlockParam,
86
+ type BetaSearchResultBlockParam,
84
87
  type BetaServerToolUsage,
85
88
  type BetaServerToolUseBlock,
86
89
  type BetaServerToolUseBlockParam,
@@ -40,6 +40,7 @@ const DEPRECATED_MODELS: {
40
40
  'claude-instant-1.1-100k': 'November 6th, 2024',
41
41
  'claude-instant-1.2': 'November 6th, 2024',
42
42
  'claude-3-sonnet-20240229': 'July 21st, 2025',
43
+ 'claude-3-opus-20240229': 'January 5th, 2026',
43
44
  'claude-2.1': 'July 21st, 2025',
44
45
  'claude-2.0': 'July 21st, 2025',
45
46
  };
@@ -62,7 +63,7 @@ export class Messages extends APIResource {
62
63
  * const betaMessage = await client.beta.messages.create({
63
64
  * max_tokens: 1024,
64
65
  * messages: [{ content: 'Hello, world', role: 'user' }],
65
- * model: 'claude-3-7-sonnet-20250219',
66
+ * model: 'claude-sonnet-4-20250514',
66
67
  * });
67
68
  * ```
68
69
  */
@@ -277,6 +278,38 @@ export interface BetaCitationPageLocationParam {
277
278
  type: 'page_location';
278
279
  }
279
280
 
281
+ export interface BetaCitationSearchResultLocation {
282
+ cited_text: string;
283
+
284
+ end_block_index: number;
285
+
286
+ search_result_index: number;
287
+
288
+ source: string;
289
+
290
+ start_block_index: number;
291
+
292
+ title: string | null;
293
+
294
+ type: 'search_result_location';
295
+ }
296
+
297
+ export interface BetaCitationSearchResultLocationParam {
298
+ cited_text: string;
299
+
300
+ end_block_index: number;
301
+
302
+ search_result_index: number;
303
+
304
+ source: string;
305
+
306
+ start_block_index: number;
307
+
308
+ title: string | null;
309
+
310
+ type: 'search_result_location';
311
+ }
312
+
280
313
  export interface BetaCitationWebSearchResultLocationParam {
281
314
  cited_text: string;
282
315
 
@@ -298,7 +331,8 @@ export interface BetaCitationsDelta {
298
331
  | BetaCitationCharLocation
299
332
  | BetaCitationPageLocation
300
333
  | BetaCitationContentBlockLocation
301
- | BetaCitationsWebSearchResultLocation;
334
+ | BetaCitationsWebSearchResultLocation
335
+ | BetaCitationSearchResultLocation;
302
336
 
303
337
  type: 'citations_delta';
304
338
  }
@@ -459,32 +493,33 @@ export interface BetaContainerUploadBlockParam {
459
493
  */
460
494
  export type BetaContentBlock =
461
495
  | BetaTextBlock
496
+ | BetaThinkingBlock
497
+ | BetaRedactedThinkingBlock
462
498
  | BetaToolUseBlock
463
499
  | BetaServerToolUseBlock
464
500
  | BetaWebSearchToolResultBlock
465
501
  | BetaCodeExecutionToolResultBlock
466
502
  | BetaMCPToolUseBlock
467
503
  | BetaMCPToolResultBlock
468
- | BetaContainerUploadBlock
469
- | BetaThinkingBlock
470
- | BetaRedactedThinkingBlock;
504
+ | BetaContainerUploadBlock;
471
505
 
472
506
  /**
473
507
  * Regular text content.
474
508
  */
475
509
  export type BetaContentBlockParam =
476
- | BetaServerToolUseBlockParam
477
- | BetaWebSearchToolResultBlockParam
478
- | BetaCodeExecutionToolResultBlockParam
479
- | BetaMCPToolUseBlockParam
480
- | BetaRequestMCPToolResultBlockParam
481
510
  | BetaTextBlockParam
482
511
  | BetaImageBlockParam
483
- | BetaToolUseBlockParam
484
- | BetaToolResultBlockParam
485
512
  | BetaRequestDocumentBlock
513
+ | BetaSearchResultBlockParam
486
514
  | BetaThinkingBlockParam
487
515
  | BetaRedactedThinkingBlockParam
516
+ | BetaToolUseBlockParam
517
+ | BetaToolResultBlockParam
518
+ | BetaServerToolUseBlockParam
519
+ | BetaWebSearchToolResultBlockParam
520
+ | BetaCodeExecutionToolResultBlockParam
521
+ | BetaMCPToolUseBlockParam
522
+ | BetaRequestMCPToolResultBlockParam
488
523
  | BetaContainerUploadBlockParam;
489
524
 
490
525
  export interface BetaContentBlockSource {
@@ -645,6 +680,10 @@ export interface BetaMessage {
645
680
  * - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
646
681
  * - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
647
682
  * - `"tool_use"`: the model invoked one or more tools
683
+ * - `"pause_turn"`: we paused a long-running turn. You may provide the response
684
+ * back as-is in a subsequent request to let the model continue.
685
+ * - `"refusal"`: when streaming classifiers intervene to handle potential policy
686
+ * violations
648
687
  *
649
688
  * In non-streaming mode this value is always non-null. In streaming mode, it is
650
689
  * null in the `message_start` event and non-null otherwise.
@@ -767,15 +806,15 @@ export interface BetaRawContentBlockStartEvent {
767
806
  */
768
807
  content_block:
769
808
  | BetaTextBlock
809
+ | BetaThinkingBlock
810
+ | BetaRedactedThinkingBlock
770
811
  | BetaToolUseBlock
771
812
  | BetaServerToolUseBlock
772
813
  | BetaWebSearchToolResultBlock
773
814
  | BetaCodeExecutionToolResultBlock
774
815
  | BetaMCPToolUseBlock
775
816
  | BetaMCPToolResultBlock
776
- | BetaContainerUploadBlock
777
- | BetaThinkingBlock
778
- | BetaRedactedThinkingBlock;
817
+ | BetaContainerUploadBlock;
779
818
 
780
819
  index: number;
781
820
 
@@ -912,6 +951,23 @@ export interface BetaRequestMCPToolResultBlockParam {
912
951
  is_error?: boolean;
913
952
  }
914
953
 
954
+ export interface BetaSearchResultBlockParam {
955
+ content: Array<BetaTextBlockParam>;
956
+
957
+ source: string;
958
+
959
+ title: string;
960
+
961
+ type: 'search_result';
962
+
963
+ /**
964
+ * Create a cache control breakpoint at this content block.
965
+ */
966
+ cache_control?: BetaCacheControlEphemeral | null;
967
+
968
+ citations?: BetaCitationsConfigParam;
969
+ }
970
+
915
971
  export interface BetaServerToolUsage {
916
972
  /**
917
973
  * The number of web search tool requests.
@@ -990,13 +1046,15 @@ export type BetaTextCitation =
990
1046
  | BetaCitationCharLocation
991
1047
  | BetaCitationPageLocation
992
1048
  | BetaCitationContentBlockLocation
993
- | BetaCitationsWebSearchResultLocation;
1049
+ | BetaCitationsWebSearchResultLocation
1050
+ | BetaCitationSearchResultLocation;
994
1051
 
995
1052
  export type BetaTextCitationParam =
996
1053
  | BetaCitationCharLocationParam
997
1054
  | BetaCitationPageLocationParam
998
1055
  | BetaCitationContentBlockLocationParam
999
- | BetaCitationWebSearchResultLocationParam;
1056
+ | BetaCitationWebSearchResultLocationParam
1057
+ | BetaCitationSearchResultLocationParam;
1000
1058
 
1001
1059
  export interface BetaTextDelta {
1002
1060
  text: string;
@@ -1279,7 +1337,7 @@ export interface BetaToolResultBlockParam {
1279
1337
  */
1280
1338
  cache_control?: BetaCacheControlEphemeral | null;
1281
1339
 
1282
- content?: string | Array<BetaTextBlockParam | BetaImageBlockParam>;
1340
+ content?: string | Array<BetaTextBlockParam | BetaImageBlockParam | BetaSearchResultBlockParam>;
1283
1341
 
1284
1342
  is_error?: boolean;
1285
1343
  }
@@ -1334,15 +1392,15 @@ export interface BetaToolTextEditor20250429 {
1334
1392
 
1335
1393
  export type BetaToolUnion =
1336
1394
  | BetaTool
1337
- | BetaToolComputerUse20241022
1338
1395
  | BetaToolBash20241022
1339
- | BetaToolTextEditor20241022
1340
- | BetaToolComputerUse20250124
1341
1396
  | BetaToolBash20250124
1397
+ | BetaCodeExecutionTool20250522
1398
+ | BetaToolComputerUse20241022
1399
+ | BetaToolComputerUse20250124
1400
+ | BetaToolTextEditor20241022
1342
1401
  | BetaToolTextEditor20250124
1343
1402
  | BetaToolTextEditor20250429
1344
- | BetaWebSearchTool20250305
1345
- | BetaCodeExecutionTool20250522;
1403
+ | BetaWebSearchTool20250305;
1346
1404
 
1347
1405
  export interface BetaToolUseBlock {
1348
1406
  id: string;
@@ -1668,7 +1726,7 @@ export interface MessageCreateParamsBase {
1668
1726
  * the top-level `system` parameter — there is no `"system"` role for input
1669
1727
  * messages in the Messages API.
1670
1728
  *
1671
- * There is a limit of 100000 messages in a single request.
1729
+ * There is a limit of 100,000 messages in a single request.
1672
1730
  */
1673
1731
  messages: Array<BetaMessageParam>;
1674
1732
 
@@ -1773,6 +1831,12 @@ export interface MessageCreateParamsBase {
1773
1831
  * those tools using the tool input generated by the model and then optionally
1774
1832
  * return results back to the model using `tool_result` content blocks.
1775
1833
  *
1834
+ * There are two types of tools: **client tools** and **server tools**. The
1835
+ * behavior described below applies to client tools. For
1836
+ * [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
1837
+ * see their individual documentation as each has its own behavior (e.g., the
1838
+ * [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
1839
+ *
1776
1840
  * Each tool definition includes:
1777
1841
  *
1778
1842
  * - `name`: Name of the tool.
@@ -1984,7 +2048,7 @@ export interface MessageCountTokensParams {
1984
2048
  * the top-level `system` parameter — there is no `"system"` role for input
1985
2049
  * messages in the Messages API.
1986
2050
  *
1987
- * There is a limit of 100000 messages in a single request.
2051
+ * There is a limit of 100,000 messages in a single request.
1988
2052
  */
1989
2053
  messages: Array<BetaMessageParam>;
1990
2054
 
@@ -2036,6 +2100,12 @@ export interface MessageCountTokensParams {
2036
2100
  * those tools using the tool input generated by the model and then optionally
2037
2101
  * return results back to the model using `tool_result` content blocks.
2038
2102
  *
2103
+ * There are two types of tools: **client tools** and **server tools**. The
2104
+ * behavior described below applies to client tools. For
2105
+ * [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
2106
+ * see their individual documentation as each has its own behavior (e.g., the
2107
+ * [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
2108
+ *
2039
2109
  * Each tool definition includes:
2040
2110
  *
2041
2111
  * - `name`: Name of the tool.
@@ -2101,15 +2171,15 @@ export interface MessageCountTokensParams {
2101
2171
  */
2102
2172
  tools?: Array<
2103
2173
  | BetaTool
2104
- | BetaToolComputerUse20241022
2105
2174
  | BetaToolBash20241022
2106
- | BetaToolTextEditor20241022
2107
- | BetaToolComputerUse20250124
2108
2175
  | BetaToolBash20250124
2176
+ | BetaCodeExecutionTool20250522
2177
+ | BetaToolComputerUse20241022
2178
+ | BetaToolComputerUse20250124
2179
+ | BetaToolTextEditor20241022
2109
2180
  | BetaToolTextEditor20250124
2110
2181
  | BetaToolTextEditor20250429
2111
2182
  | BetaWebSearchTool20250305
2112
- | BetaCodeExecutionTool20250522
2113
2183
  >;
2114
2184
 
2115
2185
  /**
@@ -2132,6 +2202,8 @@ export declare namespace Messages {
2132
2202
  type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
2133
2203
  type BetaCitationPageLocation as BetaCitationPageLocation,
2134
2204
  type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
2205
+ type BetaCitationSearchResultLocation as BetaCitationSearchResultLocation,
2206
+ type BetaCitationSearchResultLocationParam as BetaCitationSearchResultLocationParam,
2135
2207
  type BetaCitationWebSearchResultLocationParam as BetaCitationWebSearchResultLocationParam,
2136
2208
  type BetaCitationsConfigParam as BetaCitationsConfigParam,
2137
2209
  type BetaCitationsDelta as BetaCitationsDelta,
@@ -2182,6 +2254,7 @@ export declare namespace Messages {
2182
2254
  type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
2183
2255
  type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
2184
2256
  type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
2257
+ type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
2185
2258
  type BetaServerToolUsage as BetaServerToolUsage,
2186
2259
  type BetaServerToolUseBlock as BetaServerToolUseBlock,
2187
2260
  type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
@@ -33,7 +33,7 @@ export class Batches extends APIResource {
33
33
  * messages: [
34
34
  * { content: 'Hello, world', role: 'user' },
35
35
  * ],
36
- * model: 'claude-3-7-sonnet-20250219',
36
+ * model: 'claude-sonnet-4-20250514',
37
37
  * },
38
38
  * },
39
39
  * ],