Debian Codegraph @

src/anthropic/types/beta/beta_usage.py

raw
1 from typing import Optional
2 from typing_extensions import Literal
3
4 from ..._models import BaseModel
5 from .beta_cache_creation import BetaCacheCreation
6 from .beta_iterations_usage import BetaIterationsUsage
7 from .beta_server_tool_usage import BetaServerToolUsage
8 from .beta_fallback_credit_usage import BetaFallbackCreditUsage
9 from .beta_output_tokens_details import BetaOutputTokensDetails
10
11 __all__ = ["BetaUsage"]
12
13
14 class BetaUsage(BaseModel):
15 cache_creation: Optional[BetaCacheCreation] = None
16 """Breakdown of cached tokens by TTL"""
17
18 cache_creation_input_tokens: Optional[int] = None
19 """The number of input tokens used to create the cache entry."""
20
21 cache_read_input_tokens: Optional[int] = None
22 """The number of input tokens read from the cache."""
23
24 fallback_credit: Optional[BetaFallbackCreditUsage] = None
25 """Outcome of the `fallback_credit_token` presented on this request.
26
27 Present on every response to a non-batch request that carried a
28 `fallback_credit_token`, in either redemption mode; absent otherwise (batch
29 items accept and ignore the token and carry no outcome object).
30 """
31
32 inference_geo: Optional[str] = None
33 """The geographic region where inference was performed for this request."""
34
35 input_tokens: int
36 """The number of input tokens which were used."""
37
38 iterations: Optional[BetaIterationsUsage] = None
39 """Per-iteration token usage breakdown.
40
41 Each entry represents one sampling iteration, with its own input/output token
42 counts and cache statistics, discriminated by `type`. For `message` entries
43 (model sampling iterations, such as the turns of a server-side tool use loop),
44 this allows you to:
45
46 - Determine which iterations exceeded long context thresholds (>=200k tokens)
47 - Calculate the context window size from the last `message` entry
48 - Understand token accumulation across server-side tool use loops
49
50 A `compaction` entry reports the token usage of the compaction operation itself
51 — the server-side request that summarizes the context being closed — NOT the
52 size of the context that was compacted away, and its token counts can be much
53 smaller than that closed context (for example, a compaction that closes a
54 ~200k-token context can report only a few thousand tokens). Do not derive the
55 context window size from a `compaction` entry, even when it is the last entry. A
56 `compaction` entry's tokens are not included in the top-level `usage` fields.
57 When an input-token trigger is in effect (the default — 150,000 tokens unless
58 configured otherwise), each `compaction` entry closes a context that had reached
59 at least that threshold, though the context can exceed it by the final
60 iteration's output and tool results.
61 """
62
63 output_tokens: int
64 """The number of output tokens which were used."""
65
66 output_tokens_details: Optional[BetaOutputTokensDetails] = None
67 """Breakdown of output tokens by category.
68
69 `output_tokens` remains the inclusive, authoritative total used for billing.
70 This object provides a read-only decomposition for observability — for example,
71 how many of the billed output tokens were spent on internal reasoning that may
72 have been summarized before being returned to you.
73 """
74
75 server_tool_use: Optional[BetaServerToolUsage] = None
76 """The number of server tool requests."""
77
78 service_tier: Optional[Literal["standard", "priority", "batch"]] = None
79 """If the request used the priority, standard, or batch tier."""
80
81 speed: Optional[Literal["standard", "fast"]] = None
82 """The inference speed mode used for this request."""