@anthropic-ai/sdk 0.101.0 → 0.103.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 +28 -0
- package/client.d.mts +35 -2
- package/client.d.mts.map +1 -1
- package/client.d.ts +35 -2
- package/client.d.ts.map +1 -1
- package/client.js +74 -24
- package/client.js.map +1 -1
- package/client.mjs +73 -23
- package/client.mjs.map +1 -1
- package/core/middleware.d.mts +42 -5
- package/core/middleware.d.mts.map +1 -1
- package/core/middleware.d.ts +42 -5
- package/core/middleware.d.ts.map +1 -1
- package/core/middleware.js +14 -7
- package/core/middleware.js.map +1 -1
- package/core/middleware.mjs +14 -7
- package/core/middleware.mjs.map +1 -1
- package/core/streaming.d.mts +9 -0
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts +9 -0
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +11 -0
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +11 -0
- package/core/streaming.mjs.map +1 -1
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +0 -3
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +0 -3
- package/internal/parse.mjs.map +1 -1
- package/internal/request-options.d.mts +46 -3
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +46 -3
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js +12 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -1
- package/internal/utils/log.d.mts +11 -1
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts +11 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +34 -9
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +32 -8
- package/internal/utils/log.mjs.map +1 -1
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +5 -0
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +5 -0
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/middleware.d.mts +96 -0
- package/lib/middleware.d.mts.map +1 -0
- package/lib/middleware.d.ts +96 -0
- package/lib/middleware.d.ts.map +1 -0
- package/lib/middleware.js +703 -0
- package/lib/middleware.js.map +1 -0
- package/lib/middleware.mjs +698 -0
- package/lib/middleware.mjs.map +1 -0
- package/lib/tools/BetaToolRunner.d.mts +1 -1
- package/lib/tools/BetaToolRunner.d.mts.map +1 -1
- package/lib/tools/BetaToolRunner.d.ts +1 -1
- package/lib/tools/BetaToolRunner.d.ts.map +1 -1
- package/lib/tools/BetaToolRunner.js +10 -2
- package/lib/tools/BetaToolRunner.js.map +1 -1
- package/lib/tools/BetaToolRunner.mjs +10 -2
- package/lib/tools/BetaToolRunner.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +12 -22
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +12 -22
- 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 +28 -0
- package/resources/beta/messages/batches.d.mts.map +1 -1
- package/resources/beta/messages/batches.d.ts +28 -0
- 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 +247 -8
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +247 -8
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +7 -0
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +7 -0
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/models.d.mts +6 -0
- package/resources/beta/models.d.mts.map +1 -1
- package/resources/beta/models.d.ts +6 -0
- package/resources/beta/models.d.ts.map +1 -1
- package/resources/beta/webhooks.d.mts +22 -22
- package/resources/beta/webhooks.d.ts +22 -22
- 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 +1 -0
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +1 -0
- package/resources/messages/messages.mjs.map +1 -1
- package/src/client.ts +92 -27
- package/src/core/middleware.ts +53 -7
- package/src/core/streaming.ts +15 -0
- package/src/index.ts +6 -0
- package/src/internal/parse.ts +0 -4
- package/src/internal/request-options.ts +48 -3
- package/src/internal/utils/log.ts +39 -9
- package/src/lib/BetaMessageStream.ts +5 -0
- package/src/lib/middleware.ts +937 -0
- package/src/lib/tools/BetaToolRunner.ts +12 -3
- package/src/resources/beta/agents/agents.ts +13 -21
- package/src/resources/beta/beta.ts +15 -1
- package/src/resources/beta/index.ts +6 -0
- package/src/resources/beta/messages/batches.ts +30 -0
- package/src/resources/beta/messages/index.ts +6 -0
- package/src/resources/beta/messages/messages.ts +296 -7
- package/src/resources/beta/models.ts +7 -0
- package/src/resources/beta/webhooks.ts +22 -22
- package/src/resources/messages/messages.ts +6 -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
|
@@ -199,8 +199,17 @@ export class BetaToolRunner<Stream extends boolean> {
|
|
|
199
199
|
const isCompacted = await this.#checkAndCompact();
|
|
200
200
|
if (!isCompacted) {
|
|
201
201
|
if (!this.#mutated) {
|
|
202
|
-
const
|
|
203
|
-
this.#state.params.messages.push({ role, content });
|
|
202
|
+
const message = await this.#message;
|
|
203
|
+
this.#state.params.messages.push({ role: message.role, content: message.content });
|
|
204
|
+
|
|
205
|
+
// Refusal-terminated turns are terminal: the refusal may have cut a tool_use off
|
|
206
|
+
// with partial input, so executing this turn's tools would fire side effects the
|
|
207
|
+
// model never confirmed — and once middleware strips the refusal turn, their
|
|
208
|
+
// tool_results could never be replayed coherently. Surface the refusal as the
|
|
209
|
+
// final message instead.
|
|
210
|
+
if (message.stop_reason === 'refusal') {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
204
213
|
}
|
|
205
214
|
|
|
206
215
|
const toolMessage = await this.#generateToolResponse(this.#state.params.messages.at(-1)!);
|
|
@@ -521,4 +530,4 @@ export type BetaToolRunnerParams = Simplify<
|
|
|
521
530
|
}
|
|
522
531
|
>;
|
|
523
532
|
|
|
524
|
-
export type BetaToolRunnerRequestOptions = Pick<RequestOptions, 'headers' | 'signal'>;
|
|
533
|
+
export type BetaToolRunnerRequestOptions = Pick<RequestOptions, 'headers' | 'signal' | 'fallbackState'>;
|
|
@@ -519,20 +519,13 @@ export interface BetaManagedAgentsCustomTool {
|
|
|
519
519
|
* JSON Schema for custom tool input parameters.
|
|
520
520
|
*/
|
|
521
521
|
export interface BetaManagedAgentsCustomToolInputSchema {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
*/
|
|
522
|
+
type: 'object';
|
|
523
|
+
|
|
525
524
|
properties?: { [key: string]: unknown } | null;
|
|
526
525
|
|
|
527
|
-
|
|
528
|
-
* List of required property names.
|
|
529
|
-
*/
|
|
530
|
-
required?: Array<string>;
|
|
526
|
+
required?: Array<string> | null;
|
|
531
527
|
|
|
532
|
-
|
|
533
|
-
* Must be 'object' for tool input schemas.
|
|
534
|
-
*/
|
|
535
|
-
type?: 'object';
|
|
528
|
+
[k: string]: unknown;
|
|
536
529
|
}
|
|
537
530
|
|
|
538
531
|
/**
|
|
@@ -677,6 +670,7 @@ export interface BetaManagedAgentsMCPToolsetParams {
|
|
|
677
670
|
* details and options.
|
|
678
671
|
*/
|
|
679
672
|
export type BetaManagedAgentsModel =
|
|
673
|
+
| 'claude-fable-5'
|
|
680
674
|
| 'claude-opus-4-8'
|
|
681
675
|
| 'claude-opus-4-7'
|
|
682
676
|
| 'claude-opus-4-6'
|
|
@@ -835,12 +829,12 @@ export interface AgentCreateParams {
|
|
|
835
829
|
model: BetaManagedAgentsModel | BetaManagedAgentsModelConfigParams;
|
|
836
830
|
|
|
837
831
|
/**
|
|
838
|
-
* Body param: Human-readable name for the agent.
|
|
832
|
+
* Body param: Human-readable name for the agent.
|
|
839
833
|
*/
|
|
840
834
|
name: string;
|
|
841
835
|
|
|
842
836
|
/**
|
|
843
|
-
* Body param: Description of what the agent does.
|
|
837
|
+
* Body param: Description of what the agent does.
|
|
844
838
|
*/
|
|
845
839
|
description?: string | null;
|
|
846
840
|
|
|
@@ -864,12 +858,12 @@ export interface AgentCreateParams {
|
|
|
864
858
|
multiagent?: SessionsAPI.BetaManagedAgentsMultiagentParams | null;
|
|
865
859
|
|
|
866
860
|
/**
|
|
867
|
-
* Body param: Skills available to the agent.
|
|
861
|
+
* Body param: Skills available to the agent.
|
|
868
862
|
*/
|
|
869
863
|
skills?: Array<BetaManagedAgentsSkillParams>;
|
|
870
864
|
|
|
871
865
|
/**
|
|
872
|
-
* Body param: System prompt for the agent.
|
|
866
|
+
* Body param: System prompt for the agent.
|
|
873
867
|
*/
|
|
874
868
|
system?: string | null;
|
|
875
869
|
|
|
@@ -911,8 +905,7 @@ export interface AgentUpdateParams {
|
|
|
911
905
|
version: number;
|
|
912
906
|
|
|
913
907
|
/**
|
|
914
|
-
* Body param: Description.
|
|
915
|
-
* string or null to clear.
|
|
908
|
+
* Body param: Description. Omit to preserve; send empty string or null to clear.
|
|
916
909
|
*/
|
|
917
910
|
description?: string | null;
|
|
918
911
|
|
|
@@ -945,20 +938,19 @@ export interface AgentUpdateParams {
|
|
|
945
938
|
multiagent?: SessionsAPI.BetaManagedAgentsMultiagentParams | null;
|
|
946
939
|
|
|
947
940
|
/**
|
|
948
|
-
* Body param: Human-readable name.
|
|
941
|
+
* Body param: Human-readable name. Must be non-empty. Omit to preserve. Cannot be
|
|
949
942
|
* cleared.
|
|
950
943
|
*/
|
|
951
944
|
name?: string;
|
|
952
945
|
|
|
953
946
|
/**
|
|
954
947
|
* Body param: Skills. Full replacement. Omit to preserve; send empty array or null
|
|
955
|
-
* to clear.
|
|
948
|
+
* to clear.
|
|
956
949
|
*/
|
|
957
950
|
skills?: Array<BetaManagedAgentsSkillParams> | null;
|
|
958
951
|
|
|
959
952
|
/**
|
|
960
|
-
* Body param: System prompt.
|
|
961
|
-
* empty string or null to clear.
|
|
953
|
+
* Body param: System prompt. Omit to preserve; send empty string or null to clear.
|
|
962
954
|
*/
|
|
963
955
|
system?: string | null;
|
|
964
956
|
|
|
@@ -239,6 +239,12 @@ import {
|
|
|
239
239
|
BetaDocumentBlock,
|
|
240
240
|
BetaEncryptedCodeExecutionResultBlock,
|
|
241
241
|
BetaEncryptedCodeExecutionResultBlockParam,
|
|
242
|
+
BetaFallbackBlock,
|
|
243
|
+
BetaFallbackBlockParam,
|
|
244
|
+
BetaFallbackInfo,
|
|
245
|
+
BetaFallbackInfoParam,
|
|
246
|
+
BetaFallbackMessageIterationUsage,
|
|
247
|
+
BetaFallbackParam,
|
|
242
248
|
BetaFileDocumentSource,
|
|
243
249
|
BetaFileImageSource,
|
|
244
250
|
BetaImageBlockParam,
|
|
@@ -472,7 +478,9 @@ export type AnthropicBeta =
|
|
|
472
478
|
| 'advisor-tool-2026-03-01'
|
|
473
479
|
| 'managed-agents-2026-04-01'
|
|
474
480
|
| 'cache-diagnosis-2026-04-07'
|
|
475
|
-
| 'thinking-token-count-2026-05-13'
|
|
481
|
+
| 'thinking-token-count-2026-05-13'
|
|
482
|
+
| 'server-side-fallback-2026-06-01'
|
|
483
|
+
| 'fallback-credit-2026-06-01';
|
|
476
484
|
|
|
477
485
|
export interface BetaAPIError {
|
|
478
486
|
message: string;
|
|
@@ -673,6 +681,12 @@ export declare namespace Beta {
|
|
|
673
681
|
type BetaDocumentBlock as BetaDocumentBlock,
|
|
674
682
|
type BetaEncryptedCodeExecutionResultBlock as BetaEncryptedCodeExecutionResultBlock,
|
|
675
683
|
type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
|
|
684
|
+
type BetaFallbackBlock as BetaFallbackBlock,
|
|
685
|
+
type BetaFallbackBlockParam as BetaFallbackBlockParam,
|
|
686
|
+
type BetaFallbackInfo as BetaFallbackInfo,
|
|
687
|
+
type BetaFallbackInfoParam as BetaFallbackInfoParam,
|
|
688
|
+
type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
|
|
689
|
+
type BetaFallbackParam as BetaFallbackParam,
|
|
676
690
|
type BetaFileDocumentSource as BetaFileDocumentSource,
|
|
677
691
|
type BetaFileImageSource as BetaFileImageSource,
|
|
678
692
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
@@ -192,6 +192,12 @@ export {
|
|
|
192
192
|
type BetaDocumentBlock,
|
|
193
193
|
type BetaEncryptedCodeExecutionResultBlock,
|
|
194
194
|
type BetaEncryptedCodeExecutionResultBlockParam,
|
|
195
|
+
type BetaFallbackBlock,
|
|
196
|
+
type BetaFallbackBlockParam,
|
|
197
|
+
type BetaFallbackInfo,
|
|
198
|
+
type BetaFallbackInfoParam,
|
|
199
|
+
type BetaFallbackMessageIterationUsage,
|
|
200
|
+
type BetaFallbackParam,
|
|
195
201
|
type BetaFileDocumentSource,
|
|
196
202
|
type BetaFileImageSource,
|
|
197
203
|
type BetaImageBlockParam,
|
|
@@ -570,6 +570,36 @@ export namespace BatchCreateParams {
|
|
|
570
570
|
*/
|
|
571
571
|
diagnostics?: BetaMessagesAPI.BetaDiagnosticsParam | null;
|
|
572
572
|
|
|
573
|
+
/**
|
|
574
|
+
* The `fallback_credit_token` from a prior refusal's `stop_details`.
|
|
575
|
+
*
|
|
576
|
+
* When a preceding request was refused and returned a `fallback_credit_token`,
|
|
577
|
+
* pass that code here on the retry to have the retry's cache-creation tokens for
|
|
578
|
+
* the prefix that was warm on the refused model billed at the cache-read rate.
|
|
579
|
+
* Must be redeemed by the same organization and workspace, with the same request
|
|
580
|
+
* body (optionally extended by one appended `assistant` message whose content is
|
|
581
|
+
* the partial text — with any trailing whitespace stripped from the final text
|
|
582
|
+
* block — and paired server-tool blocks streamed before the refusal; the
|
|
583
|
+
* appended-assistant form is not available for requests with `output_format` set
|
|
584
|
+
* or forced `tool_choice`), on an eligible fallback model, on the same platform,
|
|
585
|
+
* and within 5 minutes of the refusal; a mismatch is a 400. A token minted
|
|
586
|
+
* mid-server-tool-loop whose partial content was continuable may only be redeemed
|
|
587
|
+
* with the appended-assistant form — if an exact-body retry is rejected with a 400
|
|
588
|
+
* saying the token must be redeemed by continuing the partial response, retry with
|
|
589
|
+
* the appended-assistant form instead.
|
|
590
|
+
*
|
|
591
|
+
* When the appended-assistant form is used on a model that otherwise disallows
|
|
592
|
+
* assistant-turn prefill, this token also authorizes that one prefill.
|
|
593
|
+
*/
|
|
594
|
+
fallback_credit_token?: string | null;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Opt-in server-side retry on one or more substitute models when the requested
|
|
598
|
+
* model declines for policy reasons. Tried in order: if the first entry also
|
|
599
|
+
* declines, the second is tried, and so on.
|
|
600
|
+
*/
|
|
601
|
+
fallbacks?: Array<BetaMessagesAPI.BetaFallbackParam> | null;
|
|
602
|
+
|
|
573
603
|
/**
|
|
574
604
|
* Specifies the geographic region for inference processing. If not specified, the
|
|
575
605
|
* workspace's `default_inference_geo` is used.
|
|
@@ -103,6 +103,12 @@ export {
|
|
|
103
103
|
type BetaDocumentBlock,
|
|
104
104
|
type BetaEncryptedCodeExecutionResultBlock,
|
|
105
105
|
type BetaEncryptedCodeExecutionResultBlockParam,
|
|
106
|
+
type BetaFallbackBlock,
|
|
107
|
+
type BetaFallbackBlockParam,
|
|
108
|
+
type BetaFallbackInfo,
|
|
109
|
+
type BetaFallbackInfoParam,
|
|
110
|
+
type BetaFallbackMessageIterationUsage,
|
|
111
|
+
type BetaFallbackParam,
|
|
106
112
|
type BetaFileDocumentSource,
|
|
107
113
|
type BetaFileImageSource,
|
|
108
114
|
type BetaImageBlockParam,
|
|
@@ -60,8 +60,15 @@ const DEPRECATED_MODELS: {
|
|
|
60
60
|
'claude-2.0': 'July 21st, 2025',
|
|
61
61
|
'claude-3-7-sonnet-latest': 'February 19th, 2026',
|
|
62
62
|
'claude-3-7-sonnet-20250219': 'February 19th, 2026',
|
|
63
|
+
'claude-3-5-haiku-latest': 'February 19th, 2026',
|
|
64
|
+
'claude-3-5-haiku-20241022': 'February 19th, 2026',
|
|
65
|
+
'claude-opus-4-0': 'June 15th, 2026',
|
|
66
|
+
'claude-opus-4-20250514': 'June 15th, 2026',
|
|
67
|
+
'claude-sonnet-4-0': 'June 15th, 2026',
|
|
68
|
+
'claude-sonnet-4-20250514': 'June 15th, 2026',
|
|
63
69
|
'claude-opus-4-1': 'August 5th, 2026',
|
|
64
70
|
'claude-opus-4-1-20250805': 'August 5th, 2026',
|
|
71
|
+
'claude-mythos-preview': 'June 30th, 2026',
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
const MODELS_TO_WARN_WITH_THINKING_ENABLED: Model[] = ['claude-mythos-preview', 'claude-opus-4-6'];
|
|
@@ -395,6 +402,17 @@ export interface BetaAdvisorTool20260301 {
|
|
|
395
402
|
*/
|
|
396
403
|
defer_loading?: boolean;
|
|
397
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Bounds the advisor's total output (thinking + text) per call. When the advisor
|
|
407
|
+
* hits this cap, the returned advisor_result or advisor_redacted_result block
|
|
408
|
+
* carries stop_reason='max_tokens', and a truncation note is appended to the
|
|
409
|
+
* advice text the worker model sees (inside the encrypted blob in redacted mode).
|
|
410
|
+
* When set, the server also emits a remaining-tokens budget block in the advisor's
|
|
411
|
+
* prompt so the advisor self-shapes toward the cap. When omitted, the advisor
|
|
412
|
+
* model's default output cap applies and no budget block is emitted.
|
|
413
|
+
*/
|
|
414
|
+
max_tokens?: number | null;
|
|
415
|
+
|
|
398
416
|
/**
|
|
399
417
|
* Maximum number of times the tool can be used in the API request.
|
|
400
418
|
*/
|
|
@@ -437,7 +455,8 @@ export interface BetaAdvisorToolResultError {
|
|
|
437
455
|
| 'too_many_requests'
|
|
438
456
|
| 'overloaded'
|
|
439
457
|
| 'unavailable'
|
|
440
|
-
| 'execution_time_exceeded'
|
|
458
|
+
| 'execution_time_exceeded'
|
|
459
|
+
| 'model_not_found';
|
|
441
460
|
|
|
442
461
|
type: 'advisor_tool_result_error';
|
|
443
462
|
}
|
|
@@ -449,7 +468,8 @@ export interface BetaAdvisorToolResultErrorParam {
|
|
|
449
468
|
| 'too_many_requests'
|
|
450
469
|
| 'overloaded'
|
|
451
470
|
| 'unavailable'
|
|
452
|
-
| 'execution_time_exceeded'
|
|
471
|
+
| 'execution_time_exceeded'
|
|
472
|
+
| 'model_not_found';
|
|
453
473
|
|
|
454
474
|
type: 'advisor_tool_result_error';
|
|
455
475
|
}
|
|
@@ -1343,7 +1363,8 @@ export type BetaContentBlock =
|
|
|
1343
1363
|
| BetaMCPToolUseBlock
|
|
1344
1364
|
| BetaMCPToolResultBlock
|
|
1345
1365
|
| BetaContainerUploadBlock
|
|
1346
|
-
| BetaCompactionBlock
|
|
1366
|
+
| BetaCompactionBlock
|
|
1367
|
+
| BetaFallbackBlock;
|
|
1347
1368
|
|
|
1348
1369
|
/**
|
|
1349
1370
|
* Regular text content.
|
|
@@ -1369,7 +1390,8 @@ export type BetaContentBlockParam =
|
|
|
1369
1390
|
| BetaRequestMCPToolResultBlockParam
|
|
1370
1391
|
| BetaContainerUploadBlockParam
|
|
1371
1392
|
| BetaCompactionBlockParam
|
|
1372
|
-
| BetaMidConversationSystemBlockParam
|
|
1393
|
+
| BetaMidConversationSystemBlockParam
|
|
1394
|
+
| BetaFallbackBlockParam;
|
|
1373
1395
|
|
|
1374
1396
|
export interface BetaContentBlockSource {
|
|
1375
1397
|
content: string | Array<BetaContentBlockSourceContent>;
|
|
@@ -1489,6 +1511,170 @@ export interface BetaEncryptedCodeExecutionResultBlockParam {
|
|
|
1489
1511
|
type: 'encrypted_code_execution_result';
|
|
1490
1512
|
}
|
|
1491
1513
|
|
|
1514
|
+
/**
|
|
1515
|
+
* Marks the point in `content` where one model's output gives way to the next.
|
|
1516
|
+
*
|
|
1517
|
+
* One block appears per hop where a preceding model actually ran this turn and
|
|
1518
|
+
* declined. A turn routed directly by the sticky decision has no such boundary and
|
|
1519
|
+
* carries no block — the signal for whether a fallback model served the response
|
|
1520
|
+
* is the presence of a `fallback_message` entry in `usage.iterations`, not this
|
|
1521
|
+
* block.
|
|
1522
|
+
*
|
|
1523
|
+
* The block is treated like a server-tool content block for streaming: it arrives
|
|
1524
|
+
* via the standard `content_block_start` / `content_block_stop` pair and carries
|
|
1525
|
+
* no deltas.
|
|
1526
|
+
*/
|
|
1527
|
+
export interface BetaFallbackBlock {
|
|
1528
|
+
/**
|
|
1529
|
+
* The model whose output ends at this point — the model that declined at this hop.
|
|
1530
|
+
* When the declining hop is the requested model, its `model` echoes the top-level
|
|
1531
|
+
* `model` string the caller sent (alias or canonical); when the declining hop is a
|
|
1532
|
+
* fallback model, its `model` is that model's canonical id.
|
|
1533
|
+
*/
|
|
1534
|
+
from: BetaFallbackInfo;
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* The fallback model producing the content that follows this block. Its `model` is
|
|
1538
|
+
* always the canonical id.
|
|
1539
|
+
*/
|
|
1540
|
+
to: BetaFallbackInfo;
|
|
1541
|
+
|
|
1542
|
+
type: 'fallback';
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* A `fallback` block echoed back from a prior response.
|
|
1547
|
+
*
|
|
1548
|
+
* Accepted in `messages[].content` and never rendered into the prompt, not
|
|
1549
|
+
* validated against the request's `fallbacks` chain or top-level `model`, and
|
|
1550
|
+
* stripped before the sticky-routing cache key is computed.
|
|
1551
|
+
*
|
|
1552
|
+
* Callers should echo the assistant turn verbatim — block included. The block's
|
|
1553
|
+
* position is load-bearing for thinking verification: the thinking runs on either
|
|
1554
|
+
* side of a fallback hop carry independently-rooted verification hash chains, and
|
|
1555
|
+
* this block is the only record of where one chain ends and the next begins. When
|
|
1556
|
+
* thinking runs flank the boundary, omitting the block merges the runs into one
|
|
1557
|
+
* contiguous span whose hashes cannot verify (the request is rejected), and moving
|
|
1558
|
+
* it into the middle of a single run splits that run's chain and is likewise
|
|
1559
|
+
* rejected; between non-thinking blocks the block's placement has no verification
|
|
1560
|
+
* effect.
|
|
1561
|
+
*/
|
|
1562
|
+
export interface BetaFallbackBlockParam {
|
|
1563
|
+
/**
|
|
1564
|
+
* Identifies one hop of a fallback transition.
|
|
1565
|
+
*/
|
|
1566
|
+
from: BetaFallbackInfoParam;
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* Identifies one hop of a fallback transition.
|
|
1570
|
+
*/
|
|
1571
|
+
to: BetaFallbackInfoParam;
|
|
1572
|
+
|
|
1573
|
+
type: 'fallback';
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Identifies one hop of a fallback transition.
|
|
1578
|
+
*/
|
|
1579
|
+
export interface BetaFallbackInfo {
|
|
1580
|
+
/**
|
|
1581
|
+
* The model that will complete your prompt.
|
|
1582
|
+
*
|
|
1583
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
1584
|
+
* details and options.
|
|
1585
|
+
*/
|
|
1586
|
+
model: MessagesAPI.Model;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/**
|
|
1590
|
+
* Identifies one hop of a fallback transition.
|
|
1591
|
+
*/
|
|
1592
|
+
export interface BetaFallbackInfoParam {
|
|
1593
|
+
/**
|
|
1594
|
+
* The model that will complete your prompt.
|
|
1595
|
+
*
|
|
1596
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
1597
|
+
* details and options.
|
|
1598
|
+
*/
|
|
1599
|
+
model: MessagesAPI.Model;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Token usage for the fallback-model attempt of a server-side fallback request.
|
|
1604
|
+
*
|
|
1605
|
+
* Produced in place of a `message` entry for whichever hop served the response. A
|
|
1606
|
+
* declined hop produces the existing `message` entry. Whether a fallback model
|
|
1607
|
+
* served the response is signalled by the presence of this entry in
|
|
1608
|
+
* `usage.iterations`.
|
|
1609
|
+
*/
|
|
1610
|
+
export interface BetaFallbackMessageIterationUsage {
|
|
1611
|
+
/**
|
|
1612
|
+
* Breakdown of cached tokens by TTL
|
|
1613
|
+
*/
|
|
1614
|
+
cache_creation: BetaCacheCreation | null;
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* The number of input tokens used to create the cache entry.
|
|
1618
|
+
*/
|
|
1619
|
+
cache_creation_input_tokens: number;
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* The number of input tokens read from the cache.
|
|
1623
|
+
*/
|
|
1624
|
+
cache_read_input_tokens: number;
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* The number of input tokens which were used.
|
|
1628
|
+
*/
|
|
1629
|
+
input_tokens: number;
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* The model that will complete your prompt.
|
|
1633
|
+
*
|
|
1634
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
1635
|
+
* details and options.
|
|
1636
|
+
*/
|
|
1637
|
+
model: MessagesAPI.Model;
|
|
1638
|
+
|
|
1639
|
+
/**
|
|
1640
|
+
* The number of output tokens which were used.
|
|
1641
|
+
*/
|
|
1642
|
+
output_tokens: number;
|
|
1643
|
+
|
|
1644
|
+
/**
|
|
1645
|
+
* Usage for the fallback-model attempt that served the response
|
|
1646
|
+
*/
|
|
1647
|
+
type: 'fallback_message';
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
/**
|
|
1651
|
+
* One entry in the `fallbacks` chain on a `/v1/messages` request.
|
|
1652
|
+
*
|
|
1653
|
+
* `model` is required. The four override fields (`max_tokens`, `thinking`,
|
|
1654
|
+
* `output_config`, and `speed`) replace the corresponding top-level field for this
|
|
1655
|
+
* attempt only and are validated as if the request were made to `model`. Any other
|
|
1656
|
+
* key is rejected at parse time.
|
|
1657
|
+
*/
|
|
1658
|
+
export interface BetaFallbackParam {
|
|
1659
|
+
/**
|
|
1660
|
+
* The model that will complete your prompt.
|
|
1661
|
+
*
|
|
1662
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
1663
|
+
* details and options.
|
|
1664
|
+
*/
|
|
1665
|
+
model: MessagesAPI.Model;
|
|
1666
|
+
|
|
1667
|
+
max_tokens?: number | null;
|
|
1668
|
+
|
|
1669
|
+
output_config?: BetaOutputConfig | null;
|
|
1670
|
+
|
|
1671
|
+
speed?: 'standard' | 'fast' | null;
|
|
1672
|
+
|
|
1673
|
+
thinking?: BetaThinkingConfigEnabled | BetaThinkingConfigDisabled | BetaThinkingConfigAdaptive | null;
|
|
1674
|
+
|
|
1675
|
+
[k: string]: unknown;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1492
1678
|
export interface BetaFileDocumentSource {
|
|
1493
1679
|
file_id: string;
|
|
1494
1680
|
|
|
@@ -1541,7 +1727,10 @@ export interface BetaInputTokensTrigger {
|
|
|
1541
1727
|
* - Understand token accumulation across server-side tool use loops
|
|
1542
1728
|
*/
|
|
1543
1729
|
export type BetaIterationsUsage = Array<
|
|
1544
|
-
|
|
1730
|
+
| BetaMessageIterationUsage
|
|
1731
|
+
| BetaCompactionIterationUsage
|
|
1732
|
+
| BetaAdvisorMessageIterationUsage
|
|
1733
|
+
| BetaFallbackMessageIterationUsage
|
|
1545
1734
|
>;
|
|
1546
1735
|
|
|
1547
1736
|
export interface BetaJSONOutputFormat {
|
|
@@ -2005,6 +2194,14 @@ export interface BetaMessageIterationUsage {
|
|
|
2005
2194
|
*/
|
|
2006
2195
|
input_tokens: number;
|
|
2007
2196
|
|
|
2197
|
+
/**
|
|
2198
|
+
* The model that will complete your prompt.
|
|
2199
|
+
*
|
|
2200
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
2201
|
+
* details and options.
|
|
2202
|
+
*/
|
|
2203
|
+
model: MessagesAPI.Model;
|
|
2204
|
+
|
|
2008
2205
|
/**
|
|
2009
2206
|
* The number of output tokens which were used.
|
|
2010
2207
|
*/
|
|
@@ -2143,7 +2340,8 @@ export interface BetaRawContentBlockStartEvent {
|
|
|
2143
2340
|
| BetaMCPToolUseBlock
|
|
2144
2341
|
| BetaMCPToolResultBlock
|
|
2145
2342
|
| BetaContainerUploadBlock
|
|
2146
|
-
| BetaCompactionBlock
|
|
2343
|
+
| BetaCompactionBlock
|
|
2344
|
+
| BetaFallbackBlock;
|
|
2147
2345
|
|
|
2148
2346
|
index: number;
|
|
2149
2347
|
|
|
@@ -2244,7 +2442,7 @@ export interface BetaRefusalStopDetails {
|
|
|
2244
2442
|
*
|
|
2245
2443
|
* `null` when the refusal doesn't map to a named category.
|
|
2246
2444
|
*/
|
|
2247
|
-
category: 'cyber' | 'bio' | null;
|
|
2445
|
+
category: 'cyber' | 'bio' | 'reasoning_extraction' | null;
|
|
2248
2446
|
|
|
2249
2447
|
/**
|
|
2250
2448
|
* Human-readable explanation of the refusal.
|
|
@@ -2254,6 +2452,59 @@ export interface BetaRefusalStopDetails {
|
|
|
2254
2452
|
*/
|
|
2255
2453
|
explanation: string | null;
|
|
2256
2454
|
|
|
2455
|
+
/**
|
|
2456
|
+
* Opaque code that refunds the cache-miss cost when retrying this refused request
|
|
2457
|
+
* on the fallback model. Pass it as `fallback_credit_token` on the retry request.
|
|
2458
|
+
* Expires 5 minutes after the refusal.
|
|
2459
|
+
*
|
|
2460
|
+
* The retry is sent either with the same request body (`system`, `messages`,
|
|
2461
|
+
* `tools`, and other render-shaping fields), or with the same body plus one
|
|
2462
|
+
* appended `assistant` message whose content is the partial text (with any
|
|
2463
|
+
* trailing whitespace stripped from the final text block) and paired server-tool
|
|
2464
|
+
* blocks from this refusal — which also authorizes that appended turn as an
|
|
2465
|
+
* assistant-prefill continuation on models that otherwise disallow prefill. A
|
|
2466
|
+
* token minted mid-server-tool-loop whose partial content was continuable may only
|
|
2467
|
+
* be redeemed the second way — if a same-body retry is rejected with a 400 saying
|
|
2468
|
+
* the token must be redeemed by continuing the partial response, retry the second
|
|
2469
|
+
* way instead. Either way: same workspace, same platform; a mismatch is a 400.
|
|
2470
|
+
* Resending a token for an already-warm prefix is permitted but yields no
|
|
2471
|
+
* additional credit.
|
|
2472
|
+
*
|
|
2473
|
+
* `null` when the refused model isn't eligible for a fallback credit.
|
|
2474
|
+
*/
|
|
2475
|
+
fallback_credit_token: string | null;
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* Whether the accompanying `fallback_credit_token` may be redeemed with the
|
|
2479
|
+
* appended-assistant retry form. Only set when `fallback_credit_token` is present.
|
|
2480
|
+
*
|
|
2481
|
+
* `true`: retry by resending the same request body plus one appended `assistant`
|
|
2482
|
+
* message whose content is this response's `content` with any trailing whitespace
|
|
2483
|
+
* stripped from the final text block and unpaired `tool_use` blocks omitted (the
|
|
2484
|
+
* same appended-turn shape described on `fallback_credit_token`), with the token
|
|
2485
|
+
* attached. `false`: retry by resending the original request body unchanged, with
|
|
2486
|
+
* the token attached — the appended-assistant form is not available for this
|
|
2487
|
+
* refusal (no continuable partial content, or the request uses `output_format` or
|
|
2488
|
+
* a `tool_choice` that forces tool use). One exception: when the request used
|
|
2489
|
+
* `output_format` or a forced `tool_choice` and the refusal arrived after server
|
|
2490
|
+
* tools (including MCP connector tools) had already executed, the token may not be
|
|
2491
|
+
* redeemable by either retry form; if the exact-body retry is then rejected with a
|
|
2492
|
+
* 400 saying the token must be redeemed by continuing the partial response,
|
|
2493
|
+
* discard the token and retry without it.
|
|
2494
|
+
*
|
|
2495
|
+
* Advisory: if an appended-assistant retry is rejected with a 400 despite `true`,
|
|
2496
|
+
* fall back to resending the original request body with the token.
|
|
2497
|
+
*/
|
|
2498
|
+
fallback_has_prefill_claim: boolean | null;
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* The server's suggested retry target for this refusal. Populated when a fallback
|
|
2502
|
+
* attempt could not be made (the fallback model's rate limit was exhausted, or it
|
|
2503
|
+
* was overloaded); names the fallback model the caller can retry directly. Null
|
|
2504
|
+
* otherwise.
|
|
2505
|
+
*/
|
|
2506
|
+
recommended_model: string | null;
|
|
2507
|
+
|
|
2257
2508
|
type: 'refusal';
|
|
2258
2509
|
}
|
|
2259
2510
|
|
|
@@ -3230,6 +3481,8 @@ export interface BetaToolSearchToolResultErrorParam {
|
|
|
3230
3481
|
error_code: 'invalid_tool_input' | 'unavailable' | 'too_many_requests' | 'execution_time_exceeded';
|
|
3231
3482
|
|
|
3232
3483
|
type: 'tool_search_tool_result_error';
|
|
3484
|
+
|
|
3485
|
+
error_message?: string | null;
|
|
3233
3486
|
}
|
|
3234
3487
|
|
|
3235
3488
|
export interface BetaToolSearchToolSearchResultBlock {
|
|
@@ -4135,6 +4388,36 @@ export interface MessageCreateParamsBase {
|
|
|
4135
4388
|
*/
|
|
4136
4389
|
diagnostics?: BetaDiagnosticsParam | null;
|
|
4137
4390
|
|
|
4391
|
+
/**
|
|
4392
|
+
* Body param: The `fallback_credit_token` from a prior refusal's `stop_details`.
|
|
4393
|
+
*
|
|
4394
|
+
* When a preceding request was refused and returned a `fallback_credit_token`,
|
|
4395
|
+
* pass that code here on the retry to have the retry's cache-creation tokens for
|
|
4396
|
+
* the prefix that was warm on the refused model billed at the cache-read rate.
|
|
4397
|
+
* Must be redeemed by the same organization and workspace, with the same request
|
|
4398
|
+
* body (optionally extended by one appended `assistant` message whose content is
|
|
4399
|
+
* the partial text — with any trailing whitespace stripped from the final text
|
|
4400
|
+
* block — and paired server-tool blocks streamed before the refusal; the
|
|
4401
|
+
* appended-assistant form is not available for requests with `output_format` set
|
|
4402
|
+
* or forced `tool_choice`), on an eligible fallback model, on the same platform,
|
|
4403
|
+
* and within 5 minutes of the refusal; a mismatch is a 400. A token minted
|
|
4404
|
+
* mid-server-tool-loop whose partial content was continuable may only be redeemed
|
|
4405
|
+
* with the appended-assistant form — if an exact-body retry is rejected with a 400
|
|
4406
|
+
* saying the token must be redeemed by continuing the partial response, retry with
|
|
4407
|
+
* the appended-assistant form instead.
|
|
4408
|
+
*
|
|
4409
|
+
* When the appended-assistant form is used on a model that otherwise disallows
|
|
4410
|
+
* assistant-turn prefill, this token also authorizes that one prefill.
|
|
4411
|
+
*/
|
|
4412
|
+
fallback_credit_token?: string | null;
|
|
4413
|
+
|
|
4414
|
+
/**
|
|
4415
|
+
* Body param: Opt-in server-side retry on one or more substitute models when the
|
|
4416
|
+
* requested model declines for policy reasons. Tried in order: if the first entry
|
|
4417
|
+
* also declines, the second is tried, and so on.
|
|
4418
|
+
*/
|
|
4419
|
+
fallbacks?: Array<BetaFallbackParam> | null;
|
|
4420
|
+
|
|
4138
4421
|
/**
|
|
4139
4422
|
* Body param: Specifies the geographic region for inference processing. If not
|
|
4140
4423
|
* specified, the workspace's `default_inference_geo` is used.
|
|
@@ -4713,6 +4996,12 @@ export declare namespace Messages {
|
|
|
4713
4996
|
type BetaDocumentBlock as BetaDocumentBlock,
|
|
4714
4997
|
type BetaEncryptedCodeExecutionResultBlock as BetaEncryptedCodeExecutionResultBlock,
|
|
4715
4998
|
type BetaEncryptedCodeExecutionResultBlockParam as BetaEncryptedCodeExecutionResultBlockParam,
|
|
4999
|
+
type BetaFallbackBlock as BetaFallbackBlock,
|
|
5000
|
+
type BetaFallbackBlockParam as BetaFallbackBlockParam,
|
|
5001
|
+
type BetaFallbackInfo as BetaFallbackInfo,
|
|
5002
|
+
type BetaFallbackInfoParam as BetaFallbackInfoParam,
|
|
5003
|
+
type BetaFallbackMessageIterationUsage as BetaFallbackMessageIterationUsage,
|
|
5004
|
+
type BetaFallbackParam as BetaFallbackParam,
|
|
4716
5005
|
type BetaFileDocumentSource as BetaFileDocumentSource,
|
|
4717
5006
|
type BetaFileImageSource as BetaFileImageSource,
|
|
4718
5007
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
@@ -195,6 +195,13 @@ export interface BetaModelInfo {
|
|
|
195
195
|
*/
|
|
196
196
|
id: string;
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Model IDs this model accepts as `fallbacks[i].model` on the Messages API. An
|
|
200
|
+
* empty list means the `fallbacks` parameter is not supported for this model as
|
|
201
|
+
* primary.
|
|
202
|
+
*/
|
|
203
|
+
allowed_fallback_models: Array<string> | null;
|
|
204
|
+
|
|
198
205
|
/**
|
|
199
206
|
* Model capability information.
|
|
200
207
|
*/
|