Skip to content

Commit d1b8d04

Browse files
feat(api): Add support for cache diagnostics beta
1 parent 8e43bf8 commit d1b8d04

11 files changed

Lines changed: 162 additions & 4 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 97
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-885805e62515d6587390efa80438fb10269cb8bf7c4b73ee8043afbdc6010319.yml
3-
openapi_spec_hash: 2f3ce77b23ff5b6365e2258fb2b29ad2
4-
config_hash: 5f6ee0e4e7983e97121e1d40fd0eecda
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-9bc52c052beb11ccfff68e9d96335774c8377f914bcf36278e5774c68aa84e69.yml
3+
openapi_spec_hash: 3a5f6e11b9fda1c165c6f9edbdee7d90
4+
config_hash: ed200254fa6776c7b124706c91c80475

api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ Types:
296296
- <code><a href="./src/resources/beta/messages/messages.ts">BetaBashCodeExecutionToolResultErrorParam</a></code>
297297
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheControlEphemeral</a></code>
298298
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheCreation</a></code>
299+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissMessagesChanged</a></code>
300+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissModelChanged</a></code>
301+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissPreviousMessageNotFound</a></code>
302+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissSystemChanged</a></code>
303+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissToolsChanged</a></code>
304+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCacheMissUnavailable</a></code>
299305
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCitationCharLocation</a></code>
300306
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCitationCharLocationParam</a></code>
301307
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCitationConfig</a></code>
@@ -343,6 +349,8 @@ Types:
343349
- <code><a href="./src/resources/beta/messages/messages.ts">BetaContextManagementConfig</a></code>
344350
- <code><a href="./src/resources/beta/messages/messages.ts">BetaContextManagementResponse</a></code>
345351
- <code><a href="./src/resources/beta/messages/messages.ts">BetaCountTokensContextManagementResponse</a></code>
352+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaDiagnostics</a></code>
353+
- <code><a href="./src/resources/beta/messages/messages.ts">BetaDiagnosticsParam</a></code>
346354
- <code><a href="./src/resources/beta/messages/messages.ts">BetaDirectCaller</a></code>
347355
- <code><a href="./src/resources/beta/messages/messages.ts">BetaDocumentBlock</a></code>
348356
- <code><a href="./src/resources/beta/messages/messages.ts">BetaEncryptedCodeExecutionResultBlock</a></code>

src/resources/beta/beta.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ import {
171171
BetaBashCodeExecutionToolResultErrorParam,
172172
BetaCacheControlEphemeral,
173173
BetaCacheCreation,
174+
BetaCacheMissMessagesChanged,
175+
BetaCacheMissModelChanged,
176+
BetaCacheMissPreviousMessageNotFound,
177+
BetaCacheMissSystemChanged,
178+
BetaCacheMissToolsChanged,
179+
BetaCacheMissUnavailable,
174180
BetaCitationCharLocation,
175181
BetaCitationCharLocationParam,
176182
BetaCitationConfig,
@@ -218,6 +224,8 @@ import {
218224
BetaContextManagementConfig,
219225
BetaContextManagementResponse,
220226
BetaCountTokensContextManagementResponse,
227+
BetaDiagnostics,
228+
BetaDiagnosticsParam,
221229
BetaDirectCaller,
222230
BetaDocumentBlock,
223231
BetaEncryptedCodeExecutionResultBlock,
@@ -448,7 +456,8 @@ export type AnthropicBeta =
448456
| 'output-300k-2026-03-24'
449457
| 'user-profiles-2026-03-24'
450458
| 'advisor-tool-2026-03-01'
451-
| 'managed-agents-2026-04-01';
459+
| 'managed-agents-2026-04-01'
460+
| 'cache-diagnosis-2026-04-07';
452461

453462
export interface BetaAPIError {
454463
message: string;
@@ -590,6 +599,12 @@ export declare namespace Beta {
590599
type BetaBashCodeExecutionToolResultErrorParam as BetaBashCodeExecutionToolResultErrorParam,
591600
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
592601
type BetaCacheCreation as BetaCacheCreation,
602+
type BetaCacheMissMessagesChanged as BetaCacheMissMessagesChanged,
603+
type BetaCacheMissModelChanged as BetaCacheMissModelChanged,
604+
type BetaCacheMissPreviousMessageNotFound as BetaCacheMissPreviousMessageNotFound,
605+
type BetaCacheMissSystemChanged as BetaCacheMissSystemChanged,
606+
type BetaCacheMissToolsChanged as BetaCacheMissToolsChanged,
607+
type BetaCacheMissUnavailable as BetaCacheMissUnavailable,
593608
type BetaCitationCharLocation as BetaCitationCharLocation,
594609
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
595610
type BetaCitationConfig as BetaCitationConfig,
@@ -637,6 +652,8 @@ export declare namespace Beta {
637652
type BetaContextManagementConfig as BetaContextManagementConfig,
638653
type BetaContextManagementResponse as BetaContextManagementResponse,
639654
type BetaCountTokensContextManagementResponse as BetaCountTokensContextManagementResponse,
655+
type BetaDiagnostics as BetaDiagnostics,
656+
type BetaDiagnosticsParam as BetaDiagnosticsParam,
640657
type BetaDirectCaller as BetaDirectCaller,
641658
type BetaDocumentBlock as BetaDocumentBlock,
642659
type BetaEncryptedCodeExecutionResultBlock as BetaEncryptedCodeExecutionResultBlock,

src/resources/beta/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ export {
124124
type BetaBashCodeExecutionToolResultErrorParam,
125125
type BetaCacheControlEphemeral,
126126
type BetaCacheCreation,
127+
type BetaCacheMissMessagesChanged,
128+
type BetaCacheMissModelChanged,
129+
type BetaCacheMissPreviousMessageNotFound,
130+
type BetaCacheMissSystemChanged,
131+
type BetaCacheMissToolsChanged,
132+
type BetaCacheMissUnavailable,
127133
type BetaCitationCharLocation,
128134
type BetaCitationCharLocationParam,
129135
type BetaCitationConfig,
@@ -171,6 +177,8 @@ export {
171177
type BetaContextManagementConfig,
172178
type BetaContextManagementResponse,
173179
type BetaCountTokensContextManagementResponse,
180+
type BetaDiagnostics,
181+
type BetaDiagnosticsParam,
174182
type BetaDirectCaller,
175183
type BetaDocumentBlock,
176184
type BetaEncryptedCodeExecutionResultBlock,

src/resources/beta/messages/batches.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ export namespace BatchCreateParams {
563563
*/
564564
context_management?: BetaMessagesAPI.BetaContextManagementConfig | null;
565565

566+
/**
567+
* Request-level diagnostics. Currently carries the previous response id for
568+
* prompt-cache divergence reporting.
569+
*/
570+
diagnostics?: BetaMessagesAPI.BetaDiagnosticsParam | null;
571+
566572
/**
567573
* Specifies the geographic region for inference processing. If not specified, the
568574
* workspace's `default_inference_geo` is used.

src/resources/beta/messages/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export {
4444
type BetaBashCodeExecutionToolResultErrorParam,
4545
type BetaCacheControlEphemeral,
4646
type BetaCacheCreation,
47+
type BetaCacheMissMessagesChanged,
48+
type BetaCacheMissModelChanged,
49+
type BetaCacheMissPreviousMessageNotFound,
50+
type BetaCacheMissSystemChanged,
51+
type BetaCacheMissToolsChanged,
52+
type BetaCacheMissUnavailable,
4753
type BetaCitationCharLocation,
4854
type BetaCitationCharLocationParam,
4955
type BetaCitationConfig,
@@ -91,6 +97,8 @@ export {
9197
type BetaContextManagementConfig,
9298
type BetaContextManagementResponse,
9399
type BetaCountTokensContextManagementResponse,
100+
type BetaDiagnostics,
101+
type BetaDiagnosticsParam,
94102
type BetaDirectCaller,
95103
type BetaDocumentBlock,
96104
type BetaEncryptedCodeExecutionResultBlock,

src/resources/beta/messages/messages.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,54 @@ export interface BetaCacheCreation {
562562
ephemeral_5m_input_tokens: number;
563563
}
564564

565+
export interface BetaCacheMissMessagesChanged {
566+
/**
567+
* Approximate number of input tokens that would have been read from cache had the
568+
* prefix matched the previous request.
569+
*/
570+
cache_missed_input_tokens: number;
571+
572+
type: 'messages_changed';
573+
}
574+
575+
export interface BetaCacheMissModelChanged {
576+
/**
577+
* Approximate number of input tokens that would have been read from cache had the
578+
* prefix matched the previous request.
579+
*/
580+
cache_missed_input_tokens: number;
581+
582+
type: 'model_changed';
583+
}
584+
585+
export interface BetaCacheMissPreviousMessageNotFound {
586+
type: 'previous_message_not_found';
587+
}
588+
589+
export interface BetaCacheMissSystemChanged {
590+
/**
591+
* Approximate number of input tokens that would have been read from cache had the
592+
* prefix matched the previous request.
593+
*/
594+
cache_missed_input_tokens: number;
595+
596+
type: 'system_changed';
597+
}
598+
599+
export interface BetaCacheMissToolsChanged {
600+
/**
601+
* Approximate number of input tokens that would have been read from cache had the
602+
* prefix matched the previous request.
603+
*/
604+
cache_missed_input_tokens: number;
605+
606+
type: 'tools_changed';
607+
}
608+
609+
export interface BetaCacheMissUnavailable {
610+
type: 'unavailable';
611+
}
612+
565613
export interface BetaCitationCharLocation {
566614
cited_text: string;
567615

@@ -1330,6 +1378,42 @@ export interface BetaCountTokensContextManagementResponse {
13301378
original_input_tokens: number;
13311379
}
13321380

1381+
/**
1382+
* Response envelope for request-level diagnostics. Present (possibly null)
1383+
* whenever the caller supplied `diagnostics` on the request.
1384+
*/
1385+
export interface BetaDiagnostics {
1386+
/**
1387+
* Explains why the prompt cache could not fully reuse the prefix from the request
1388+
* identified by `diagnostics.previous_message_id`. `null` means diagnosis is still
1389+
* pending — the response was serialized before the background comparison
1390+
* completed.
1391+
*/
1392+
cache_miss_reason:
1393+
| BetaCacheMissModelChanged
1394+
| BetaCacheMissSystemChanged
1395+
| BetaCacheMissToolsChanged
1396+
| BetaCacheMissMessagesChanged
1397+
| BetaCacheMissPreviousMessageNotFound
1398+
| BetaCacheMissUnavailable
1399+
| null;
1400+
}
1401+
1402+
/**
1403+
* Request-level diagnostics. Currently carries the previous response id for
1404+
* prompt-cache divergence reporting.
1405+
*/
1406+
export interface BetaDiagnosticsParam {
1407+
/**
1408+
* The `id` (`msg_...`) from this client's previous /v1/messages response. The
1409+
* server compares that request's prompt fingerprint against this one and returns
1410+
* `diagnostics.cache_miss_reason` when the prompt-cache prefix could not be
1411+
* reused. Pass `null` on the first turn to opt in without a prior message to
1412+
* compare.
1413+
*/
1414+
previous_message_id?: string | null;
1415+
}
1416+
13331417
/**
13341418
* Tool invocation directly from the model.
13351419
*/
@@ -1746,6 +1830,12 @@ export interface BetaMessage {
17461830
*/
17471831
context_management: BetaContextManagementResponse | null;
17481832

1833+
/**
1834+
* Response envelope for request-level diagnostics. Present (possibly null)
1835+
* whenever the caller supplied `diagnostics` on the request.
1836+
*/
1837+
diagnostics: BetaDiagnostics | null;
1838+
17491839
/**
17501840
* The model that will complete your prompt.\n\nSee
17511841
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -3947,6 +4037,12 @@ export interface MessageCreateParamsBase {
39474037
*/
39484038
context_management?: BetaContextManagementConfig | null;
39494039

4040+
/**
4041+
* Body param: Request-level diagnostics. Currently carries the previous response
4042+
* id for prompt-cache divergence reporting.
4043+
*/
4044+
diagnostics?: BetaDiagnosticsParam | null;
4045+
39504046
/**
39514047
* Body param: Specifies the geographic region for inference processing. If not
39524048
* specified, the workspace's `default_inference_geo` is used.
@@ -4465,6 +4561,12 @@ export declare namespace Messages {
44654561
type BetaBashCodeExecutionToolResultErrorParam as BetaBashCodeExecutionToolResultErrorParam,
44664562
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
44674563
type BetaCacheCreation as BetaCacheCreation,
4564+
type BetaCacheMissMessagesChanged as BetaCacheMissMessagesChanged,
4565+
type BetaCacheMissModelChanged as BetaCacheMissModelChanged,
4566+
type BetaCacheMissPreviousMessageNotFound as BetaCacheMissPreviousMessageNotFound,
4567+
type BetaCacheMissSystemChanged as BetaCacheMissSystemChanged,
4568+
type BetaCacheMissToolsChanged as BetaCacheMissToolsChanged,
4569+
type BetaCacheMissUnavailable as BetaCacheMissUnavailable,
44684570
type BetaCitationCharLocation as BetaCitationCharLocation,
44694571
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
44704572
type BetaCitationConfig as BetaCitationConfig,
@@ -4512,6 +4614,8 @@ export declare namespace Messages {
45124614
type BetaContextManagementConfig as BetaContextManagementConfig,
45134615
type BetaContextManagementResponse as BetaContextManagementResponse,
45144616
type BetaCountTokensContextManagementResponse as BetaCountTokensContextManagementResponse,
4617+
type BetaDiagnostics as BetaDiagnostics,
4618+
type BetaDiagnosticsParam as BetaDiagnosticsParam,
45154619
type BetaDirectCaller as BetaDirectCaller,
45164620
type BetaDocumentBlock as BetaDocumentBlock,
45174621
type BetaEncryptedCodeExecutionResultBlock as BetaEncryptedCodeExecutionResultBlock,

tests/api-resources/beta/messages/batches.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('resource batches', () => {
6363
},
6464
],
6565
},
66+
diagnostics: { previous_message_id: 'previous_message_id' },
6667
inference_geo: 'inference_geo',
6768
mcp_servers: [
6869
{

tests/api-resources/beta/messages/messages.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('resource messages', () => {
5151
},
5252
],
5353
},
54+
diagnostics: { previous_message_id: 'previous_message_id' },
5455
inference_geo: 'inference_geo',
5556
mcp_servers: [
5657
{

tests/lib/parser.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('Beta Parser', () => {
7575
},
7676
],
7777
context_management: null,
78+
diagnostics: null,
7879
stop_details: null,
7980
stop_reason: 'end_turn',
8081
stop_sequence: null,
@@ -253,6 +254,7 @@ describe('Beta Parser', () => {
253254
},
254255
],
255256
context_management: null,
257+
diagnostics: null,
256258
stop_details: null,
257259
stop_reason: 'end_turn',
258260
stop_sequence: null,

0 commit comments

Comments
 (0)