Class BetaMessageDeltaUsage

    • Constructor Detail

    • Method Detail

      • fallbackCredit

         final Optional<BetaFallbackCreditUsage> fallbackCredit()

        Outcome of the fallback_credit_token presented on this request.

        Present on every response to a non-batch request that carried a fallback_credit_token, in either redemption mode; absent otherwise (batch items accept and ignore the token and carry no outcome object).

      • iterations

         final Optional<List<BetaMessageDeltaUsage.Iteration>> iterations()

        Per-iteration token usage breakdown.

        Each entry represents one sampling iteration, with its own input/output token counts and cache statistics, discriminated by type. For message entries (model sampling iterations, such as the turns of a server-side tool use loop), this allows you to:

        • Calculate the context window size from the last message entry

        • Understand token accumulation across server-side tool use loops

        A compaction entry reports the token usage of the compaction operation itself — the server-side request that summarizes the context being closed — NOT the size of the context that was compacted away, and its token counts can be much smaller than that closed context (for example, a compaction that closes a ~200k-token context can report only a few thousand tokens). Do not derive the context window size from a compaction entry, even when it is the last entry. A compaction entry's tokens are not included in the top-level usage fields. When an input-token trigger is in effect (the default — 150,000 tokens unless configured otherwise), each compaction entry closes a context that had reached at least that threshold, though the context can exceed it by the final iteration's output and tool results.

      • outputTokens

         final Long outputTokens()

        The cumulative number of output tokens which were used.

      • outputTokensDetails

         final Optional<BetaOutputTokensDetails> outputTokensDetails()

        Breakdown of output tokens by category.

        output_tokens remains the inclusive, authoritative total used for billing. This object provides a read-only decomposition for observability — for example, how many of the billed output tokens were spent on internal reasoning that may have been summarized before being returned to you.

      • _cacheCreationInputTokens

         final JsonField<Long> _cacheCreationInputTokens()

        Returns the raw JSON value of cacheCreationInputTokens.

        Unlike cacheCreationInputTokens, this method doesn't throw if the JSON field has an unexpected type.

      • _cacheReadInputTokens

         final JsonField<Long> _cacheReadInputTokens()

        Returns the raw JSON value of cacheReadInputTokens.

        Unlike cacheReadInputTokens, this method doesn't throw if the JSON field has an unexpected type.

      • _inputTokens

         final JsonField<Long> _inputTokens()

        Returns the raw JSON value of inputTokens.

        Unlike inputTokens, this method doesn't throw if the JSON field has an unexpected type.

      • _outputTokens

         final JsonField<Long> _outputTokens()

        Returns the raw JSON value of outputTokens.

        Unlike outputTokens, this method doesn't throw if the JSON field has an unexpected type.

      • validate

         final BetaMessageDeltaUsage validate()

        Validates that the types of all values in this object match their expected types recursively.

        This method is not forwards compatible with new types from the API for existing fields.

      • builder

         final static BetaMessageDeltaUsage.Builder builder()

        Returns a mutable builder for constructing an instance of BetaMessageDeltaUsage.

        The following fields are required:

        .cacheCreationInputTokens()
        .cacheReadInputTokens()
        .fallbackCredit()
        .inputTokens()
        .iterations()
        .outputTokens()
        .outputTokensDetails()
        .serverToolUse()