use t3router::t3::client::Client;use t3router::t3::message::{Message, Type};use t3router::t3::config::Config;use dotenv::dotenv;
2
Load credentials and initialize the client
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { dotenv().ok(); let cookies = std::env::var("COOKIES").expect("COOKIES not set"); let convex_session_id = std::env::var("CONVEX_SESSION_ID") .expect("CONVEX_SESSION_ID not set"); let mut client = Client::new(cookies, convex_session_id); // Initialize the client by connecting to t3.chat if client.init().await? { println!("Client initialized successfully"); } Ok(())}
The init() method establishes a connection with t3.chat and validates your credentials.
3
Send a message and get a response
let config = Config::new();let response = client .send( "gemini-2.5-flash-lite", Some(Message::new( Type::User, "What is the capital of France?".to_string(), )), Some(config), ) .await?;println!("User: What is the capital of France?");println!("Assistant: {}", response.content);
Here’s a complete working example from examples/basic_usage.rs:23-36:
use dotenv::dotenv;use t3router::t3::{ client::Client, config::Config, message::{Message, Type},};#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { dotenv().ok(); let cookies = std::env::var("COOKIES").expect("COOKIES not set"); let convex_session_id = std::env::var("CONVEX_SESSION_ID") .expect("CONVEX_SESSION_ID not set"); let mut client = Client::new(cookies, convex_session_id); if client.init().await? { println!("Client initialized successfully\n"); } let config = Config::new(); println!("=== Example 1: Single Message ==="); let response = client .send( "gemini-2.5-flash-lite", Some(Message::new( Type::User, "What is the capital of France?".to_string(), )), Some(config.clone()), ) .await?; println!("User: What is the capital of France?"); println!("Assistant: {}\n", response.content); Ok(())}