@@ -941,6 +941,118 @@ func (r *BetaCacheCreation) UnmarshalJSON(data []byte) error {
941941 return apijson .UnmarshalRoot (data , r )
942942}
943943
944+ type BetaCacheMissMessagesChanged struct {
945+ // Approximate number of input tokens that would have been read from cache had the
946+ // prefix matched the previous request.
947+ CacheMissedInputTokens int64 `json:"cache_missed_input_tokens" api:"required"`
948+ Type constant.MessagesChanged `json:"type" default:"messages_changed"`
949+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
950+ JSON struct {
951+ CacheMissedInputTokens respjson.Field
952+ Type respjson.Field
953+ ExtraFields map [string ]respjson.Field
954+ raw string
955+ } `json:"-"`
956+ }
957+
958+ // Returns the unmodified JSON received from the API
959+ func (r BetaCacheMissMessagesChanged ) RawJSON () string { return r .JSON .raw }
960+ func (r * BetaCacheMissMessagesChanged ) UnmarshalJSON (data []byte ) error {
961+ return apijson .UnmarshalRoot (data , r )
962+ }
963+
964+ type BetaCacheMissModelChanged struct {
965+ // Approximate number of input tokens that would have been read from cache had the
966+ // prefix matched the previous request.
967+ CacheMissedInputTokens int64 `json:"cache_missed_input_tokens" api:"required"`
968+ Type constant.ModelChanged `json:"type" default:"model_changed"`
969+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
970+ JSON struct {
971+ CacheMissedInputTokens respjson.Field
972+ Type respjson.Field
973+ ExtraFields map [string ]respjson.Field
974+ raw string
975+ } `json:"-"`
976+ }
977+
978+ // Returns the unmodified JSON received from the API
979+ func (r BetaCacheMissModelChanged ) RawJSON () string { return r .JSON .raw }
980+ func (r * BetaCacheMissModelChanged ) UnmarshalJSON (data []byte ) error {
981+ return apijson .UnmarshalRoot (data , r )
982+ }
983+
984+ type BetaCacheMissPreviousMessageNotFound struct {
985+ Type constant.PreviousMessageNotFound `json:"type" default:"previous_message_not_found"`
986+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
987+ JSON struct {
988+ Type respjson.Field
989+ ExtraFields map [string ]respjson.Field
990+ raw string
991+ } `json:"-"`
992+ }
993+
994+ // Returns the unmodified JSON received from the API
995+ func (r BetaCacheMissPreviousMessageNotFound ) RawJSON () string { return r .JSON .raw }
996+ func (r * BetaCacheMissPreviousMessageNotFound ) UnmarshalJSON (data []byte ) error {
997+ return apijson .UnmarshalRoot (data , r )
998+ }
999+
1000+ type BetaCacheMissSystemChanged struct {
1001+ // Approximate number of input tokens that would have been read from cache had the
1002+ // prefix matched the previous request.
1003+ CacheMissedInputTokens int64 `json:"cache_missed_input_tokens" api:"required"`
1004+ Type constant.SystemChanged `json:"type" default:"system_changed"`
1005+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1006+ JSON struct {
1007+ CacheMissedInputTokens respjson.Field
1008+ Type respjson.Field
1009+ ExtraFields map [string ]respjson.Field
1010+ raw string
1011+ } `json:"-"`
1012+ }
1013+
1014+ // Returns the unmodified JSON received from the API
1015+ func (r BetaCacheMissSystemChanged ) RawJSON () string { return r .JSON .raw }
1016+ func (r * BetaCacheMissSystemChanged ) UnmarshalJSON (data []byte ) error {
1017+ return apijson .UnmarshalRoot (data , r )
1018+ }
1019+
1020+ type BetaCacheMissToolsChanged struct {
1021+ // Approximate number of input tokens that would have been read from cache had the
1022+ // prefix matched the previous request.
1023+ CacheMissedInputTokens int64 `json:"cache_missed_input_tokens" api:"required"`
1024+ Type constant.ToolsChanged `json:"type" default:"tools_changed"`
1025+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1026+ JSON struct {
1027+ CacheMissedInputTokens respjson.Field
1028+ Type respjson.Field
1029+ ExtraFields map [string ]respjson.Field
1030+ raw string
1031+ } `json:"-"`
1032+ }
1033+
1034+ // Returns the unmodified JSON received from the API
1035+ func (r BetaCacheMissToolsChanged ) RawJSON () string { return r .JSON .raw }
1036+ func (r * BetaCacheMissToolsChanged ) UnmarshalJSON (data []byte ) error {
1037+ return apijson .UnmarshalRoot (data , r )
1038+ }
1039+
1040+ type BetaCacheMissUnavailable struct {
1041+ Type constant.Unavailable `json:"type" default:"unavailable"`
1042+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1043+ JSON struct {
1044+ Type respjson.Field
1045+ ExtraFields map [string ]respjson.Field
1046+ raw string
1047+ } `json:"-"`
1048+ }
1049+
1050+ // Returns the unmodified JSON received from the API
1051+ func (r BetaCacheMissUnavailable ) RawJSON () string { return r .JSON .raw }
1052+ func (r * BetaCacheMissUnavailable ) UnmarshalJSON (data []byte ) error {
1053+ return apijson .UnmarshalRoot (data , r )
1054+ }
1055+
9441056type BetaCitationCharLocation struct {
9451057 CitedText string `json:"cited_text" api:"required"`
9461058 DocumentIndex int64 `json:"document_index" api:"required"`
@@ -4080,6 +4192,150 @@ func (r *BetaCountTokensContextManagementResponse) UnmarshalJSON(data []byte) er
40804192 return apijson .UnmarshalRoot (data , r )
40814193}
40824194
4195+ // Response envelope for request-level diagnostics. Present (possibly null)
4196+ // whenever the caller supplied `diagnostics` on the request.
4197+ type BetaDiagnostics struct {
4198+ // Explains why the prompt cache could not fully reuse the prefix from the request
4199+ // identified by `diagnostics.previous_message_id`. `null` means diagnosis is still
4200+ // pending — the response was serialized before the background comparison
4201+ // completed.
4202+ CacheMissReason BetaDiagnosticsCacheMissReasonUnion `json:"cache_miss_reason" api:"required"`
4203+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
4204+ JSON struct {
4205+ CacheMissReason respjson.Field
4206+ ExtraFields map [string ]respjson.Field
4207+ raw string
4208+ } `json:"-"`
4209+ }
4210+
4211+ // Returns the unmodified JSON received from the API
4212+ func (r BetaDiagnostics ) RawJSON () string { return r .JSON .raw }
4213+ func (r * BetaDiagnostics ) UnmarshalJSON (data []byte ) error {
4214+ return apijson .UnmarshalRoot (data , r )
4215+ }
4216+
4217+ // BetaDiagnosticsCacheMissReasonUnion contains all possible properties and values
4218+ // from [BetaCacheMissModelChanged], [BetaCacheMissSystemChanged],
4219+ // [BetaCacheMissToolsChanged], [BetaCacheMissMessagesChanged],
4220+ // [BetaCacheMissPreviousMessageNotFound], [BetaCacheMissUnavailable].
4221+ //
4222+ // Use the [BetaDiagnosticsCacheMissReasonUnion.AsAny] method to switch on the
4223+ // variant.
4224+ //
4225+ // Use the methods beginning with 'As' to cast the union to one of its variants.
4226+ type BetaDiagnosticsCacheMissReasonUnion struct {
4227+ CacheMissedInputTokens int64 `json:"cache_missed_input_tokens"`
4228+ // Any of "model_changed", "system_changed", "tools_changed", "messages_changed",
4229+ // "previous_message_not_found", "unavailable".
4230+ Type string `json:"type"`
4231+ JSON struct {
4232+ CacheMissedInputTokens respjson.Field
4233+ Type respjson.Field
4234+ raw string
4235+ } `json:"-"`
4236+ }
4237+
4238+ // anyBetaDiagnosticsCacheMissReason is implemented by each variant of
4239+ // [BetaDiagnosticsCacheMissReasonUnion] to add type safety for the return type of
4240+ // [BetaDiagnosticsCacheMissReasonUnion.AsAny]
4241+ type anyBetaDiagnosticsCacheMissReason interface {
4242+ implBetaDiagnosticsCacheMissReasonUnion ()
4243+ }
4244+
4245+ func (BetaCacheMissModelChanged ) implBetaDiagnosticsCacheMissReasonUnion () {}
4246+ func (BetaCacheMissSystemChanged ) implBetaDiagnosticsCacheMissReasonUnion () {}
4247+ func (BetaCacheMissToolsChanged ) implBetaDiagnosticsCacheMissReasonUnion () {}
4248+ func (BetaCacheMissMessagesChanged ) implBetaDiagnosticsCacheMissReasonUnion () {}
4249+ func (BetaCacheMissPreviousMessageNotFound ) implBetaDiagnosticsCacheMissReasonUnion () {}
4250+ func (BetaCacheMissUnavailable ) implBetaDiagnosticsCacheMissReasonUnion () {}
4251+
4252+ // Use the following switch statement to find the correct variant
4253+ //
4254+ // switch variant := BetaDiagnosticsCacheMissReasonUnion.AsAny().(type) {
4255+ // case anthropic.BetaCacheMissModelChanged:
4256+ // case anthropic.BetaCacheMissSystemChanged:
4257+ // case anthropic.BetaCacheMissToolsChanged:
4258+ // case anthropic.BetaCacheMissMessagesChanged:
4259+ // case anthropic.BetaCacheMissPreviousMessageNotFound:
4260+ // case anthropic.BetaCacheMissUnavailable:
4261+ // default:
4262+ // fmt.Errorf("no variant present")
4263+ // }
4264+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsAny () anyBetaDiagnosticsCacheMissReason {
4265+ switch u .Type {
4266+ case "model_changed" :
4267+ return u .AsModelChanged ()
4268+ case "system_changed" :
4269+ return u .AsSystemChanged ()
4270+ case "tools_changed" :
4271+ return u .AsToolsChanged ()
4272+ case "messages_changed" :
4273+ return u .AsMessagesChanged ()
4274+ case "previous_message_not_found" :
4275+ return u .AsPreviousMessageNotFound ()
4276+ case "unavailable" :
4277+ return u .AsUnavailable ()
4278+ }
4279+ return nil
4280+ }
4281+
4282+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsModelChanged () (v BetaCacheMissModelChanged ) {
4283+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4284+ return
4285+ }
4286+
4287+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsSystemChanged () (v BetaCacheMissSystemChanged ) {
4288+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4289+ return
4290+ }
4291+
4292+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsToolsChanged () (v BetaCacheMissToolsChanged ) {
4293+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4294+ return
4295+ }
4296+
4297+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsMessagesChanged () (v BetaCacheMissMessagesChanged ) {
4298+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4299+ return
4300+ }
4301+
4302+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsPreviousMessageNotFound () (v BetaCacheMissPreviousMessageNotFound ) {
4303+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4304+ return
4305+ }
4306+
4307+ func (u BetaDiagnosticsCacheMissReasonUnion ) AsUnavailable () (v BetaCacheMissUnavailable ) {
4308+ apijson .UnmarshalRoot (json .RawMessage (u .JSON .raw ), & v )
4309+ return
4310+ }
4311+
4312+ // Returns the unmodified JSON received from the API
4313+ func (u BetaDiagnosticsCacheMissReasonUnion ) RawJSON () string { return u .JSON .raw }
4314+
4315+ func (r * BetaDiagnosticsCacheMissReasonUnion ) UnmarshalJSON (data []byte ) error {
4316+ return apijson .UnmarshalRoot (data , r )
4317+ }
4318+
4319+ // Request-level diagnostics. Currently carries the previous response id for
4320+ // prompt-cache divergence reporting.
4321+ type BetaDiagnosticsParam struct {
4322+ // The `id` (`msg_...`) from this client's previous /v1/messages response. The
4323+ // server compares that request's prompt fingerprint against this one and returns
4324+ // `diagnostics.cache_miss_reason` when the prompt-cache prefix could not be
4325+ // reused. Pass `null` on the first turn to opt in without a prior message to
4326+ // compare.
4327+ PreviousMessageID param.Opt [string ] `json:"previous_message_id,omitzero"`
4328+ paramObj
4329+ }
4330+
4331+ func (r BetaDiagnosticsParam ) MarshalJSON () (data []byte , err error ) {
4332+ type shadow BetaDiagnosticsParam
4333+ return param .MarshalObject (r , (* shadow )(& r ))
4334+ }
4335+ func (r * BetaDiagnosticsParam ) UnmarshalJSON (data []byte ) error {
4336+ return apijson .UnmarshalRoot (data , r )
4337+ }
4338+
40834339// Tool invocation directly from the model.
40844340type BetaDirectCaller struct {
40854341 Type constant.Direct `json:"type" default:"direct"`
@@ -5095,6 +5351,9 @@ type BetaMessage struct {
50955351 //
50965352 // Information about context management strategies applied during the request.
50975353 ContextManagement BetaContextManagementResponse `json:"context_management" api:"required"`
5354+ // Response envelope for request-level diagnostics. Present (possibly null)
5355+ // whenever the caller supplied `diagnostics` on the request.
5356+ Diagnostics BetaDiagnostics `json:"diagnostics" api:"required"`
50985357 // The model that will complete your prompt.\n\nSee
50995358 // [models](https://docs.anthropic.com/en/docs/models-overview) for additional
51005359 // details and options.
@@ -5155,6 +5414,7 @@ type BetaMessage struct {
51555414 Container respjson.Field
51565415 Content respjson.Field
51575416 ContextManagement respjson.Field
5417+ Diagnostics respjson.Field
51585418 Model respjson.Field
51595419 Role respjson.Field
51605420 StopDetails respjson.Field
@@ -11420,6 +11680,9 @@ type BetaMessageNewParams struct {
1142011680 // This allows you to control how Claude manages context across multiple requests,
1142111681 // such as whether to clear function results or not.
1142211682 ContextManagement BetaContextManagementConfigParam `json:"context_management,omitzero"`
11683+ // Request-level diagnostics. Currently carries the previous response id for
11684+ // prompt-cache divergence reporting.
11685+ Diagnostics BetaDiagnosticsParam `json:"diagnostics,omitzero"`
1142311686 // MCP servers to be utilized in this request
1142411687 MCPServers []BetaRequestMCPServerURLDefinitionParam `json:"mcp_servers,omitzero"`
1142511688 // An object describing metadata about the request.
0 commit comments