Module Chatoyant_tokens.CostSource

Token usage and cost data shared by core and provider layers.

Sourcetype usage = {
  1. input_tokens : int;
  2. output_tokens : int;
  3. reasoning_tokens : int;
  4. cached_tokens : int;
  5. cache_write_tokens : int;
  6. total_tokens : int;
  7. actual_cost_usd : float option;
}
Sourcetype source =
  1. | Provider_reported
  2. | Estimated
  3. | Unmetered
  4. | Unknown
    (*

    Provenance for token usage. Provider-reported values are authoritative; estimated values must only be used when a provider did not return usage. Local inference is unmetered by design.

    *)
Sourcetype pricing = {
  1. input_per_million : float;
  2. output_per_million : float;
  3. cached_per_million : float option;
  4. cache_write_per_million : float option;
  5. cache_write_1h_per_million : float option;
  6. per_image : float option;
  7. per_second : float option;
}
Sourcetype result = {
  1. input : float;
  2. output : float;
  3. cached : float;
  4. cache_write : float;
  5. actual_usd : float option;
  6. total : float;
}
Sourcetype cost_per_token = {
  1. per_token_input : float;
  2. per_token_output : float;
  3. per_token_cached : float;
  4. per_token_cache_write : float;
}
Sourceval empty_usage : usage
Sourceval pricing : ?cached_per_million:float -> ?cache_write_per_million:float -> ?cache_write_1h_per_million:float -> ?per_image:float -> ?per_second:float -> input_per_million:float -> output_per_million:float -> unit -> pricing
Sourceval calculate : pricing:pricing option -> usage -> result
Sourceval estimate : pricing:pricing option -> ?input_tokens:int -> ?input_text:string -> expected_output_tokens:int -> unit -> result
Sourceval calculate_batch : pricing:pricing option -> usage list -> result
Sourceval calculate_image : pricing:pricing option -> count:int -> float
Sourceval calculate_video : pricing:pricing option -> duration_seconds:int -> float
Sourceval cost_per_token : pricing -> cost_per_token
Sourceval normalize_total : usage -> usage
Sourceval source_to_string : source -> string
Sourceval usage_to_json : usage -> Chatoyant_runtime.Json.t
Sourceval result_to_json : result -> Chatoyant_runtime.Json.t