### Manage Multi-Turn Conversations Source: https://context7.com/vibheksoni/t3router/llms.txt Illustrates how to maintain conversation context across multiple messages. It covers starting a new conversation, appending messages manually, and retrieving the full history. ```rust use t3router::t3::{ client::Client, config::Config, message::{Message, Type}, }; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let mut client = Client::new(cookies, convex_session_id); client.init().await?; let config = Config::new(); // Start a new conversation client.new_conversation(); // First message client.append_message(Message::new( Type::User, "I'm planning a trip to Paris. What are the top 3 attractions?".to_string(), )); let response1 = client.send("gemini-2.5-flash-lite", None, Some(config.clone())).await?; println!("Assistant: {}", response1.content); // Follow-up message (context is preserved) let response2 = client.send( "gemini-2.5-flash-lite", Some(Message::new(Type::User, "Tell me more about the first one.".to_string())), Some(config.clone()) ).await?; println!("Assistant: {}", response2.content); // Check conversation state println!("Thread ID: {:?}", client.get_thread_id()); println!("Total messages: {}", client.get_messages().len()); Ok(()) } ``` -------------------------------- ### Supported AI Models for T3Router Source: https://context7.com/vibheksoni/t3router/llms.txt T3Router supports over 50 AI models from various providers, including both language and image generation models. This snippet shows examples of how to invoke different model types using the client's send method. ```rust // Language model examples client.send("claude-4-sonnet", message, config).await?; // Claude 4 Sonnet client.send("gpt-4o", message, config).await?; // GPT-4o client.send("gemini-2.5-flash", message, config).await?; // Gemini 2.5 Flash client.send("deepseek-r1", message, config).await?; // DeepSeek R1 client.send("llama-3.3-70b", message, config).await?; // Llama 3.3 70B // Image generation examples client.send("gpt-image-1", message, config).await?; // DALL-E client.send("gemini-imagen-4", message, config).await?; // Gemini Imagen ``` -------------------------------- ### Initialize T3Router Client Source: https://context7.com/vibheksoni/t3router/llms.txt Demonstrates how to instantiate and initialize the T3Router client using authentication cookies and a Convex session ID. This step is mandatory before performing any API interactions. ```rust use t3router::t3::client::Client; use dotenv::dotenv; #[tokio::main] async fn main() -> Result<(), Box> { dotenv().ok(); // Load credentials from environment variables let cookies = std::env::var("COOKIES").expect("COOKIES not set"); let convex_session_id = format!( "\"{}\"", std::env::var("CONVEX_SESSION_ID").expect("CONVEX_SESSION_ID not set") ); // Create and initialize the client let mut client = Client::new(cookies, convex_session_id); if client.init().await? { println!("Client initialized successfully"); } Ok(()) } ``` -------------------------------- ### Initialize and Send Chat Messages Source: https://github.com/vibheksoni/t3router/blob/master/README.md Demonstrates how to initialize the T3Router client using environment variables and send a message to a specific AI model. The client manages the connection and returns the model's response. ```rust use t3router::t3::{client::Client, message::{Message, Type}, config::Config}; use dotenv::dotenv; #[tokio::main] async fn main() -> Result<(), Box> { dotenv().ok(); let cookies = std::env::var("COOKIES")?; let session_id = format!("\"{}\"", std::env::var("CONVEX_SESSION_ID")?); let mut client = Client::new(cookies, session_id); client.init().await?; let config = Config::new(); let response = client.send( "claude-3.7", Some(Message::new(Type::User, "What is the weather like today?".to_string())), Some(config) ).await?; println!("{}", response.content); Ok(()) ``` -------------------------------- ### Configure T3Router with ReasoningEffort and Search in Rust Source: https://context7.com/vibheksoni/t3router/llms.txt Illustrates how to customize request parameters using the `Config` struct, including setting `reasoning_effort` to 'High' for deeper analysis and enabling `include_search` for up-to-date information. Requires COOKIES and CONVEX_SESSION_ID environment variables. ```rust use t3router::t3::config::{Config, ReasoningEffort}; use t3router::t3::{client::Client, message::{Message, Type}}; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let mut client = Client::new(cookies, convex_session_id); client.init().await?; // Create custom configuration let mut config = Config::new(); config.reasoning_effort = ReasoningEffort::High; // Low, Medium, or High config.include_search = true; // Enable web search for current information let response = client.send( "claude-4-sonnet", Some(Message::new( Type::User, "Analyze the current state of AI development in 2024".to_string(), )), Some(config) ).await?; println!("Response: {}", response.content); Ok(()) } ``` -------------------------------- ### Send Messages to AI Models Source: https://context7.com/vibheksoni/t3router/llms.txt Shows how to send a single prompt to a specific AI model using the client's send method. It requires a configured client and returns the assistant's response content. ```rust use t3router::t3::{ client::Client, config::Config, message::{Message, Type}, }; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let mut client = Client::new(cookies, convex_session_id); client.init().await?; let config = Config::new(); // Send a single message to Claude 3.7 let response = client.send( "claude-3.7", Some(Message::new(Type::User, "What is the capital of France?".to_string())), Some(config) ).await?; println!("Assistant: {}", response.content); Ok(()) } ``` -------------------------------- ### Pre-Populate Conversations with T3Router in Rust Source: https://context7.com/vibheksoni/t3router/llms.txt Demonstrates how to pre-populate a conversation with historical messages using `append_message()` before sending a new request. This is useful for setting up specific scenarios or resuming previous sessions. It requires COOKIES and CONVEX_SESSION_ID environment variables. ```rust use t3router::t3::{ client::Client, config::Config, message::{Message, Type}, }; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let mut client = Client::new(cookies, convex_session_id); client.init().await?; // Pre-populate conversation context client.new_conversation(); client.append_message(Message::new( Type::User, "Let's play a word association game.".to_string(), )); client.append_message(Message::new( Type::Assistant, "Great! I love word association games. Go ahead!".to_string(), )); client.append_message(Message::new(Type::User, "Ocean".to_string())); client.append_message(Message::new(Type::Assistant, "Waves".to_string())); client.append_message(Message::new(Type::User, "Beach".to_string())); // Send without a new message - uses existing context let response = client.send("gemini-2.5-flash-lite", None, Some(Config::new())).await?; println!("Assistant: {}", response.content); // Output: Assistant: Sand (or similar word association response) // Print full conversation history for msg in client.get_messages() { let role = match msg.role { Type::User => "User", Type::Assistant => "Assistant", }; println!("{}: {}", role, msg.content); } Ok(()) } ``` -------------------------------- ### Discover AI Models with ModelsClient Source: https://context7.com/vibheksoni/t3router/llms.txt Uses ModelsClient to automatically discover available AI models by parsing t3.chat's JavaScript bundles. It returns model names, descriptions, providers, and availability status. Falls back to a curated list if dynamic fetching fails. Requires COOKIES and CONVEX_SESSION_ID environment variables. ```rust use t3router::t3::models::ModelsClient; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let models_client = ModelsClient::new(cookies, convex_session_id); let models = models_client.get_model_statuses().await?; println!("Found {} available models:", models.len()); for model in &models[..10] { // Show first 10 models println!(" {} - {}", model.name, model.description); } // Output: // Found 50+ available models: // gemini-2.5-flash - Google's state of the art fast model // claude-3.7 - Anthropic's Claude 3.7 Sonnet // gpt-4o - OpenAI's GPT-4o model // ... Ok(()) } ``` -------------------------------- ### Discover Available AI Models Source: https://github.com/vibheksoni/t3router/blob/master/README.md Uses the ModelsClient to fetch and display the status and details of available AI models supported by the current session. ```rust use t3router::t3::models::ModelsClient; let models_client = ModelsClient::new(cookies, session_id); let models = models_client.get_model_statuses().await?; for model in &models[..5] { println!(" {} - {}", model.name, model.description); } ``` -------------------------------- ### Configure Dependencies for T3Router Source: https://github.com/vibheksoni/t3router/blob/master/README.md Defines the required dependencies in the Cargo.toml file to integrate the t3router library with tokio for asynchronous operations and dotenv for environment variable management. ```toml [dependencies] t3router = { git = "https://github.com/vibheksoni/t3router" } tokio = { version = "1.47", features = ["full"] } dotenv = "0.15" ``` -------------------------------- ### Generate and Download Images with T3Router in Rust Source: https://context7.com/vibheksoni/t3router/llms.txt Utilizes the `send_with_image_download` method to generate images using specified models and automatically save them to a given path. It also returns base64-encoded image data for further processing. Requires COOKIES and CONVEX_SESSION_ID environment variables. ```rust use std::path::Path; use t3router::t3::{ client::Client, config::Config, message::{ContentType, Message, Type}, }; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = format!("\"{}\"", std::env::var("CONVEX_SESSION_ID")?); let mut client = Client::new(cookies, convex_session_id); client.init().await?; let save_path = Path::new("output/generated_image.png"); let response = client.send_with_image_download( "gpt-image-1", Some(Message::new( Type::User, "Create a simple drawing of a happy robot".to_string(), )), Some(Config::new()), Some(save_path), ).await?; match response.content_type { ContentType::Image => { if let Some(url) = response.image_url { println!("Generated image URL: {}", url); } if save_path.exists() { println!("Image saved to: {:?}", save_path); } if let Some(b64) = response.base64_data { println!("Base64 data available ({} characters)", b64.len()); } } ContentType::Text => { println!("Text response: {}", response.content); } } Ok(()) } ``` -------------------------------- ### Manage Conversation Context Source: https://github.com/vibheksoni/t3router/blob/master/README.md Shows how to maintain a multi-turn conversation by appending messages to the client instance before sending a new request. ```rust client.append_message(Message::new(Type::User, "Let's talk about Rust".to_string())); client.append_message(Message::new(Type::Assistant, "Sure! I'd be happy to discuss Rust.".to_string())); let response = client.send( "gpt-4o", Some(Message::new(Type::User, "What makes Rust memory safe?".to_string())), Some(config) ).await?; ``` -------------------------------- ### Generate and Download Images Source: https://github.com/vibheksoni/t3router/blob/master/README.md Utilizes the client to request image generation from a model and save the resulting output to a local file path. ```rust use std::path::Path; let save_path = Path::new("output/image.png"); let response = client.send_with_image_download( "gpt-image-1", Some(Message::new(Type::User, "A sunset over mountains".to_string())), Some(config), Some(save_path) ).await?; ``` -------------------------------- ### Session Management with T3 Client Source: https://context7.com/vibheksoni/t3router/llms.txt The `Client` automatically manages session state, including thread IDs and session refresh. Provides methods for manual session updates (`refresh_session`), resetting state (`new_conversation`), and clearing message history while preserving the thread (`clear_messages`). Requires COOKIES and CONVEX_SESSION_ID environment variables. ```rust use t3router::t3::{client::Client, config::Config, message::{Message, Type}}; #[tokio::main] async fn main() -> Result<(), Box> { let cookies = std::env::var("COOKIES")?; let convex_session_id = std::env::var("CONVEX_SESSION_ID")?; let mut client = Client::new(cookies, convex_session_id); client.init().await?; // First conversation let _ = client.send( "claude-3.7", Some(Message::new(Type::User, "Hello!".to_string())), Some(Config::new()) ).await?; println!("Thread ID: {:?}", client.get_thread_id()); println!("Messages: {}", client.get_messages().len()); // Start fresh conversation (new thread, clear messages) client.new_conversation(); println!("After new_conversation:"); println!("Thread ID: {:?}", client.get_thread_id()); // None println!("Messages: {}", client.get_messages().len()); // 0 // Or just clear messages (keeps thread for reference) client.clear_messages(); // Manual session refresh (usually automatic) let refreshed = client.refresh_session().await?; println!("Session refreshed: {}", refreshed); Ok(()) } ``` -------------------------------- ### Configure Model Settings Source: https://github.com/vibheksoni/t3router/blob/master/README.md Adjusts advanced model parameters such as reasoning effort and search functionality using the Config struct. ```rust use t3router::t3::config::{Config, ReasoningEffort}; let mut config = Config::new(); config.reasoning_effort = ReasoningEffort::High; config.include_search = true; ``` -------------------------------- ### Message Types and Content Handling Source: https://context7.com/vibheksoni/t3router/llms.txt Defines the `Message` struct for conversation messages, supporting both text and image content. Uses `Type` for roles (User/Assistant) and `ContentType` to differentiate between text and image data. Allows creating messages with default or custom IDs. ```rust use t3router::t3::message::{Message, Type, ContentType}; // Create a text message from user let user_message = Message::new( Type::User, "Hello, how are you?".to_string() ); println!("Message ID: {}", user_message.id); println!("Content: {}", user_message.content); // Create a message with specific ID (for custom tracking) let custom_message = Message::with_id( "custom-id-123".to_string(), Type::Assistant, "I'm doing well, thank you!".to_string() ); // Create an image message let image_message = Message::new_image( Type::Assistant, "https://example.com/image.png".to_string(), Some("base64encodeddata...".to_string()) ); // Check content type for proper handling match image_message.content_type { ContentType::Text => println!("Text: {}", image_message.content), ContentType::Image => { if let Some(url) = image_message.image_url { println!("Image URL: {}", url); } if let Some(b64) = image_message.base64_data { println!("Base64 length: {}", b64.len()); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.