Skip to main content

Authentication

T3Router uses your browser cookies to authenticate with t3.chat. This guide will walk you through extracting these credentials and setting them up securely.
Security First: Your cookies provide full access to your t3.chat account. Treat them like passwords - never commit them to version control or share them publicly.

How Authentication Works

T3Router authenticates by:
  1. Using your browser’s cookie string to maintain your session
  2. Including your convex-session-id to identify your active session
  3. Automatically refreshing the wos-session cookie when needed
The library mimics your browser’s requests, so as long as your cookies are valid, you have full access to your t3.chat subscription.

Getting Your Credentials

1

Open t3.chat in Your Browser

Navigate to t3.chat and make sure you’re logged in to your paid account.
2

Open Developer Tools

  • Press F12, or
  • Press Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac), or
  • Right-click anywhere and select Inspect
3

Navigate to Storage

  1. Click the Application tab in Developer Tools
  2. In the left sidebar, expand Cookies
  3. Click on https://t3.chat
4

Copy convex-session-id

In the cookies table:
  1. Find the row with Name convex-session-id
  2. Copy the Value column (a long string of characters)
  3. Save it temporarily - you’ll need this in a moment
The convex-session-id identifies your active session on t3.chat. It looks something like: j1h9z3y8x7w6v5u4t3s2r1q0p9o8n7m6
5

Copy Full Cookie String

Now you need to copy ALL cookies as a single string:
Copy each cookie’s name and value, joining them with ; :
cookie1=value1; cookie2=value2; cookie3=value3
This is tedious but works on all browsers.
The result should look like:
wos-session=abc123; convex-session-id=def456; other-cookie=xyz789

Setting Up Your Environment

1

Create .env File

In your project root directory, create a file named .env:
.env
COOKIES="your_full_cookie_string_here"
CONVEX_SESSION_ID="your_session_id_here"
Important formatting notes:
  • Put your actual values inside the quotes
  • The COOKIES value should be the entire cookie string from step 5
  • The CONVEX_SESSION_ID value is just the session ID from step 4 (without extra quotes)
  • Do not include the format!() wrapper - that’s done in your Rust code
2

Add .env to .gitignore

Critical security step: Never commit credentials to version control.Add to your .gitignore:
.gitignore
.env
.env.local
.env.*.local
3

Use in Your Code

Load the credentials in your Rust program:
use dotenv::dotenv;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load environment variables from .env file
    dotenv().ok();
    
    // Get credentials
    let cookies = std::env::var("COOKIES")?;
    let session_id = format!(
        "\"{}\"",
        std::env::var("CONVEX_SESSION_ID")?
    );
    
    // Create client
    let mut client = Client::new(cookies, session_id);
    client.init().await?;
    
    // Your code here...
    Ok(())
}
Notice the format!("\"{}\"\, ...) wrapper around CONVEX_SESSION_ID - this adds the required quotes for the API.

Example .env File

Here’s what a properly formatted .env file looks like:
.env
COOKIES="wos-session=sess_01JQPXYZ123ABC; convex-session-id=j1h9z3y8x7w6v5u4t3s2r1q0; _ga=GA1.2.123456789.1234567890; _gid=GA1.2.987654321.0987654321"
CONVEX_SESSION_ID="j1h9z3y8x7w6v5u4t3s2r1q0"
These are example values - use your actual credentials from t3.chat!

Security Best Practices

  • Always use .env files for credentials
  • Always add .env to .gitignore
  • Use .env.example (with placeholder values) to document required variables
  • Never hardcode credentials in your source code
Cookies can expire or be invalidated. When you notice authentication failures:
  1. Log out of t3.chat in your browser
  2. Log back in
  3. Extract fresh credentials using the steps above
  4. Update your .env file
For production deployments:
  • Use your platform’s secret management (AWS Secrets Manager, etc.)
  • Never store credentials in container images
  • Use environment variables injected at runtime
  • Consider using temporary credentials when possible
  • Only store credentials on machines you trust
  • Don’t share your .env file
  • Use restrictive file permissions: chmod 600 .env
  • Consider using a password manager to store backup credentials

How the Client Uses Your Credentials

When you create a client, here’s what happens:
let mut client = Client::new(cookies, session_id);
The Client struct stores your credentials and uses them to:
  1. Authenticate requests: Your cookie string is sent with every API call
  2. Maintain sessions: The convex-session-id identifies your active session
  3. Auto-refresh: The wos-session cookie is automatically updated via refresh_session()
From src/t3/client.rs:32-58:
pub fn new(cookies: String, convex_session_id: String) -> Self {
    Self {
        cookies,
        convex_session_id,
        thread_id: None,
        client: reqwest::Client::builder()
            .user_agent("Mozilla/5.0 ...")
            .default_headers({
                let mut headers = reqwest::header::HeaderMap::new();
                headers.insert("origin", "https://t3.chat".parse().unwrap());
                // ... more headers
                headers
            })
            .build()
            .unwrap(),
        messages: Vec::new(),
    }
}

Troubleshooting

The .env file isn’t being loaded. Check:
  • File is named exactly .env (not .env.txt)
  • File is in your project root (same directory as Cargo.toml)
  • You called dotenv().ok(); before accessing the variables
Your cookies may have expired:
  1. Extract fresh credentials from your browser
  2. Make sure you’re logged into a paid t3.chat account
  3. Verify the cookie string is complete and properly formatted
  4. Check that convex-session-id matches what’s in your browser
The library automatically refreshes your session, but if you see issues:
  • The wos-session cookie may need manual refresh
  • Try calling client.refresh_session().await? explicitly
  • Extract fresh cookies from your browser if problems persist

Next Steps

Quickstart

Now that you understand authentication, complete the quickstart guide.

Client Reference

Learn about all the methods available on the Client struct.

Build docs developers (and LLMs) love