select id, to_char(created_at at time zone 'Asia/Shanghai','HH24:MI:SS') bj, request_id, group_id, model, coalesce(billing_model,'') billing_model,
       input_tokens, output_tokens, cache_read_tokens,
       input_cost, output_cost, cache_read_cost, total_cost,
       round((input_cost/nullif(input_tokens,0)*1000000)::numeric,3) as in_per_m,
       round((output_cost/nullif(output_tokens,0)*1000000)::numeric,3) as out_per_m
from usage_logs
where api_key_id=157 and model='gpt-5.4-mini' and created_at > now() - interval '8 minutes'
order by id desc limit 20;

select coalesce(billing_model,'') billing_model, count(*) cnt, min(created_at at time zone 'Asia/Shanghai') min_bj, max(created_at at time zone 'Asia/Shanghai') max_bj,
       sum(total_cost) total
from usage_logs
where api_key_id=157 and model='gpt-5.4-mini' and created_at > now() - interval '8 minutes'
group by 1 order by 2 desc;
