Usage
Sub classes¶
| Name | Children | Inherits |
|---|---|---|
| ClaudeUsage clawd_code_sdk.storage.models Token usage from Claude API response, with additional storage fields. |
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| BaseModel pydantic.main !!! abstract "Usage Documentation" |
â‹” Inheritance diagram¶
graph TD
2143730855["usage.Usage"]
3879467795["main.BaseModel"]
2751680898["builtins.object"]
3879467795 --> 2143730855
2751680898 --> 3879467795
🛈 DocStrings¶
Bases: BaseModel
Token usage counters.
Used both for per-turn snapshots (on ResultMessage) and as an accumulator (on ClaudeSDKClient.query_usage / session_usage).
Source code in src/clawd_code_sdk/models/usage.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
cache_creation
class-attribute
instance-attribute
¶
cache_creation: CacheCreationUsage | None = None
Cache-write tokens split by TTL.
cache_creation_input_tokens
class-attribute
instance-attribute
¶
The number of input tokens used to create the cache entry.
cache_read_input_tokens
class-attribute
instance-attribute
¶
The number of input tokens read from the cache.
fallback_credit
class-attribute
instance-attribute
¶
Fallback credit info (may be null).
inference_geo
class-attribute
instance-attribute
¶
Inference geography (e.g. "global").
input_tokens
class-attribute
instance-attribute
¶
The number of input tokens which were used.
iterations
class-attribute
instance-attribute
¶
iterations: list[UsageIteration] | None = None
Per-iteration usage for the turn.
output_tokens
class-attribute
instance-attribute
¶
The number of output tokens which were used.
output_tokens_details
class-attribute
instance-attribute
¶
output_tokens_details: OutputTokensDetails | None = None
Breakdown of output tokens.
server_tool_use
class-attribute
instance-attribute
¶
server_tool_use: AgentServerToolUse | None = None
Server-side tool usage counters.
service_tier
class-attribute
instance-attribute
¶
Service tier the request was served on (e.g. "standard").
speed
class-attribute
instance-attribute
¶
Speed mode (e.g. "standard", "fast").
accumulate
¶
accumulate(usage: Usage) -> None
Add another Usage's values to this one.
Source code in src/clawd_code_sdk/models/usage.py
reset
¶
to_otel
¶
Extract usage metrics from a Claude usage object or dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
usage
|
A usage object or dict from the SDK. |
required | |
partial
|
bool
|
If True, prefix attribute names with |
False
|