Repository navigation
Expand file tree
/
Copy pathcodex-smoke.py
More file actions
82 lines (70 loc) · 2.55 KB
/
Copy pathcodex-smoke.py
File metadata and controls
82 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
"""Forge: smoke-test ChatGPT Codex OAuth token against the Codex backend.
Uses ~/.codex/auth.json only (never prints secrets). Exit 0 on success.
python3 scripts/codex-smoke.py
python3 scripts/codex-smoke.py --model gpt-5.6-luna
"""
from __future__ import annotations
import argparse
import json
import sys
import urllib.error
import urllib.request
from pathlib import Path
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--model", default="gpt-5.6-sol")
args = ap.parse_args()
auth_path = Path.home() / ".codex" / "auth.json"
if not auth_path.is_file():
print(f"FAIL: missing {auth_path} — run `codex login`", file=sys.stderr)
return 1
auth = json.loads(auth_path.read_text())
tokens = auth.get("tokens") or {}
tok = tokens.get("access_token")
account = tokens.get("account_id")
if not tok or not account:
print("FAIL: auth.json has no tokens.access_token / account_id", file=sys.stderr)
return 1
body = {
"model": args.model,
"stream": True,
"store": False,
"input": [
{
"role": "user",
"content": [{"type": "input_text", "text": "Reply with exactly: codex-ok"}],
}
],
}
req = urllib.request.Request(
"https://chatgpt.com/backend-api/codex/responses",
data=json.dumps(body).encode(),
headers={
"Authorization": f"Bearer {tok}",
"Content-Type": "application/json",
"Accept": "text/event-stream",
"ChatGPT-Account-Id": account,
"OpenAI-Beta": "responses=experimental",
"originator": "codex_cli_rs",
"User-Agent": "codex_cli_rs",
},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=90) as resp:
raw = resp.read(4000).decode("utf-8", "replace")
if resp.status != 200 or "response.created" not in raw:
print(f"FAIL: unexpected response status={resp.status}", file=sys.stderr)
print(raw[:400], file=sys.stderr)
return 1
except urllib.error.HTTPError as e:
print(f"FAIL: HTTP {e.code}: {e.read()[:400].decode()}", file=sys.stderr)
return 1
except Exception as e:
print(f"FAIL: {type(e).__name__}: {e}", file=sys.stderr)
return 1
print(f"OK: Codex backend accepts model={args.model} (token from ~/.codex/auth.json)")
return 0
if __name__ == "__main__":
raise SystemExit(main())