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 inference_geo: Optional[str] = None
28 """The geographic region where inference was performed for this request."""
29
30 input_tokens: int
31 """The number of input tokens which were used."""
32
33 iterations: Optional[BetaIterationsUsage] = None
34 """Per-iteration token usage breakdown.
35
36 Each entry represents one sampling iteration, with its own input/output token
37 counts and cache statistics, discriminated by `type`. For `message` entries
38 (model sampling iterations, such as the turns of a server-side tool use loop),
39 this allows you to:
40
41 - Determine which iterations exceeded long context thresholds (>=200k tokens)
42 - Calculate the context window size from the last `message` entry
43 - Understand token accumulation across server-side tool use loops
44
45 A `compaction` entry reports the token usage of the compaction operation itself
46 — the server-side request that summarizes the context being closed — NOT the
47 size of the context that was compacted away, and its token counts can be much
48 smaller than that closed context (for example, a compaction that closes a
49 ~200k-token context can report only a few thousand tokens). Do not derive the
50 context window size from a `compaction` entry, even when it is the last entry. A
51 `compaction` entry's tokens are not included in the top-level `usage` fields.
52 When an input-token trigger is in effect (the default — 150,000 tokens unless
53 configured otherwise), each `compaction` entry closes a context that had reached
54 at least that threshold, though the context can exceed it by the final
55 iteration's output and tool results.
56 """
57
58 output_tokens: int
59 """The number of output tokens which were used."""
60
61 output_tokens_details: Optional[BetaOutputTokensDetails] = None
62 """Breakdown of output tokens by category.
63
64 `output_tokens` remains the inclusive, authoritative total used for billing.
65 This object provides a read-only decomposition for observability — for example,
66 how many of the billed output tokens were spent on internal reasoning that may
67 have been summarized before being returned to you.
68 """
69
70 server_tool_use: Optional[BetaServerToolUsage] = None
71 """The number of server tool requests."""
72
73 service_tier: Optional[Literal["standard", "priority", "batch"]] = None
74 """If the request used the priority, standard, or batch tier."""
75
76 speed: Optional[Literal["standard", "fast"]] = None
77 """Inference speed mode.
78
79 `fast` provides significantly faster output token generation at premium pricing.
80 Not all models support `fast`; invalid combinations are rejected at create time.
81 """