Skip to main content

read_opencode_usage

Function read_opencode_usage 

Source
pub fn read_opencode_usage(
    db_path: &Path,
    time_range: TimeRange,
) -> Result<Vec<(String, CodeAnalysis, f64)>>
Expand description

Reads per-session token usage from the OpenCode database.

Each returned tuple is (local YYYY-MM-DD date, CodeAnalysis, stored_cost) where the CodeAnalysis holds one assistant message’s conversation_usage, keyed by that message’s provider-qualified model id, and stored_cost is OpenCode’s own cost for that message. The date comes from the assistant message timestamp and is filtered by time_range, matching the file-walker semantics.

§Errors

Returns an error if the database cannot be opened or queried.