DERBACH's picture
download
raw
2.08 kB
import json
from pathlib import Path
import pandas as pd
def main():
p=Path('outputs/api_budget_ledger.json')
if not p.exists():return
d=json.loads(p.read_text());rows=d['entries'];records=[]
for m in sorted(set(r['model'] for r in rows)):
r=[x for x in rows if x['model']==m];ok=[x for x in r if x['status']=='completed']
known=[x for x in r if 'prompt_tokens' in x and 'completion_tokens' in x]
records.append({'model':m,'attempts':len(r),'completed':len(ok),'attempts_without_reported_usage':len(r)-len(known),'reported_prompt_tokens':sum(x['prompt_tokens'] for x in known),'reported_completion_tokens':sum(x['completion_tokens'] for x in known),'reported_reasoning_tokens':sum((x.get('usage',{}).get('completion_tokens_details') or {}).get('reasoning_tokens',0) for x in known),'estimated_reported_usage_cost_CNY':sum(x['accounted_cost'] for x in known),'unknown_or_pending_reservation_CNY':sum(x['reserved_cost'] for x in r if x not in known),'estimated_cost_with_reservations_CNY':sum(x.get('accounted_cost',x['reserved_cost']) for x in r),'mean_completed_input':sum(x['prompt_tokens'] for x in ok)/len(ok) if ok else None,'mean_completed_output':sum(x['completion_tokens'] for x in ok)/len(ok) if ok else None})
df=pd.DataFrame(records);df.to_csv('outputs/api_usage.csv',index=False)
Path('reports/api_usage.md').write_text('# Observed API usage\n\n'+df.to_markdown(index=False)+'\n\nToken columns are sums of reported usage only. Missing usage is unknown, not zero; its attempt count and reserved budget are separate. Reasoning tokens are a subset of completion tokens, not an extra charge. Costs use the conservative planning rates in `configs/api_budget.yaml`, not a verified provider invoice. Failed/unknown usage retains an upper-bound reservation. The two pre-ledger connectivity tests are listed separately in `api_budget.md`. Codex threads use the existing ChatGPT account quota, which is separate from this intervention API ledger.\n');print(df.to_string(index=False),flush=True)
if __name__=='__main__':main()

Xet Storage Details

Size:
2.08 kB
·
Xet hash:
98e34e9399b844a1dee5e16e945d6eb0947872c45bb7bd76b4b58793be885b86

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.