Accumulated session usage metrics, including premium request cost, token counts, model breakdown, and code-change totals.
| 19111 | # Experimental: this type is part of an experimental API and may change or be removed. |
| 19112 | @dataclass |
| 19113 | class UsageGetMetricsResult: |
| 19114 | """Accumulated session usage metrics, including premium request cost, token counts, model |
| 19115 | breakdown, and code-change totals. |
| 19116 | """ |
| 19117 | code_changes: UsageMetricsCodeChanges |
| 19118 | """Aggregated code change metrics""" |
| 19119 | |
| 19120 | last_call_input_tokens: int |
| 19121 | """Input tokens from the most recent main-agent API call""" |
| 19122 | |
| 19123 | last_call_output_tokens: int |
| 19124 | """Output tokens from the most recent main-agent API call""" |
| 19125 | |
| 19126 | model_metrics: dict[str, UsageMetricsModelMetric] |
| 19127 | """Per-model token and request metrics, keyed by model identifier""" |
| 19128 | |
| 19129 | session_start_time: datetime |
| 19130 | """ISO 8601 timestamp when the session started""" |
| 19131 | |
| 19132 | total_api_duration_ms: int |
| 19133 | """Total time spent in model API calls (milliseconds)""" |
| 19134 | |
| 19135 | total_premium_request_cost: float |
| 19136 | """Total user-initiated premium request cost across all models (may be fractional due to |
| 19137 | multipliers) |
| 19138 | """ |
| 19139 | total_user_requests: int |
| 19140 | """Raw count of user-initiated API requests""" |
| 19141 | |
| 19142 | current_model: str | None = None |
| 19143 | """Currently active model identifier""" |
| 19144 | |
| 19145 | token_details: dict[str, UsageMetricsTokenDetail] | None = None |
| 19146 | """Session-wide per-token-type accumulated token counts""" |
| 19147 | |
| 19148 | total_nano_aiu: float | None = None |
| 19149 | """Session-wide accumulated nano-AI units cost""" |
| 19150 | |
| 19151 | @staticmethod |
| 19152 | def from_dict(obj: Any) -> 'UsageGetMetricsResult': |
| 19153 | assert isinstance(obj, dict) |
| 19154 | code_changes = UsageMetricsCodeChanges.from_dict(obj.get("codeChanges")) |
| 19155 | last_call_input_tokens = from_int(obj.get("lastCallInputTokens")) |
| 19156 | last_call_output_tokens = from_int(obj.get("lastCallOutputTokens")) |
| 19157 | model_metrics = from_dict(UsageMetricsModelMetric.from_dict, obj.get("modelMetrics")) |
| 19158 | session_start_time = from_datetime(obj.get("sessionStartTime")) |
| 19159 | total_api_duration_ms = from_int(obj.get("totalApiDurationMs")) |
| 19160 | total_premium_request_cost = from_float(obj.get("totalPremiumRequestCost")) |
| 19161 | total_user_requests = from_int(obj.get("totalUserRequests")) |
| 19162 | current_model = from_union([from_str, from_none], obj.get("currentModel")) |
| 19163 | token_details = from_union([lambda x: from_dict(UsageMetricsTokenDetail.from_dict, x), from_none], obj.get("tokenDetails")) |
| 19164 | total_nano_aiu = from_union([from_float, from_none], obj.get("totalNanoAiu")) |
| 19165 | return UsageGetMetricsResult(code_changes, last_call_input_tokens, last_call_output_tokens, model_metrics, session_start_time, total_api_duration_ms, total_premium_request_cost, total_user_requests, current_model, token_details, total_nano_aiu) |
| 19166 | |
| 19167 | def to_dict(self) -> dict: |
| 19168 | result: dict = {} |
| 19169 | result["codeChanges"] = to_class(UsageMetricsCodeChanges, self.code_changes) |
| 19170 | result["lastCallInputTokens"] = from_int(self.last_call_input_tokens) |
no outgoing calls
no test coverage detected
searching dependent graphs…