Initial public release

This commit is contained in:
aaronjaworski710
2026-10-14 17:49:04 +03:00
commit c5954ddf37
6 changed files with 439 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
config.json
treg_accounts.jsonl
treg_farm_state.json
*.log
__pycache__/
.venv/
+96
View File
@@ -0,0 +1,96 @@
# treg-autoreg
Mass auto-registration toolkit for **[treg.to](https://treg.to/)** — the "OpenRouter for agent tools" (3955 endpoints, 111 providers, one API key).
Each fresh account gets a **$1.00 signup grant** (~1600–2000 tool calls: X/Twitter posts at $0.0005, TikTok profiles at $0.001, web search free). Zero captcha — pure email OTP flow.
> Part of the free-tools series. More finds: [t.me/AlStack](https://t.me/AlStack)
## How it works (full protocol, reverse-engineered)
```
POST /auth/email/start {"email": "you+treg1@gmail.com"} -> {"sent": true}
OTP: 6-digit code arrives in the email SUBJECT (sender treg.to)
POST /auth/email/verify {"email", "code"} -> {"token"} + Set-Cookie session
POST /orgs {"name": "myorg123"} [X-Treg-Token] -> org created, grant $1 (async ~2s)
GET /auth/cli-token [X-Treg-Org: myorg123, SESSION COOKIE] -> {"token": <org_key>} <-- usable API key
GET /orgs/{id}/balance [X-Treg-Token: org_key] -> {"balance_micro": 1000000}
```
All requests carry `X-Treg-Key-Protocol: 1`.
### Pitfalls this toolkit solves
| Pitfall | Fix |
|---|---|
| `GET /auth/cli-token` returns **403** "a bootstrap token cannot mint a Default key" | Send the verify **session cookie only**, NO `X-Treg-Token` header on that request |
| Org names containing `treg` are rejected | Neutral random names (`keynest983`, `gothlab331`, ...) |
| Gmail IMAP `search` returns **stale** results | `m.noop()` before every search |
| Re-issued `start` invalidates the previous code | Filter mails by `Date >= since_ts - 30` |
| Render backend saturates (503 `treg_saturated: true`) | Exponential backoff retry on every call |
| IP budget: 30 OTP starts / 15 min | Pacing 10–22 s between accounts, auto-cool 900 s on 429 |
| Grant is per-**user**, once (DB-locked) | One Gmail `+alias` = one user = one $1 |
## Setup
```bash
# Python 3.10+, only dependency: requests
pip install requests
# 1. create config
cp config.example.json config.json
# 2. edit config.json: put your Gmail address + IMAP app password
# (Gmail: Security -> 2-Step Verification -> App passwords)
```
No secrets in the repo — `config.json` is gitignored. Env vars `TREG_IMAP_USER` / `TREG_IMAP_PASS` work too.
## Usage
```bash
# register accounts 1..30 (aliases you+treg1 ... you+treg30)
python treg_farm.py 1 30
# re-login accounts that have an org but no pinned key (recovers 403-stuck accounts)
python treg_farm.py recover
# live-check the bank: balances + pinned keys
python verify_bank.py
```
Output:
- `treg_accounts.jsonl` — the bank: `{email, token, org_token, org, org_id, balance_micro, ts}`
- `treg_farm_state.json` — resumable wave state (`registered` / `no_grant` / `failed`)
Auto-stop: 4 consecutive accounts without grant. The wave is resumable — rerun with a new start index any time.
## Using the keys
```bash
# raw HTTP
curl https://treg.to/call/treg.web.search \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{"q": "hello world"}'
# official CLI
pip install "tools-registry[proxy]"
treg login --token ***
treg call treg.x.user.posts --data '{"username": "elonmusk", "limit": 3}'
treg balance
```
Prices (live-verified): X user posts **$0.0005**, X search $0.00075, TikTok profile **$0.001**, web search **free** (19 providers), email verify free. Platform margin 0% — you pay provider cost. BYOK keys are unmetered.
## Rate limits (from source)
- 30 OTP starts / 15 min / IP, 5 / email
- 1 signup grant per user (not per IP) — alias farming is the intended scale path
- Backend on Render: expect occasional 503 saturation windows
## Disclaimer
For authorized security research / personal API usage on your own accounts only. Respect treg.to ToS.
---
[t.me/AlStack](https://t.me/AlStack) — free AI tools, APIs, proxies & farming drops
+7
View File
@@ -0,0 +1,7 @@
{
"imap_user": "youraddress@gmail.com",
"imap_pass": "your-16-char-app-password",
"imap_host": "imap.gmail.com",
"alias_prefix": "treg",
"base_url": "https://treg.to"
}
+1
View File
@@ -0,0 +1 @@
requests
+256
View File
@@ -0,0 +1,256 @@
# treg.to mass autoreg — email OTP via Gmail alias + IMAP, org create, Default-key pin
# Usage: python treg_farm.py <start_n> <count> (aliases <imap_user>+<prefix><n>@gmail.com)
# python treg_farm.py recover (re-login accounts missing org_token)
# Config: config.json (see config.example.json) or env TREG_IMAP_USER / TREG_IMAP_PASS
# Output: treg_accounts.jsonl {email, token, org_token, org, org_id, balance_micro, ts}
import sys, json, time, re, random, os, imaplib, email.utils
import requests
from datetime import datetime, timezone
HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, "treg_accounts.jsonl")
STATE = os.path.join(HERE, "treg_farm_state.json")
def load_cfg():
cfg = {}
p = os.path.join(HERE, "config.json")
if os.path.exists(p):
with open(p, encoding="utf-8") as f:
cfg = json.load(f)
cfg["imap_user"] = cfg.get("imap_user") or os.environ.get("TREG_IMAP_USER", "")
cfg["imap_pass"] = cfg.get("imap_pass") or os.environ.get("TREG_IMAP_PASS", "")
if not cfg["imap_user"] or not cfg["imap_pass"]:
sys.exit("ERROR: set imap_user/imap_pass in config.json or TREG_IMAP_USER/TREG_IMAP_PASS env")
cfg.setdefault("imap_host", "imap.gmail.com")
cfg.setdefault("alias_prefix", "treg")
cfg.setdefault("base_url", "https://treg.to")
cfg.setdefault("email_domain", cfg["imap_user"].split("@", 1)[1])
cfg.setdefault("email_base", cfg["imap_user"].split("@", 1)[0])
return cfg
CFG = load_cfg()
BASE = CFG["base_url"]
HDRS = {"Content-Type": "application/json", "X-Treg-Key-Protocol": "1"}
def log(msg):
print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}", flush=True)
def alias(n):
return f"{CFG['email_base']}+{CFG['alias_prefix']}{n}@{CFG['email_domain']}"
def req_with_retry(sess, method, path, retries=6, **kw):
url = BASE + path
for att in range(retries):
try:
r = sess.request(method, url, timeout=35, **kw)
if r.status_code == 503 and "saturated" in r.text:
time.sleep(8 + att * 7 + random.uniform(0, 5))
continue
try:
return r.status_code, r.json()
except Exception:
return r.status_code, {"raw": r.text[:200]}
except Exception as e:
if att == retries - 1:
return 0, {"err": str(e)[:150]}
time.sleep(5 + att * 4)
return 503, {"err": "saturated-exhausted"}
def load_state():
if os.path.exists(STATE):
with open(STATE, encoding="utf-8") as f:
return json.load(f)
return {"registered": [], "no_grant": [], "failed": []}
def save_state(st):
with open(STATE, "w", encoding="utf-8") as f:
json.dump(st, f, indent=1)
def imap_code(want_email, since_ts, timeout_s=120):
"""6-digit code (in email SUBJECT) for want_email; Date >= since_ts-30 guard."""
deadline = time.time() + timeout_s
m = None
while time.time() < deadline:
try:
if m is None:
m = imaplib.IMAP4_SSL(CFG["imap_host"])
m.login(CFG["imap_user"], CFG["imap_pass"])
m.select("INBOX", readonly=True)
m.noop() # CRITICAL: Gmail IMAP search results are stale without noop
typ, data = m.search(None, "FROM", "treg.to")
ids = data[0].split()
for i in reversed(ids[-8:]):
typ, msg = m.fetch(i, "(BODY.PEEK[HEADER.FIELDS (TO SUBJECT DATE)])")
hdr = msg[0][1].decode("utf-8", "ignore")
if want_email.lower() not in hdr.lower():
continue
dm = re.search(r"Date: (.+)", hdr)
if dm:
try:
dts = email.utils.parsedate_to_datetime(dm.group(1).strip()).timestamp()
if dts < since_ts - 30:
continue
except Exception:
pass
subj = re.search(r"Subject: (\d{6})", hdr)
if subj:
try: m.logout()
except Exception: pass
return subj.group(1)
except Exception as e:
log(f"imap err {e}")
try:
if m: m.logout()
except Exception: pass
m = None
time.sleep(5)
try:
if m: m.logout()
except Exception: pass
return None
ORG_WORDS = ["reformlab", "vladwork", "gothlab", "stackyard", "promptden", "datahive",
"keynest", "loopdock", "nodegarden", "byteshed", "orbitkit", "fluxden"]
def login_and_pin(email, want_org=None, org_name=None, used_orgs=None):
"""OTP login -> create org -> pin Default key (cookie-only!) -> balance."""
sess = requests.Session()
sess.headers.update(HDRS)
rec = {"email": email, "ts": datetime.now(timezone.utc).isoformat()}
since_ts = time.time()
st, d = req_with_retry(sess, "POST", "/auth/email/start", json={"email": email})
if st != 200:
rec["stage"], rec["err"] = "start", f"{st} {json.dumps(d)[:150]}"
return rec
code = imap_code(email, since_ts)
if not code:
rec["stage"], rec["err"] = "imap", "no code"
return rec
st, d = req_with_retry(sess, "POST", "/auth/email/verify", json={"email": email, "code": code})
if st != 200 or "token" not in d:
rec["stage"], rec["err"] = "verify", f"{st} {json.dumps(d)[:150]}"
return rec
rec["token"] = d["token"]
# org: existing (recover) or fresh random name ('treg' substring is RESERVED server-side)
if want_org:
org_name = want_org
else:
if not org_name:
for w in random.sample(ORG_WORDS, len(ORG_WORDS)):
cand = f"{w}{random.randint(100, 999)}"
if used_orgs is None or cand not in used_orgs:
org_name = cand
break
st, d = req_with_retry(sess, "POST", "/orgs", json={"name": org_name},
headers={"X-Treg-Token": rec["token"]})
if st >= 400:
rec["stage"], rec["err"] = "org", f"{st} {json.dumps(d)[:150]}"
return rec
if used_orgs is not None:
used_orgs.add(org_name)
rec["org"] = org_name
time.sleep(1.5)
# PIN: /auth/cli-token with SESSION COOKIE ONLY — sending the bootstrap token in
# X-Treg-Token trips server-side 403 "a bootstrap token cannot mint a Default key".
st, d = req_with_retry(sess, "GET", "/auth/cli-token", headers={"X-Treg-Org": org_name})
if st == 200 and d.get("token"):
rec["org_token"] = d["token"]
else:
rec["stage"], rec["err"] = "pin", f"{st} {json.dumps(d)[:150]}"
return rec
sess.headers["X-Treg-Token"] = rec["org_token"]
st, d = req_with_retry(sess, "GET", "/orgs")
org_id = None
if st == 200:
orgs = d if isinstance(d, list) else d.get("orgs", d.get("items", []))
for o in orgs:
if isinstance(o, dict) and (o.get("slug") or o.get("name")) == org_name:
org_id = o.get("org_id") or o.get("id")
rec["org_id"] = org_id
if org_id:
st, d = req_with_retry(sess, "GET", f"/orgs/{org_id}/balance?limit=3")
if st == 200:
rec["balance_micro"] = d.get("balance_micro", d.get("balance"))
else:
rec["bal_err"] = f"{st} {json.dumps(d)[:100]}"
return rec
def merge_account(st, rec):
st["registered"] = [r for r in st["registered"] if r.get("email") != rec["email"]]
st["no_grant"] = [r for r in st["no_grant"] if r.get("email") != rec["email"]]
if rec.get("balance_micro") and int(rec["balance_micro"]) > 0:
st["registered"].append(rec)
else:
st["no_grant"].append(rec)
save_state(st)
bank = {}
for src in (st["registered"], st["no_grant"]):
for r in src:
if r.get("token"):
bank[r["email"]] = r
with open(OUT, "w", encoding="utf-8") as f:
for r in bank.values():
f.write(json.dumps(r) + "\n")
def recover():
st = load_state()
stuck = [r for r in st.get("no_grant", []) if r.get("org") and not r.get("org_token")]
if os.path.exists(OUT):
for l in open(OUT, encoding="utf-8"):
r = json.loads(l)
if r.get("org") and not r.get("org_token") and not any(x["email"] == r["email"] for x in stuck):
stuck.append(r)
log(f"recover: {len(stuck)} stuck accounts")
for r in stuck:
rec = login_and_pin(r["email"], want_org=r["org"])
if rec.get("org_token"):
merge_account(st, rec)
log(f"RECOVERED {r['email']} org={r['org']} bal={rec.get('balance_micro')}")
else:
log(f"RECOVER-FAIL {r['email']} {rec.get('stage')} {str(rec.get('err',''))[:100]}")
time.sleep(random.uniform(10, 20))
def main():
if len(sys.argv) > 1 and sys.argv[1] == "recover":
recover()
return
start_n = int(sys.argv[1]) if len(sys.argv) > 1 else 1
count = int(sys.argv[2]) if len(sys.argv) > 2 else 10
st = load_state()
done_emails = {r.get("email") for r in st["registered"]}
used_orgs = {r.get("org") for r in st["registered"] + st["no_grant"] if r.get("org")}
ok, nogrant, fail = 0, 0, 0
consecutive_nogrant = 0
for n in range(start_n, start_n + count):
email = alias(n)
if email in done_emails:
continue
rec = login_and_pin(email, org_name=None, used_orgs=used_orgs)
if rec.get("org_token"):
merge_account(st, rec)
bal = rec.get("balance_micro")
if bal and int(bal) > 0:
ok += 1
consecutive_nogrant = 0
log(f"OK n={n} org={rec['org']} bal=${int(bal)/1e6:.2f} (ok={ok})")
else:
nogrant += 1
consecutive_nogrant += 1
log(f"NO-GRANT n={n} org={rec.get('org')} bal={bal} err={rec.get('bal_err','')} (nogrant={nogrant})")
else:
st["failed"].append({k: rec.get(k) for k in ("email", "stage", "err", "ts")})
fail += 1
save_state(st)
log(f"FAIL n={n} stage={rec.get('stage')} err={str(rec.get('err',''))[:120]}")
if rec.get("stage") == "start" and ("429" in str(rec.get("err", "")) or "rate" in str(rec.get("err", "")).lower()):
log("RATE-LIMITED — cooling 900s (OTP IP window: 30 starts / 15 min)")
time.sleep(900)
if consecutive_nogrant >= 4:
log("4 consecutive no-grant — stopping wave")
break
time.sleep(random.uniform(10, 22))
total_bal = sum(int(r.get("balance_micro") or 0) for r in st["registered"])
log(f"WAVE DONE ok={ok} nogrant={nogrant} fail={fail} | accounts_with_grant={len(st['registered'])} total=${total_bal/1e6:.2f}")
if __name__ == "__main__":
main()
+73
View File
@@ -0,0 +1,73 @@
# Live-check the bank: for each account in treg_accounts.jsonl verify org_token + balance via API.
# Usage: python verify_bank.py [--json out.json]
import json, os, sys, time
import requests
HERE = os.path.dirname(os.path.abspath(__file__))
BANK = os.path.join(HERE, "treg_accounts.jsonl")
BASE = "https://treg.to"
HDRS = {"X-Treg-Key-Protocol": "1", "Content-Type": "application/json"}
def main():
out_json = None
if "--json" in sys.argv:
out_json = sys.argv[sys.argv.index("--json") + 1]
rows = [json.loads(l) for l in open(BANK, encoding="utf-8")] if os.path.exists(BANK) else []
if not rows:
print("bank empty")
return
live, dead = [], []
total = 0
for r in rows:
tok = r.get("org_token")
if not tok:
dead.append({**r, "why": "no org_token"})
continue
ok = False
for att in range(4):
try:
resp = requests.get(BASE + "/orgs", headers={**HDRS, "X-Treg-Token": tok}, timeout=30)
if resp.status_code == 503 and "saturated" in resp.text:
time.sleep(6 + att * 5); continue
if resp.status_code == 200:
orgs = resp.json()
orgs = orgs if isinstance(orgs, list) else orgs.get("orgs", orgs.get("items", []))
oid = r.get("org_id")
if not oid:
for o in orgs:
if isinstance(o, dict) and (o.get("slug") or o.get("name")) == r.get("org"):
oid = o.get("org_id") or o.get("id")
bal = None
if oid:
b = requests.get(f"{BASE}/orgs/{oid}/balance?limit=1",
headers={**HDRS, "X-Treg-Token": tok}, timeout=30)
if b.status_code == 200:
bal = b.json().get("balance_micro", b.json().get("balance"))
live.append({"email": r["email"], "org": r.get("org"), "org_id": oid,
"balance_micro": bal, "org_token": tok})
if bal: total += int(bal)
ok = True
else:
dead.append({**r, "why": f"HTTP {resp.status_code}"})
ok = True
break
except Exception as e:
if att == 3:
dead.append({**r, "why": str(e)[:100]})
ok = True
time.sleep(4)
if not ok:
dead.append({**r, "why": "retries exhausted"})
time.sleep(0.6)
print(f"LIVE={len(live)} DEAD={len(dead)} TOTAL=${total/1e6:.2f}")
for x in live:
print(f" OK {x['email']} org={x['org']} bal=${int(x['balance_micro'] or 0)/1e6:.3f}")
for x in dead:
print(f" RIP {x['email']} {x.get('why','')[:80]}")
if out_json:
with open(out_json, "w", encoding="utf-8") as f:
json.dump({"live": live, "dead": dead, "total_micro": total}, f, indent=1)
print(f"saved -> {out_json}")
if __name__ == "__main__":
main()