| 325 | } |
| 326 | |
| 327 | fn usage_to_json(usage: TokenUsage) -> JsonValue { |
| 328 | let mut object = BTreeMap::new(); |
| 329 | object.insert( |
| 330 | "input_tokens".to_string(), |
| 331 | JsonValue::Number(i64::from(usage.input_tokens)), |
| 332 | ); |
| 333 | object.insert( |
| 334 | "output_tokens".to_string(), |
| 335 | JsonValue::Number(i64::from(usage.output_tokens)), |
| 336 | ); |
| 337 | object.insert( |
| 338 | "cache_creation_input_tokens".to_string(), |
| 339 | JsonValue::Number(i64::from(usage.cache_creation_input_tokens)), |
| 340 | ); |
| 341 | object.insert( |
| 342 | "cache_read_input_tokens".to_string(), |
| 343 | JsonValue::Number(i64::from(usage.cache_read_input_tokens)), |
| 344 | ); |
| 345 | JsonValue::Object(object) |
| 346 | } |
| 347 | |
| 348 | fn usage_from_json(value: &JsonValue) -> Result<TokenUsage, SessionError> { |
| 349 | let object = value |