cometapi autoreg: Castle via CDP, org fix, sequential wave (43 accounts verified)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import json, sys, requests, time
|
||||
|
||||
B = 'https://www.cometapi.com'
|
||||
|
||||
|
||||
def go(result_file):
|
||||
d = json.load(open(result_file))
|
||||
s = requests.Session()
|
||||
for k, v in (d.get('cookies') or {}).items():
|
||||
try:
|
||||
s.cookies.set(k, v, domain='www.cometapi.com')
|
||||
except Exception:
|
||||
pass
|
||||
H = {'User-Agent': 'Mozilla/5.0 Chrome/141', 'Accept': 'application/json', 'Origin': B,
|
||||
'Referer': B + '/console/token', 'Content-Type': 'application/json'}
|
||||
r = s.get(B + '/api/user/self', headers=H, timeout=25)
|
||||
me = r.json().get('data', {})
|
||||
print('self', r.status_code, 'quota', me.get('quota'), 'orgs', json.dumps(me.get('org_list'), ensure_ascii=False)[:300])
|
||||
if not me.get('org_list'):
|
||||
nm = (d.get('email') or 'acct').split('@')[0]
|
||||
r2 = s.post(B + '/api/organization', headers=H, json={"name": nm + " org"}, timeout=30)
|
||||
print('org create', r2.status_code, r2.text[:300])
|
||||
r = s.get(B + '/api/user/self', headers=H, timeout=25)
|
||||
me = r.json().get('data', {})
|
||||
print('self2 quota', me.get('quota'), 'orgs', json.dumps(me.get('org_list'), ensure_ascii=False)[:300])
|
||||
ol = me.get('org_list') or []
|
||||
oid = str(ol[0]['id']) if ol else None
|
||||
if oid:
|
||||
HH = dict(H); HH['X-Organization-Id'] = oid; HH['X-Workspace-Id'] = oid
|
||||
tk = s.post(B + '/api/token', headers=HH, json={"name": "main", "remain_quota": 0, "expired_time": -1,
|
||||
"unlimited_quota": True, "model_limits_enabled": False,
|
||||
"model_limits": "", "allow_ips": "", "group": ""}, timeout=30)
|
||||
print('token', tk.status_code, tk.text[:300])
|
||||
key = None
|
||||
try:
|
||||
key = tk.json()['data']['key']
|
||||
except Exception:
|
||||
pass
|
||||
me2 = s.get(B + '/api/user/self', headers=HH, timeout=25).json().get('data', {})
|
||||
print('after: quota', me2.get('quota'), 'fct', me2.get('first_create_token'), 'fac', me2.get('first_api_call'))
|
||||
if key:
|
||||
k = key if key.startswith('sk-') else 'sk-' + key
|
||||
print('KEY', k)
|
||||
json.dump({'email': d.get('email'), 'key': k, 'org': oid}, open(result_file.replace('.json', '_tok.json'), 'w'))
|
||||
# test chat
|
||||
r3 = requests.post('https://api.cometapi.com/v1/chat/completions',
|
||||
headers={'Authorization': 'Bearer ' + k, 'Content-Type': 'application/json'},
|
||||
json={'model': 'gpt-6-luna', 'messages': [{'role': 'user', 'content': 'say ok'}], 'max_tokens': 10},
|
||||
timeout=90)
|
||||
print('chat', r3.status_code, r3.text[:250])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
go(sys.argv[1])
|
||||
Reference in New Issue
Block a user