Skip to main content

test_codex/
test_codex.rs

1use seher::{BrowserDetector, CookieReader};
2
3#[tokio::main(flavor = "current_thread")]
4async fn main() {
5    let detector = BrowserDetector::new();
6    let browsers = detector.detect_browsers();
7
8    for browser in &browsers {
9        if !browser.is_chromium_based() {
10            continue;
11        }
12        for prof in detector.list_profiles(*browser) {
13            if let Ok(cookies) = CookieReader::read_cookies(&prof, "chatgpt.com") {
14                let has_session = cookies
15                    .iter()
16                    .any(|c| c.name.starts_with("__Secure-next-auth.session-token"));
17
18                if !has_session {
19                    continue;
20                }
21
22                println!(
23                    "Using {} - {} ({} cookies)",
24                    browser.name(),
25                    prof.name,
26                    cookies.len(),
27                );
28
29                match seher::codex::CodexClient::fetch_usage(&cookies).await {
30                    Ok(usage) => {
31                        println!("\nSuccess! Codex usage:");
32                        println!("  plan_type: {}", usage.plan_type);
33                        println!("  rate_limit limited: {}", usage.rate_limit.is_limited());
34                        println!(
35                            "  rate_limit reset_time: {:?}",
36                            usage.rate_limit.next_reset_time()
37                        );
38                        println!(
39                            "  code_review limited: {}",
40                            usage.code_review_rate_limit.is_limited()
41                        );
42                        return;
43                    }
44                    Err(e) => {
45                        println!("\nFailed to fetch Codex usage: {e}");
46                    }
47                }
48            }
49        }
50    }
51
52    println!("No chatgpt.com session with __Secure-next-auth.session-token found");
53}