@anthropic-ai/sdk 0.113.0 → 0.115.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.
- package/CHANGELOG.md +23 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts.map +1 -1
- package/client.js +8 -1
- package/client.js.map +1 -1
- package/client.mjs +8 -1
- package/client.mjs.map +1 -1
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +3 -0
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +3 -0
- package/core/streaming.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +10 -1
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +10 -1
- package/internal/parse.mjs.map +1 -1
- package/internal/request-signal.d.mts +4 -0
- package/internal/request-signal.d.mts.map +1 -0
- package/internal/request-signal.d.ts +4 -0
- package/internal/request-signal.d.ts.map +1 -0
- package/internal/request-signal.js +50 -0
- package/internal/request-signal.js.map +1 -0
- package/internal/request-signal.mjs +45 -0
- package/internal/request-signal.mjs.map +1 -0
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +3 -0
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +3 -0
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/middleware.d.mts +5 -3
- package/lib/middleware.d.mts.map +1 -1
- package/lib/middleware.d.ts +5 -3
- package/lib/middleware.d.ts.map +1 -1
- package/lib/middleware.js +58 -15
- package/lib/middleware.js.map +1 -1
- package/lib/middleware.mjs +58 -15
- package/lib/middleware.mjs.map +1 -1
- package/lib/tools/BetaToolRunner.d.mts.map +1 -1
- package/lib/tools/BetaToolRunner.d.ts.map +1 -1
- package/lib/tools/BetaToolRunner.js +80 -7
- package/lib/tools/BetaToolRunner.js.map +1 -1
- package/lib/tools/BetaToolRunner.mjs +80 -7
- package/lib/tools/BetaToolRunner.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +1 -1
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +1 -1
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/beta.d.mts +3 -3
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +3 -3
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.mts +1 -1
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/batches.d.mts +4 -3
- package/resources/beta/messages/batches.d.mts.map +1 -1
- package/resources/beta/messages/batches.d.ts +4 -3
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/index.d.mts +1 -1
- package/resources/beta/messages/index.d.mts.map +1 -1
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +155 -6
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +155 -6
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/sessions/events.d.mts +10 -6
- package/resources/beta/sessions/events.d.mts.map +1 -1
- package/resources/beta/sessions/events.d.ts +10 -6
- package/resources/beta/sessions/events.d.ts.map +1 -1
- package/resources/beta/sessions/events.js.map +1 -1
- package/resources/beta/sessions/events.mjs.map +1 -1
- package/resources/messages/messages.d.mts +3 -2
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +3 -2
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/src/client.ts +13 -1
- package/src/core/streaming.ts +3 -0
- package/src/internal/parse.ts +10 -1
- package/src/internal/request-signal.ts +68 -0
- package/src/lib/BetaMessageStream.ts +4 -0
- package/src/lib/middleware.ts +61 -16
- package/src/lib/tools/BetaToolRunner.ts +101 -8
- package/src/resources/beta/agents/agents.ts +1 -0
- package/src/resources/beta/beta.ts +22 -0
- package/src/resources/beta/index.ts +10 -0
- package/src/resources/beta/messages/batches.ts +4 -3
- package/src/resources/beta/messages/index.ts +10 -0
- package/src/resources/beta/messages/messages.ts +200 -4
- package/src/resources/beta/sessions/events.ts +10 -6
- package/src/resources/messages/messages.ts +10 -1
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/lib/tools/ToolRunner.d.mts +0 -132
- package/lib/tools/ToolRunner.d.mts.map +0 -1
- package/lib/tools/ToolRunner.d.ts +0 -132
- package/lib/tools/ToolRunner.d.ts.map +0 -1
- package/lib/tools/ToolRunner.js +0 -294
- package/lib/tools/ToolRunner.js.map +0 -1
- package/lib/tools/ToolRunner.mjs +0 -290
- package/lib/tools/ToolRunner.mjs.map +0 -1
- package/src/lib/tools/ToolRunner.ts +0 -381
|
@@ -2,7 +2,18 @@ import { BetaRunnableTool } from './BetaRunnableTool';
|
|
|
2
2
|
import { ToolError } from './ToolError';
|
|
3
3
|
import { Anthropic } from '../..';
|
|
4
4
|
import { AnthropicError } from '../../core/error';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BetaContentBlockParam,
|
|
7
|
+
BetaMessage,
|
|
8
|
+
BetaMessageParam,
|
|
9
|
+
BetaRequestToolAdditionBlock,
|
|
10
|
+
BetaRequestToolRemovalBlock,
|
|
11
|
+
BetaToolChangeMCPToolReference,
|
|
12
|
+
BetaToolChangeMCPToolsetReference,
|
|
13
|
+
BetaToolChangeToolReference,
|
|
14
|
+
BetaToolUnion,
|
|
15
|
+
MessageCreateParams,
|
|
16
|
+
} from '../../resources/beta';
|
|
6
17
|
import { BetaMessageStream } from '../BetaMessageStream';
|
|
7
18
|
import { RequestOptions } from '../../internal/request-options';
|
|
8
19
|
import { buildHeaders } from '../../internal/headers';
|
|
@@ -467,16 +478,14 @@ async function generateToolResponse(
|
|
|
467
478
|
return null;
|
|
468
479
|
}
|
|
469
480
|
|
|
481
|
+
const available = availableToolNames(params);
|
|
470
482
|
const toolResults = await Promise.all(
|
|
471
483
|
toolUseBlocks.map(async (toolUse) => {
|
|
472
484
|
const tool = params.tools.find((t) => ('name' in t ? t.name : t.mcp_server_name) === toolUse.name);
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
content: `Error: Tool '${toolUse.name}' not found`,
|
|
478
|
-
is_error: true,
|
|
479
|
-
};
|
|
485
|
+
// A `tool_removal` is only a hint to the model, which may still emit a tool_use for a
|
|
486
|
+
// withdrawn tool — treat those exactly like a tool that was never defined.
|
|
487
|
+
if (!tool || !('run' in tool) || !available.has(toolUse.name)) {
|
|
488
|
+
return toolNotFoundResult(toolUse);
|
|
480
489
|
}
|
|
481
490
|
|
|
482
491
|
try {
|
|
@@ -515,6 +524,90 @@ async function generateToolResponse(
|
|
|
515
524
|
};
|
|
516
525
|
}
|
|
517
526
|
|
|
527
|
+
function toolNotFoundResult(toolUse: { id: string; name: string }) {
|
|
528
|
+
return {
|
|
529
|
+
type: 'tool_result' as const,
|
|
530
|
+
tool_use_id: toolUse.id,
|
|
531
|
+
content: `Error: Tool '${toolUse.name}' not found`,
|
|
532
|
+
is_error: true,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Computes the names of locally runnable tools that are still available for the assistant
|
|
538
|
+
* turn being answered, by folding `tool_removal` / `tool_addition` blocks from the
|
|
539
|
+
* `role: "system"` messages over the runnable tools. The assistant turn being answered is
|
|
540
|
+
* terminal-or-absent and only `system` messages are inspected, so folding the whole current
|
|
541
|
+
* history is exactly folding the messages preceding that turn — call this before appending
|
|
542
|
+
* anything after it. MCP references are ignored — those tools are executed server-side and
|
|
543
|
+
* never dispatched by this runner.
|
|
544
|
+
*/
|
|
545
|
+
function availableToolNames(params: BetaToolRunnerParams): Set<string> {
|
|
546
|
+
const available = new Set<string>();
|
|
547
|
+
for (const tool of params.tools) {
|
|
548
|
+
if ('run' in tool) {
|
|
549
|
+
available.add(tool.name);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
for (const message of params.messages) {
|
|
554
|
+
if (message.role !== 'system' || typeof message.content === 'string') {
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
for (const block of message.content) {
|
|
558
|
+
applyToolChange(block, available);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return available;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function applyToolChange(block: BetaContentBlockParam, available: Set<string>): void {
|
|
565
|
+
switch (block.type) {
|
|
566
|
+
case 'tool_removal':
|
|
567
|
+
case 'tool_addition':
|
|
568
|
+
applyToolReference(block, available);
|
|
569
|
+
break;
|
|
570
|
+
case 'mid_conv_system':
|
|
571
|
+
// A `mid_conv_system` block's content is limited by the API schema to
|
|
572
|
+
// text / tool_addition / tool_removal, so we walk exactly one level — no recursion.
|
|
573
|
+
for (const inner of block.content) {
|
|
574
|
+
if (inner.type === 'tool_removal' || inner.type === 'tool_addition') {
|
|
575
|
+
applyToolReference(inner, available);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
default:
|
|
580
|
+
// Other and unknown/newer block types leave the set untouched (forward compatibility).
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function applyToolReference(
|
|
586
|
+
block: BetaRequestToolAdditionBlock | BetaRequestToolRemovalBlock,
|
|
587
|
+
available: Set<string>,
|
|
588
|
+
): void {
|
|
589
|
+
const name = referencedToolName(block.tool);
|
|
590
|
+
if (name === undefined) return;
|
|
591
|
+
if (block.type === 'tool_removal') {
|
|
592
|
+
available.delete(name);
|
|
593
|
+
} else {
|
|
594
|
+
available.add(name);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function referencedToolName(
|
|
599
|
+
ref: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference,
|
|
600
|
+
): string | undefined {
|
|
601
|
+
switch (ref.type) {
|
|
602
|
+
case 'tool_reference':
|
|
603
|
+
return ref.name;
|
|
604
|
+
default:
|
|
605
|
+
// mcp_tool_reference / mcp_toolset_reference run server-side; unknown reference
|
|
606
|
+
// types are ignored rather than rejected.
|
|
607
|
+
return undefined;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
518
611
|
// vendored from typefest just to make things look a bit nicer on hover
|
|
519
612
|
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
520
613
|
|
|
@@ -363,11 +363,16 @@ import {
|
|
|
363
363
|
BetaEncryptedCodeExecutionResultBlockParam,
|
|
364
364
|
BetaFallbackBlock,
|
|
365
365
|
BetaFallbackBlockParam,
|
|
366
|
+
BetaFallbackCreditNotApplied,
|
|
367
|
+
BetaFallbackCreditRedeemed,
|
|
368
|
+
BetaFallbackCreditTokenParam,
|
|
369
|
+
BetaFallbackCreditUsage,
|
|
366
370
|
BetaFallbackInfo,
|
|
367
371
|
BetaFallbackInfoParam,
|
|
368
372
|
BetaFallbackMessageIterationUsage,
|
|
369
373
|
BetaFallbackParam,
|
|
370
374
|
BetaFallbackRefusalTrigger,
|
|
375
|
+
BetaFallbacksParam,
|
|
371
376
|
BetaFileDocumentSource,
|
|
372
377
|
BetaFileImageSource,
|
|
373
378
|
BetaImageBlockParam,
|
|
@@ -412,6 +417,8 @@ import {
|
|
|
412
417
|
BetaRequestMCPServerToolConfiguration,
|
|
413
418
|
BetaRequestMCPServerURLDefinition,
|
|
414
419
|
BetaRequestMCPToolResultBlockParam,
|
|
420
|
+
BetaRequestToolAdditionBlock,
|
|
421
|
+
BetaRequestToolRemovalBlock,
|
|
415
422
|
BetaSearchResultBlockParam,
|
|
416
423
|
BetaServerToolCaller,
|
|
417
424
|
BetaServerToolCaller20260120,
|
|
@@ -449,6 +456,9 @@ import {
|
|
|
449
456
|
BetaTool,
|
|
450
457
|
BetaToolBash20241022,
|
|
451
458
|
BetaToolBash20250124,
|
|
459
|
+
BetaToolChangeMCPToolReference,
|
|
460
|
+
BetaToolChangeMCPToolsetReference,
|
|
461
|
+
BetaToolChangeToolReference,
|
|
452
462
|
BetaToolChoice,
|
|
453
463
|
BetaToolChoiceAny,
|
|
454
464
|
BetaToolChoiceAuto,
|
|
@@ -633,7 +643,9 @@ export type AnthropicBeta =
|
|
|
633
643
|
| 'dreaming-2026-04-21'
|
|
634
644
|
| 'thinking-token-count-2026-05-13'
|
|
635
645
|
| 'server-side-fallback-2026-06-01'
|
|
646
|
+
| 'server-side-fallback-2026-07-01'
|
|
636
647
|
| 'fallback-credit-2026-06-01'
|
|
648
|
+
| 'fallback-credit-2026-07-01'
|
|
637
649
|
| 'agent-memory-2026-07-22';
|
|
638
650
|
|
|
639
651
|
export interface BetaAPIError {
|
|
@@ -842,11 +854,16 @@ export declare namespace Beta {
|
|
|
842
854
|
type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
|
|
843
855
|
type BetaFallbackBlock as BetaFallbackBlock,
|
|
844
856
|
type BetaFallbackBlockParam as BetaFallbackBlockParam,
|
|
857
|
+
type BetaFallbackCreditNotApplied as BetaFallbackCreditNotApplied,
|
|
858
|
+
type BetaFallbackCreditRedeemed as BetaFallbackCreditRedeemed,
|
|
859
|
+
type BetaFallbackCreditTokenParam as BetaFallbackCreditTokenParam,
|
|
860
|
+
type BetaFallbackCreditUsage as BetaFallbackCreditUsage,
|
|
845
861
|
type BetaFallbackInfo as BetaFallbackInfo,
|
|
846
862
|
type BetaFallbackInfoParam as BetaFallbackInfoParam,
|
|
847
863
|
type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
|
|
848
864
|
type BetaFallbackParam as BetaFallbackParam,
|
|
849
865
|
type BetaFallbackRefusalTrigger as BetaFallbackRefusalTrigger,
|
|
866
|
+
type BetaFallbacksParam as BetaFallbacksParam,
|
|
850
867
|
type BetaFileDocumentSource as BetaFileDocumentSource,
|
|
851
868
|
type BetaFileImageSource as BetaFileImageSource,
|
|
852
869
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
@@ -893,6 +910,8 @@ export declare namespace Beta {
|
|
|
893
910
|
type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
|
|
894
911
|
type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
|
|
895
912
|
type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
|
|
913
|
+
type BetaRequestToolAdditionBlock as BetaRequestToolAdditionBlock,
|
|
914
|
+
type BetaRequestToolRemovalBlock as BetaRequestToolRemovalBlock,
|
|
896
915
|
type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
|
|
897
916
|
type BetaServerToolCaller as BetaServerToolCaller,
|
|
898
917
|
type BetaServerToolCaller20260120 as BetaServerToolCaller20260120,
|
|
@@ -930,6 +949,9 @@ export declare namespace Beta {
|
|
|
930
949
|
type BetaTool as BetaTool,
|
|
931
950
|
type BetaToolBash20241022 as BetaToolBash20241022,
|
|
932
951
|
type BetaToolBash20250124 as BetaToolBash20250124,
|
|
952
|
+
type BetaToolChangeMCPToolReference as BetaToolChangeMCPToolReference,
|
|
953
|
+
type BetaToolChangeMCPToolsetReference as BetaToolChangeMCPToolsetReference,
|
|
954
|
+
type BetaToolChangeToolReference as BetaToolChangeToolReference,
|
|
933
955
|
type BetaToolChoice as BetaToolChoice,
|
|
934
956
|
type BetaToolChoiceAny as BetaToolChoiceAny,
|
|
935
957
|
type BetaToolChoiceAuto as BetaToolChoiceAuto,
|
|
@@ -292,11 +292,16 @@ export {
|
|
|
292
292
|
type BetaEncryptedCodeExecutionResultBlockParam,
|
|
293
293
|
type BetaFallbackBlock,
|
|
294
294
|
type BetaFallbackBlockParam,
|
|
295
|
+
type BetaFallbackCreditNotApplied,
|
|
296
|
+
type BetaFallbackCreditRedeemed,
|
|
297
|
+
type BetaFallbackCreditTokenParam,
|
|
298
|
+
type BetaFallbackCreditUsage,
|
|
295
299
|
type BetaFallbackInfo,
|
|
296
300
|
type BetaFallbackInfoParam,
|
|
297
301
|
type BetaFallbackMessageIterationUsage,
|
|
298
302
|
type BetaFallbackParam,
|
|
299
303
|
type BetaFallbackRefusalTrigger,
|
|
304
|
+
type BetaFallbacksParam,
|
|
300
305
|
type BetaFileDocumentSource,
|
|
301
306
|
type BetaFileImageSource,
|
|
302
307
|
type BetaImageBlockParam,
|
|
@@ -344,6 +349,8 @@ export {
|
|
|
344
349
|
type BetaRequestMCPServerToolConfiguration,
|
|
345
350
|
type BetaRequestMCPServerURLDefinition,
|
|
346
351
|
type BetaRequestMCPToolResultBlockParam,
|
|
352
|
+
type BetaRequestToolAdditionBlock,
|
|
353
|
+
type BetaRequestToolRemovalBlock,
|
|
347
354
|
type BetaSearchResultBlockParam,
|
|
348
355
|
type BetaServerToolCaller,
|
|
349
356
|
type BetaServerToolCaller20260120,
|
|
@@ -381,6 +388,9 @@ export {
|
|
|
381
388
|
type BetaTool,
|
|
382
389
|
type BetaToolBash20241022,
|
|
383
390
|
type BetaToolBash20250124,
|
|
391
|
+
type BetaToolChangeMCPToolReference,
|
|
392
|
+
type BetaToolChangeMCPToolsetReference,
|
|
393
|
+
type BetaToolChangeToolReference,
|
|
384
394
|
type BetaToolChoice,
|
|
385
395
|
type BetaToolChoiceAny,
|
|
386
396
|
type BetaToolChoiceAuto,
|
|
@@ -607,14 +607,15 @@ export namespace BatchCreateParams {
|
|
|
607
607
|
* When the appended-assistant form is used on a model that otherwise disallows
|
|
608
608
|
* assistant-turn prefill, this token also authorizes that one prefill.
|
|
609
609
|
*/
|
|
610
|
-
fallback_credit_token?: string | null;
|
|
610
|
+
fallback_credit_token?: string | BetaMessagesAPI.BetaFallbackCreditTokenParam | null;
|
|
611
611
|
|
|
612
612
|
/**
|
|
613
613
|
* Opt-in server-side retry on one or more substitute models when the requested
|
|
614
614
|
* model declines for policy reasons. Tried in order: if the first entry also
|
|
615
|
-
* declines, the second is tried, and so on.
|
|
615
|
+
* declines, the second is tried, and so on. The string "default" requests the
|
|
616
|
+
* requested model's server-defined default fallback configuration.
|
|
616
617
|
*/
|
|
617
|
-
fallbacks?:
|
|
618
|
+
fallbacks?: BetaMessagesAPI.BetaFallbacksParam | null;
|
|
618
619
|
|
|
619
620
|
/**
|
|
620
621
|
* Specifies the geographic region for inference processing. If not specified, the
|
|
@@ -106,11 +106,16 @@ export {
|
|
|
106
106
|
type BetaEncryptedCodeExecutionResultBlockParam,
|
|
107
107
|
type BetaFallbackBlock,
|
|
108
108
|
type BetaFallbackBlockParam,
|
|
109
|
+
type BetaFallbackCreditNotApplied,
|
|
110
|
+
type BetaFallbackCreditRedeemed,
|
|
111
|
+
type BetaFallbackCreditTokenParam,
|
|
112
|
+
type BetaFallbackCreditUsage,
|
|
109
113
|
type BetaFallbackInfo,
|
|
110
114
|
type BetaFallbackInfoParam,
|
|
111
115
|
type BetaFallbackMessageIterationUsage,
|
|
112
116
|
type BetaFallbackParam,
|
|
113
117
|
type BetaFallbackRefusalTrigger,
|
|
118
|
+
type BetaFallbacksParam,
|
|
114
119
|
type BetaFileDocumentSource,
|
|
115
120
|
type BetaFileImageSource,
|
|
116
121
|
type BetaImageBlockParam,
|
|
@@ -156,6 +161,8 @@ export {
|
|
|
156
161
|
type BetaRequestMCPServerToolConfiguration,
|
|
157
162
|
type BetaRequestMCPServerURLDefinition,
|
|
158
163
|
type BetaRequestMCPToolResultBlockParam,
|
|
164
|
+
type BetaRequestToolAdditionBlock,
|
|
165
|
+
type BetaRequestToolRemovalBlock,
|
|
159
166
|
type BetaSearchResultBlockParam,
|
|
160
167
|
type BetaServerToolCaller,
|
|
161
168
|
type BetaServerToolCaller20260120,
|
|
@@ -193,6 +200,9 @@ export {
|
|
|
193
200
|
type BetaTool,
|
|
194
201
|
type BetaToolBash20241022,
|
|
195
202
|
type BetaToolBash20250124,
|
|
203
|
+
type BetaToolChangeMCPToolReference,
|
|
204
|
+
type BetaToolChangeMCPToolsetReference,
|
|
205
|
+
type BetaToolChangeToolReference,
|
|
196
206
|
type BetaToolChoice,
|
|
197
207
|
type BetaToolChoiceAny,
|
|
198
208
|
type BetaToolChoiceAuto,
|
|
@@ -1441,6 +1441,8 @@ export type BetaContentBlockParam =
|
|
|
1441
1441
|
| BetaContainerUploadBlockParam
|
|
1442
1442
|
| BetaCompactionBlockParam
|
|
1443
1443
|
| BetaMidConversationSystemBlockParam
|
|
1444
|
+
| BetaRequestToolAdditionBlock
|
|
1445
|
+
| BetaRequestToolRemovalBlock
|
|
1444
1446
|
| BetaFallbackBlockParam;
|
|
1445
1447
|
|
|
1446
1448
|
export interface BetaContentBlockSource {
|
|
@@ -1631,6 +1633,94 @@ export interface BetaFallbackBlockParam {
|
|
|
1631
1633
|
trigger?: unknown;
|
|
1632
1634
|
}
|
|
1633
1635
|
|
|
1636
|
+
/**
|
|
1637
|
+
* No reprice was applied; `reason` says why.
|
|
1638
|
+
*/
|
|
1639
|
+
export interface BetaFallbackCreditNotApplied {
|
|
1640
|
+
/**
|
|
1641
|
+
* Why the reprice was not applied.
|
|
1642
|
+
*
|
|
1643
|
+
* A closed enum; additions to the redemption-check vocabulary arrive as deliberate
|
|
1644
|
+
* schema updates.
|
|
1645
|
+
*/
|
|
1646
|
+
reason:
|
|
1647
|
+
| 'body_mismatch'
|
|
1648
|
+
| 'continuation_excluded'
|
|
1649
|
+
| 'continuation_only'
|
|
1650
|
+
| 'expired'
|
|
1651
|
+
| 'invalid_target_model'
|
|
1652
|
+
| 'not_enabled'
|
|
1653
|
+
| 'reprice_unavailable'
|
|
1654
|
+
| 'temporarily_unavailable'
|
|
1655
|
+
| 'variant_fields_present'
|
|
1656
|
+
| 'wrong_organization'
|
|
1657
|
+
| 'wrong_platform'
|
|
1658
|
+
| 'wrong_workspace';
|
|
1659
|
+
|
|
1660
|
+
type: 'not_applied';
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* Request fields to remove before retrying, so the retry can redeem this token.
|
|
1664
|
+
*
|
|
1665
|
+
* Present exactly when `reason` is `variant_fields_present` — never null, never an
|
|
1666
|
+
* empty array; absent otherwise. Fields are named only from your own request, and
|
|
1667
|
+
* only after the sealed variant hash matched. A served best-effort retry has
|
|
1668
|
+
* already been billed at normal price; nothing redeems retroactively, but a
|
|
1669
|
+
* corrected re-send inside the token's five-minute window can still redeem.
|
|
1670
|
+
*/
|
|
1671
|
+
remove_to_redeem?: Array<string> | null;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* The reprice was applied: the retry is billed as if the conversation had been on
|
|
1676
|
+
* the retry model all along.
|
|
1677
|
+
*/
|
|
1678
|
+
export interface BetaFallbackCreditRedeemed {
|
|
1679
|
+
type: 'redeemed';
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Object form of `fallback_credit_token`: the token plus a redemption mode.
|
|
1684
|
+
*
|
|
1685
|
+
* Requires `anthropic-beta: fallback-credit-2026-07-01`; without that header the
|
|
1686
|
+
* field accepts the bare string only. The bare string and the mode-less object are
|
|
1687
|
+
* equivalent (both select `strict`), so wrapping an existing token changes nothing
|
|
1688
|
+
* by itself.
|
|
1689
|
+
*/
|
|
1690
|
+
export interface BetaFallbackCreditTokenParam {
|
|
1691
|
+
/**
|
|
1692
|
+
* The opaque `fallback_credit_token` from a prior refusal's `stop_details` — the
|
|
1693
|
+
* same string the bare-string form carries.
|
|
1694
|
+
*/
|
|
1695
|
+
token: string;
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* How a failing token affects the retry. `strict` (the default, and the
|
|
1699
|
+
* bare-string behavior): a failing redemption is a 400 and the retry is not
|
|
1700
|
+
* served. `best_effort`: the retry is served either way — a token-layer failure no
|
|
1701
|
+
* longer rejects the request; the retry proceeds at normal price and the outcome
|
|
1702
|
+
* is reported on the response's `usage.fallback_credit`. Two failures stay hard in
|
|
1703
|
+
* both modes: a malformed token, and combining `fallback_credit_token` with
|
|
1704
|
+
* `fallbacks`.
|
|
1705
|
+
*/
|
|
1706
|
+
mode?: 'strict' | 'best_effort';
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Outcome of the `fallback_credit_token` presented on this request.
|
|
1711
|
+
*/
|
|
1712
|
+
export interface BetaFallbackCreditUsage {
|
|
1713
|
+
/**
|
|
1714
|
+
* Whether the fallback-credit reprice was applied to this response's billing.
|
|
1715
|
+
*
|
|
1716
|
+
* A union discriminated on `type`. `redeemed`: the retry is billed as if the
|
|
1717
|
+
* conversation had been on the retry model all along — including when the
|
|
1718
|
+
* resulting shift is zero because there was nothing to move. `not_applied`: no
|
|
1719
|
+
* reprice was applied; the arm's `reason` says why.
|
|
1720
|
+
*/
|
|
1721
|
+
status: BetaFallbackCreditRedeemed | BetaFallbackCreditNotApplied;
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1634
1724
|
/**
|
|
1635
1725
|
* Identifies one hop of a fallback transition.
|
|
1636
1726
|
*/
|
|
@@ -1765,6 +1855,14 @@ export interface BetaFallbackRefusalTrigger {
|
|
|
1765
1855
|
type: 'refusal';
|
|
1766
1856
|
}
|
|
1767
1857
|
|
|
1858
|
+
/**
|
|
1859
|
+
* Opt-in server-side retry on one or more substitute models when the requested
|
|
1860
|
+
* model declines for policy reasons. Tried in order: if the first entry also
|
|
1861
|
+
* declines, the second is tried, and so on. The string "default" requests the
|
|
1862
|
+
* requested model's server-defined default fallback configuration.
|
|
1863
|
+
*/
|
|
1864
|
+
export type BetaFallbacksParam = Array<BetaFallbackParam> | 'default';
|
|
1865
|
+
|
|
1768
1866
|
export interface BetaFileDocumentSource {
|
|
1769
1867
|
file_id: string;
|
|
1770
1868
|
|
|
@@ -2172,6 +2270,7 @@ export interface BetaMessage {
|
|
|
2172
2270
|
* back as-is in a subsequent request to let the model continue.
|
|
2173
2271
|
* - `"refusal"`: when streaming classifiers intervene to handle potential policy
|
|
2174
2272
|
* violations
|
|
2273
|
+
* - `"model_context_window_exceeded"`: we exceeded the model's context window
|
|
2175
2274
|
*
|
|
2176
2275
|
* In non-streaming mode this value is always non-null. In streaming mode, it is
|
|
2177
2276
|
* null in the `message_start` event and non-null otherwise.
|
|
@@ -2224,6 +2323,11 @@ export interface BetaMessageDeltaUsage {
|
|
|
2224
2323
|
*/
|
|
2225
2324
|
cache_read_input_tokens: number | null;
|
|
2226
2325
|
|
|
2326
|
+
/**
|
|
2327
|
+
* Outcome of the `fallback_credit_token` presented on this request.
|
|
2328
|
+
*/
|
|
2329
|
+
fallback_credit: BetaFallbackCreditUsage | null;
|
|
2330
|
+
|
|
2227
2331
|
/**
|
|
2228
2332
|
* The cumulative number of input tokens which were used.
|
|
2229
2333
|
*/
|
|
@@ -2346,7 +2450,7 @@ export interface BetaMidConversationSystemBlockParam {
|
|
|
2346
2450
|
/**
|
|
2347
2451
|
* System instruction text blocks.
|
|
2348
2452
|
*/
|
|
2349
|
-
content: Array<BetaTextBlockParam>;
|
|
2453
|
+
content: Array<BetaTextBlockParam | BetaRequestToolAdditionBlock | BetaRequestToolRemovalBlock>;
|
|
2350
2454
|
|
|
2351
2455
|
type: 'mid_conv_system';
|
|
2352
2456
|
|
|
@@ -2668,6 +2772,50 @@ export interface BetaRequestMCPToolResultBlockParam {
|
|
|
2668
2772
|
is_error?: boolean;
|
|
2669
2773
|
}
|
|
2670
2774
|
|
|
2775
|
+
/**
|
|
2776
|
+
* Mid-conversation directive to surface a declared tool.
|
|
2777
|
+
*
|
|
2778
|
+
* `tool` references a tool (or MCP toolset) by name from the request's `tools`; it
|
|
2779
|
+
* is offered to the model from this point in the conversation onward.
|
|
2780
|
+
*/
|
|
2781
|
+
export interface BetaRequestToolAdditionBlock {
|
|
2782
|
+
/**
|
|
2783
|
+
* Reference to a single tool the caller declared directly in `tools[]`. Does not
|
|
2784
|
+
* accept the composed `{server}_{name}` form the server assigns to MCP-resolved
|
|
2785
|
+
* tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
|
|
2786
|
+
*/
|
|
2787
|
+
tool: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference;
|
|
2788
|
+
|
|
2789
|
+
type: 'tool_addition';
|
|
2790
|
+
|
|
2791
|
+
/**
|
|
2792
|
+
* Create a cache control breakpoint at this content block.
|
|
2793
|
+
*/
|
|
2794
|
+
cache_control?: BetaCacheControlEphemeral | null;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
/**
|
|
2798
|
+
* Mid-conversation directive to withdraw a tool.
|
|
2799
|
+
*
|
|
2800
|
+
* `tool` references a tool (or MCP toolset) by name from the request's `tools`; it
|
|
2801
|
+
* is no longer offered to the model from this point in the conversation onward.
|
|
2802
|
+
*/
|
|
2803
|
+
export interface BetaRequestToolRemovalBlock {
|
|
2804
|
+
/**
|
|
2805
|
+
* Reference to a single tool the caller declared directly in `tools[]`. Does not
|
|
2806
|
+
* accept the composed `{server}_{name}` form the server assigns to MCP-resolved
|
|
2807
|
+
* tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
|
|
2808
|
+
*/
|
|
2809
|
+
tool: BetaToolChangeToolReference | BetaToolChangeMCPToolReference | BetaToolChangeMCPToolsetReference;
|
|
2810
|
+
|
|
2811
|
+
type: 'tool_removal';
|
|
2812
|
+
|
|
2813
|
+
/**
|
|
2814
|
+
* Create a cache control breakpoint at this content block.
|
|
2815
|
+
*/
|
|
2816
|
+
cache_control?: BetaCacheControlEphemeral | null;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2671
2819
|
export interface BetaSearchResultBlockParam {
|
|
2672
2820
|
content: Array<BetaTextBlockParam>;
|
|
2673
2821
|
|
|
@@ -3252,6 +3400,38 @@ export interface BetaToolBash20250124 {
|
|
|
3252
3400
|
strict?: boolean;
|
|
3253
3401
|
}
|
|
3254
3402
|
|
|
3403
|
+
/**
|
|
3404
|
+
* Reference to a single MCP tool by its server and remote name — the same
|
|
3405
|
+
* `server_name`/`name` pair `mcp_tool_use` carries.
|
|
3406
|
+
*/
|
|
3407
|
+
export interface BetaToolChangeMCPToolReference {
|
|
3408
|
+
name: string;
|
|
3409
|
+
|
|
3410
|
+
server_name: string;
|
|
3411
|
+
|
|
3412
|
+
type: 'mcp_tool_reference';
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
/**
|
|
3416
|
+
* Reference to every tool in the named MCP server's toolset.
|
|
3417
|
+
*/
|
|
3418
|
+
export interface BetaToolChangeMCPToolsetReference {
|
|
3419
|
+
server_name: string;
|
|
3420
|
+
|
|
3421
|
+
type: 'mcp_toolset_reference';
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
/**
|
|
3425
|
+
* Reference to a single tool the caller declared directly in `tools[]`. Does not
|
|
3426
|
+
* accept the composed `{server}_{name}` form the server assigns to MCP-resolved
|
|
3427
|
+
* tools — use `mcp_tool_reference` or `mcp_toolset_reference` for those.
|
|
3428
|
+
*/
|
|
3429
|
+
export interface BetaToolChangeToolReference {
|
|
3430
|
+
name: string;
|
|
3431
|
+
|
|
3432
|
+
type: 'tool_reference';
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3255
3435
|
/**
|
|
3256
3436
|
* How the model should use the provided tools. The model can use a specific tool,
|
|
3257
3437
|
* any available tool, decide by itself, or not use tools at all.
|
|
@@ -3865,6 +4045,11 @@ export interface BetaUsage {
|
|
|
3865
4045
|
*/
|
|
3866
4046
|
cache_read_input_tokens: number | null;
|
|
3867
4047
|
|
|
4048
|
+
/**
|
|
4049
|
+
* Outcome of the `fallback_credit_token` presented on this request.
|
|
4050
|
+
*/
|
|
4051
|
+
fallback_credit: BetaFallbackCreditUsage | null;
|
|
4052
|
+
|
|
3868
4053
|
/**
|
|
3869
4054
|
* The geographic region where inference was performed for this request.
|
|
3870
4055
|
*/
|
|
@@ -4694,14 +4879,15 @@ export interface MessageCreateParamsBase {
|
|
|
4694
4879
|
* When the appended-assistant form is used on a model that otherwise disallows
|
|
4695
4880
|
* assistant-turn prefill, this token also authorizes that one prefill.
|
|
4696
4881
|
*/
|
|
4697
|
-
fallback_credit_token?: string | null;
|
|
4882
|
+
fallback_credit_token?: string | BetaFallbackCreditTokenParam | null;
|
|
4698
4883
|
|
|
4699
4884
|
/**
|
|
4700
4885
|
* Body param: Opt-in server-side retry on one or more substitute models when the
|
|
4701
4886
|
* requested model declines for policy reasons. Tried in order: if the first entry
|
|
4702
|
-
* also declines, the second is tried, and so on.
|
|
4887
|
+
* also declines, the second is tried, and so on. The string "default" requests the
|
|
4888
|
+
* requested model's server-defined default fallback configuration.
|
|
4703
4889
|
*/
|
|
4704
|
-
fallbacks?:
|
|
4890
|
+
fallbacks?: BetaFallbacksParam | null;
|
|
4705
4891
|
|
|
4706
4892
|
/**
|
|
4707
4893
|
* Body param: Specifies the geographic region for inference processing. If not
|
|
@@ -5306,11 +5492,16 @@ export declare namespace Messages {
|
|
|
5306
5492
|
type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
|
|
5307
5493
|
type BetaFallbackBlock as BetaFallbackBlock,
|
|
5308
5494
|
type BetaFallbackBlockParam as BetaFallbackBlockParam,
|
|
5495
|
+
type BetaFallbackCreditNotApplied as BetaFallbackCreditNotApplied,
|
|
5496
|
+
type BetaFallbackCreditRedeemed as BetaFallbackCreditRedeemed,
|
|
5497
|
+
type BetaFallbackCreditTokenParam as BetaFallbackCreditTokenParam,
|
|
5498
|
+
type BetaFallbackCreditUsage as BetaFallbackCreditUsage,
|
|
5309
5499
|
type BetaFallbackInfo as BetaFallbackInfo,
|
|
5310
5500
|
type BetaFallbackInfoParam as BetaFallbackInfoParam,
|
|
5311
5501
|
type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
|
|
5312
5502
|
type BetaFallbackParam as BetaFallbackParam,
|
|
5313
5503
|
type BetaFallbackRefusalTrigger as BetaFallbackRefusalTrigger,
|
|
5504
|
+
type BetaFallbacksParam as BetaFallbacksParam,
|
|
5314
5505
|
type BetaFileDocumentSource as BetaFileDocumentSource,
|
|
5315
5506
|
type BetaFileImageSource as BetaFileImageSource,
|
|
5316
5507
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
@@ -5358,6 +5549,8 @@ export declare namespace Messages {
|
|
|
5358
5549
|
type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
|
|
5359
5550
|
type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
|
|
5360
5551
|
type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
|
|
5552
|
+
type BetaRequestToolAdditionBlock as BetaRequestToolAdditionBlock,
|
|
5553
|
+
type BetaRequestToolRemovalBlock as BetaRequestToolRemovalBlock,
|
|
5361
5554
|
type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
|
|
5362
5555
|
type BetaServerToolCaller as BetaServerToolCaller,
|
|
5363
5556
|
type BetaServerToolCaller20260120 as BetaServerToolCaller20260120,
|
|
@@ -5395,6 +5588,9 @@ export declare namespace Messages {
|
|
|
5395
5588
|
type BetaTool as BetaTool,
|
|
5396
5589
|
type BetaToolBash20241022 as BetaToolBash20241022,
|
|
5397
5590
|
type BetaToolBash20250124 as BetaToolBash20250124,
|
|
5591
|
+
type BetaToolChangeMCPToolReference as BetaToolChangeMCPToolReference,
|
|
5592
|
+
type BetaToolChangeMCPToolsetReference as BetaToolChangeMCPToolsetReference,
|
|
5593
|
+
type BetaToolChangeToolReference as BetaToolChangeToolReference,
|
|
5398
5594
|
type BetaToolChoice as BetaToolChoice,
|
|
5399
5595
|
type BetaToolChoiceAny as BetaToolChoiceAny,
|
|
5400
5596
|
type BetaToolChoiceAuto as BetaToolChoiceAuto,
|
|
@@ -1869,28 +1869,32 @@ export interface BetaManagedAgentsUserToolResultEventParams {
|
|
|
1869
1869
|
|
|
1870
1870
|
export interface EventListParams extends PageCursorParams {
|
|
1871
1871
|
/**
|
|
1872
|
-
* Query param: Return events created after this time (exclusive).
|
|
1872
|
+
* Query param: Return events created after this time (exclusive). Compared against
|
|
1873
|
+
* the event's `processed_at` value.
|
|
1873
1874
|
*/
|
|
1874
1875
|
'created_at[gt]'?: string;
|
|
1875
1876
|
|
|
1876
1877
|
/**
|
|
1877
|
-
* Query param: Return events created at or after this time (inclusive).
|
|
1878
|
+
* Query param: Return events created at or after this time (inclusive). Compared
|
|
1879
|
+
* against the event's `processed_at` value.
|
|
1878
1880
|
*/
|
|
1879
1881
|
'created_at[gte]'?: string;
|
|
1880
1882
|
|
|
1881
1883
|
/**
|
|
1882
|
-
* Query param: Return events created before this time (exclusive).
|
|
1884
|
+
* Query param: Return events created before this time (exclusive). Compared
|
|
1885
|
+
* against the event's `processed_at` value.
|
|
1883
1886
|
*/
|
|
1884
1887
|
'created_at[lt]'?: string;
|
|
1885
1888
|
|
|
1886
1889
|
/**
|
|
1887
|
-
* Query param: Return events created at or before this time (inclusive).
|
|
1890
|
+
* Query param: Return events created at or before this time (inclusive). Compared
|
|
1891
|
+
* against the event's `processed_at` value.
|
|
1888
1892
|
*/
|
|
1889
1893
|
'created_at[lte]'?: string;
|
|
1890
1894
|
|
|
1891
1895
|
/**
|
|
1892
|
-
* Query param: Sort direction for results, ordered by
|
|
1893
|
-
* (chronological).
|
|
1896
|
+
* Query param: Sort direction for results, ordered by the event's `processed_at`.
|
|
1897
|
+
* Defaults to asc (chronological).
|
|
1894
1898
|
*/
|
|
1895
1899
|
order?: 'asc' | 'desc';
|
|
1896
1900
|
|
|
@@ -1100,6 +1100,7 @@ export interface Message {
|
|
|
1100
1100
|
* back as-is in a subsequent request to let the model continue.
|
|
1101
1101
|
* - `"refusal"`: when streaming classifiers intervene to handle potential policy
|
|
1102
1102
|
* violations
|
|
1103
|
+
* - `"model_context_window_exceeded"`: we exceeded the model's context window
|
|
1103
1104
|
*
|
|
1104
1105
|
* In non-streaming mode this value is always non-null. In streaming mode, it is
|
|
1105
1106
|
* null in the `message_start` event and non-null otherwise.
|
|
@@ -1259,6 +1260,7 @@ export type Model =
|
|
|
1259
1260
|
| 'claude-sonnet-5'
|
|
1260
1261
|
| 'claude-fable-5'
|
|
1261
1262
|
| 'claude-mythos-5'
|
|
1263
|
+
| 'claude-opus-5'
|
|
1262
1264
|
| 'claude-opus-4-8'
|
|
1263
1265
|
| 'claude-opus-4-7'
|
|
1264
1266
|
| 'claude-mythos-preview'
|
|
@@ -1587,7 +1589,14 @@ export interface SignatureDelta {
|
|
|
1587
1589
|
type: 'signature_delta';
|
|
1588
1590
|
}
|
|
1589
1591
|
|
|
1590
|
-
export type StopReason =
|
|
1592
|
+
export type StopReason =
|
|
1593
|
+
| 'end_turn'
|
|
1594
|
+
| 'max_tokens'
|
|
1595
|
+
| 'stop_sequence'
|
|
1596
|
+
| 'tool_use'
|
|
1597
|
+
| 'pause_turn'
|
|
1598
|
+
| 'refusal'
|
|
1599
|
+
| 'model_context_window_exceeded';
|
|
1591
1600
|
|
|
1592
1601
|
export interface TextBlock {
|
|
1593
1602
|
/**
|