"""Read-only catalog/account access check. No model calls; no credentials written.""" from pathlib import Path import urllib.request,json,datetime root=Path(__file__).resolve().parents[1]/'kit/operator/access';root.mkdir(exist_ok=True) base='https://openrouter.ai/api/v1/' def get(route, key=None): headers={'User-Agent':'Kingy-Qwen4-ReadOnly-Preflight/1.0'} if key:headers['Authorization']='Bearer '+key with urllib.request.urlopen(urllib.request.Request(base+route,headers=headers),timeout=30) as r:return json.load(r) catalog=get('models') ids=['qwen/qwen4-max','openai/gpt-6-astra','openai/gpt-6.1-sol','anthropic/claude-opus-5.5','anthropic/claude-fable-5.2'] rows=[x for x in catalog['data'] if x['id'] in ids] (root/'model-catalog.json').write_text(json.dumps(rows,indent=2)) for row in rows: name=row['id']; endpoints=get('models/'+name+'/endpoints') (root/(name.replace('/','--')+'-endpoints.json')).write_text(json.dumps(endpoints,indent=2)) print(json.dumps([{k:x.get(k) for k in ['id','canonical_slug','pricing','reasoning']}for x in rows],indent=2)) authpath=Path.home()/'.local/share/opencode/auth.json' if authpath.exists(): key=json.loads(authpath.read_text()).get('openrouter',{}).get('key') if key: status=get('key',key)['data'] safe={k:status.get(k) for k in ['limit','limit_remaining','usage','is_free_tier','rate_limit','expires_at']} safe['checked_utc']=datetime.datetime.now(datetime.timezone.utc).isoformat() (root/'account-status.json').write_text(json.dumps(safe,indent=2));print(json.dumps(safe,indent=2))