Skip to content

Commit dedeb6d

Browse files
feat(api): Add support for thinking-token-count beta for estimated tokens in thinking block deltas when streaming
1 parent d138190 commit dedeb6d

3 files changed

Lines changed: 26 additions & 9 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: 106
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-56896df83861385b03a49bdf36623a811f5dedd599fdacf5680c73f9e73e1546.yml
3-
openapi_spec_hash: e1812c6c53a1029d12b5d83ca50f4b78
4-
config_hash: 45b88a8e434814b9e6f4258be5804047
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-945e3a57b7a6fa5974baf70845ebafdb25f185625f6e2fab98dc034e44d14a5a.yml
3+
openapi_spec_hash: e7c214b4d3bd33e1ca39451a8727897c
4+
config_hash: 4cc78a8eca8090f65d574c5f03a0ba0a

beta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const (
8080
AnthropicBetaAdvisorTool2026_03_01 AnthropicBeta = "advisor-tool-2026-03-01"
8181
AnthropicBetaManagedAgents2026_04_01 AnthropicBeta = "managed-agents-2026-04-01"
8282
AnthropicBetaCacheDiagnosis2026_04_07 AnthropicBeta = "cache-diagnosis-2026-04-07"
83+
AnthropicBetaThinkingTokenCount2026_05_13 AnthropicBeta = "thinking-token-count-2026-05-13"
8384
)
8485

8586
type BetaAPIError struct {

betamessage.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5665,6 +5665,8 @@ type BetaRawContentBlockDeltaUnion struct {
56655665
// This field is from variant [BetaCitationsDelta].
56665666
Citation BetaCitationsDeltaCitationUnion `json:"citation"`
56675667
// This field is from variant [BetaThinkingDelta].
5668+
EstimatedTokens int64 `json:"estimated_tokens"`
5669+
// This field is from variant [BetaThinkingDelta].
56685670
Thinking string `json:"thinking"`
56695671
// This field is from variant [BetaSignatureDelta].
56705672
Signature string `json:"signature"`
@@ -5677,6 +5679,7 @@ type BetaRawContentBlockDeltaUnion struct {
56775679
Type respjson.Field
56785680
PartialJSON respjson.Field
56795681
Citation respjson.Field
5682+
EstimatedTokens respjson.Field
56805683
Thinking respjson.Field
56815684
Signature respjson.Field
56825685
Content respjson.Field
@@ -6479,6 +6482,8 @@ type BetaRawMessageStreamEventUnionDelta struct {
64796482
// This field is from variant [BetaRawContentBlockDeltaUnion].
64806483
Citation BetaCitationsDeltaCitationUnion `json:"citation"`
64816484
// This field is from variant [BetaRawContentBlockDeltaUnion].
6485+
EstimatedTokens int64 `json:"estimated_tokens"`
6486+
// This field is from variant [BetaRawContentBlockDeltaUnion].
64826487
Thinking string `json:"thinking"`
64836488
// This field is from variant [BetaRawContentBlockDeltaUnion].
64846489
Signature string `json:"signature"`
@@ -6495,6 +6500,7 @@ type BetaRawMessageStreamEventUnionDelta struct {
64956500
Type respjson.Field
64966501
PartialJSON respjson.Field
64976502
Citation respjson.Field
6503+
EstimatedTokens respjson.Field
64986504
Thinking respjson.Field
64996505
Signature respjson.Field
65006506
Content respjson.Field
@@ -8305,14 +8311,24 @@ func init() {
83058311
}
83068312

83078313
type BetaThinkingDelta struct {
8308-
Thinking string `json:"thinking" api:"required"`
8309-
Type constant.ThinkingDelta `json:"type" default:"thinking_delta"`
8314+
// Per-frame increment of a coarse, running estimate of the tokens this thinking
8315+
// block has produced so far. Present whenever the
8316+
// `thinking-token-count-2026-05-13` beta is set; `null` unless `thinking.display`
8317+
// resolves to `"omitted"` and a count is due this frame. Sum the increments across
8318+
// `thinking_delta` frames on this block for a progress indicator. Each increment
8319+
// is a non-negative multiple of a fixed quantum and the cadence is rate-limited,
8320+
// so this is a deliberately lossy display hint, not a billable count;
8321+
// `usage.output_tokens` remains authoritative.
8322+
EstimatedTokens int64 `json:"estimated_tokens" api:"required"`
8323+
Thinking string `json:"thinking" api:"required"`
8324+
Type constant.ThinkingDelta `json:"type" default:"thinking_delta"`
83108325
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
83118326
JSON struct {
8312-
Thinking respjson.Field
8313-
Type respjson.Field
8314-
ExtraFields map[string]respjson.Field
8315-
raw string
8327+
EstimatedTokens respjson.Field
8328+
Thinking respjson.Field
8329+
Type respjson.Field
8330+
ExtraFields map[string]respjson.Field
8331+
raw string
83168332
} `json:"-"`
83178333
}
83188334

0 commit comments

Comments
 (0)