### Rainy SDK Quick Start: Basic and Advanced Chat Completions in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Provides a quick start guide for using the Rainy SDK, demonstrating both simple and advanced chat completion methods. It covers client initialization with an API key and making requests to different models like GPT-4o and Claude Sonnet 4. Requires the rainy_sdk and tokio crates. ```rust use rainy_sdk::{models, ChatCompletionRequest, ChatMessage, RainyClient}; use std::error::Error; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize client with your API key from environment variables let api_key = std::env::var("RAINY_API_KEY").expect("RAINY_API_KEY not set"); let client = RainyClient::with_api_key(api_key)?; // Simple chat completion let response = client .simple_chat( models::model_constants::GPT_4O, "Hello! Tell me a short story.", ) .await?; println!("Simple response: {}", response); // Advanced usage with metadata let request = ChatCompletionRequest::new( models::model_constants::CLAUDE_SONNET_4, vec![ChatMessage::user("Explain quantum computing in one sentence")], ) .with_temperature(0.7) .with_max_tokens(100); let (response, metadata) = client.chat_completion(request).await?; println!("\nAdvanced response: {}", response.choices[0].message.content); println!("Provider: {:?}", metadata.provider.unwrap_or_default()); println!("Response time: {}ms", metadata.response_time.unwrap_or_default()); Ok(()) } ``` -------------------------------- ### Run Examples with Cargo Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Instructions on how to run the provided examples using Cargo. This involves setting the `RAINY_API_KEY` environment variable and then executing specific examples like `basic_usage` or `chat_completion` using `cargo run --example `. This is a command-line snippet. ```bash # Set your API key export RAINY_API_KEY="your-api-key-here" # Run basic usage example cargo run --example basic_usage # Run chat completion example cargo run --example chat_completion ``` -------------------------------- ### Manage API Keys with Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This example illustrates how to manage API keys programmatically using the Rainy SDK. It covers listing existing API keys, creating a new API key with an optional expiration duration, and deleting an API key by its ID. The results of these operations are printed to the console. Dependencies include the `rainy_sdk` crate. ```rust # use rainy_sdk::RainyClient; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; // List all API keys let keys = client.list_api_keys().await?; for key in keys { println!("Key ID: {} - Active: {}", key.id, key.is_active); } // Create a new API key let new_key = client.create_api_key("My new key", Some(30)).await?; println!("Created key: {}", new_key.key); // Delete the API key client.delete_api_key(&new_key.id.to_string()).await?; # Ok(()) # } ``` -------------------------------- ### Install Rainy SDK using Cargo Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This command-line instruction demonstrates how to add the Rainy SDK to your project using the `cargo add` command. This is a convenient way to manage dependencies. ```bash cargo add rainy-sdk ``` -------------------------------- ### Rainy SDK Chat Completions in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Provides a basic example of creating a standard chat completion using the `chat_completion` method. This is a core operation for interacting with language models. Requires the rainy_sdk crate. ```rust # use rainy_sdk::{RainyClient, ChatCompletionRequest, ChatMessage, models}; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; # let request = ChatCompletionRequest::new( # models::model_constants::GPT_3_5_TURBO, # vec![ChatMessage::user("Hello world!")], # ); let (response, metadata) = client.chat_completion(request).await?; println!("Response: {}", response.choices[0].message.content); # Ok(()) # } ``` -------------------------------- ### Get Usage Statistics with Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This snippet demonstrates how to retrieve credit and usage statistics using the Rainy SDK. It shows how to fetch current credit balance and past usage data (e.g., for the last 7 days) by calling `get_credit_stats` and `get_usage_stats` respectively. The results are then printed to the console. Dependencies include the `rainy_sdk` crate. ```rust # use rainy_sdk::RainyClient; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; // Get credit stats let credits = client.get_credit_stats(None).await?; println!("Current credits: {}", credits.current_credits); // Get usage stats for the last 7 days let usage = client.get_usage_stats(Some(7)).await?; println!("Total requests (last 7 days): {}", usage.total_requests); # Ok(()) # } ``` -------------------------------- ### Stream Chat Completions with Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This example shows how to receive chat completion responses as a stream of events using the Rainy SDK. It sets up a chat completion request with streaming enabled and iterates over the stream, printing each chunk of the response as it arrives. Error handling for stream chunks is also included. Dependencies include `rainy_sdk` and `futures`. ```rust # use rainy_sdk::{RainyClient, ChatCompletionRequest, ChatMessage, models}; # use futures::StreamExt; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; let request = ChatCompletionRequest::new( models::model_constants::LLAMA_3_1_8B_INSTANT, vec![ChatMessage::user("Write a haiku about Rust programming")], ) .with_stream(true); let mut stream = client.create_chat_completion_stream(request).await?; while let Some(chunk) = stream.next().await { match chunk { Ok(response) => { if let Some(choice) = response.choices.first() { print!("{}", choice.message.content); } } Err(e) => eprintln!("\nError in stream: {}", e), } } # Ok(()) # } ``` -------------------------------- ### Rainy SDK Authentication with API Key in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Shows how to authenticate with the Rainy SDK using an API key. It demonstrates loading the API key from an environment variable and initializing the `RainyClient`. Requires the rainy_sdk crate. ```rust use rainy_sdk::RainyClient; // Load API key from environment and create client let api_key = std::env::var("RAINY_API_KEY").expect("RAINY_API_KEY not set"); let client = RainyClient::with_api_key(api_key)?; ``` -------------------------------- ### Cowork Integration and Feature Gating in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Illustrates the Cowork integration for tier-based feature gating (Free, GoPlus, Plus, Pro, ProPlus). It shows how to check the user's plan and feature availability, such as web research and document export. Requires the rainy_sdk crate. ```rust use rainy_sdk::{CoworkStatus, CoworkClient}; let cowork_client = CoworkClient::new(client); let status = cowork_client.get_cowork_status().await?; println!("Plan: {:?}", status.plan); println!("Remaining uses: {}", status.usage.remaining_uses); // Check feature availability if status.can_use_web_research() { // Enable web search features } if status.can_use_document_export() { // Enable document generation } ``` -------------------------------- ### Web Search Integration with Tavily in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates how to integrate web search functionality powered by Tavily. This allows for real-time information retrieval and content extraction from specified URLs. Requires the rainy_sdk crate and Tavily integration. ```rust use rainy_sdk::search::{SearchOptions, SearchResponse}; let search_options = SearchOptions { query: "latest developments in Rust programming".to_string(), max_results: Some(10), ..Default::default() }; let search_results = client.search_web(search_options).await?; for result in search_results.results { println!("{}: {}", result.title, result.url); } // Extract content from specific URLs let extracted = client.extract_content(vec!["https://example.com/article".to_string()]).await?; println!("Content: {}", extracted.content); ``` -------------------------------- ### Perform Chat Completion with Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This snippet demonstrates how to perform a standard chat completion using the Rainy SDK. It initializes the client, defines a list of messages, creates a chat completion request with specified model and parameters, and then sends the request to the API. The response is processed to extract and print the assistant's message. Dependencies include the `rainy_sdk` crate. ```rust # use rainy_sdk::{RainyClient, ChatCompletionRequest, ChatMessage, models}; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; let messages = vec![ ChatMessage::system("You are a helpful assistant."), ChatMessage::user("Explain quantum computing in simple terms."), ]; let request = ChatCompletionRequest::new(models::model_constants::GPT_4O, messages) .with_max_tokens(500) .with_temperature(0.7); let (response, metadata) = client.chat_completion(request).await?; if let Some(choice) = response.choices.first() { println!("Response: {}", choice.message.content); } # Ok(()) # } ``` -------------------------------- ### Gemini 2.5 Dynamic Thinking Configuration in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Shows how to configure Gemini 2.5 for dynamic thinking, allowing for a flexible thinking budget. This enables the model to adjust its reasoning process based on the task's complexity. Requires the rainy_sdk crate. ```rust let config = ThinkingConfig::gemini_2_5( -1, // Dynamic thinking budget true // Include thoughts ); let request = ChatCompletionRequest::new( models::model_constants::GOOGLE_GEMINI_2_5_PRO, messages ) .with_thinking_config(config); ``` -------------------------------- ### Gemini 3 Thinking Features in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates how to use Gemini 3's advanced thinking features for complex problem-solving. It shows how to configure the thinking level and include thought summaries in the response. Requires the rainy_sdk crate. ```rust use rainy_sdk::{models, ChatCompletionRequest, ChatMessage, RainyClient, ThinkingConfig}; let request = ChatCompletionRequest::new( models::model_constants::GOOGLE_GEMINI_3_PRO, vec![ChatMessage::user("Solve this complex optimization problem step by step.")] ) .with_thinking_config(ThinkingConfig::gemini_3( models::ThinkingLevel::High, // High reasoning for complex tasks true // Include thought summaries in response )); let (response, metadata) = client.chat_completion(request).await?; println!("Response: {}", response.choices[0].message.content); // Access thinking token usage if let Some(thinking_tokens) = metadata.thoughts_token_count { println!("Thinking tokens used: {}", thinking_tokens); } ``` -------------------------------- ### OpenAI Compatible Chat Completion with Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This Rust code demonstrates how to perform a chat completion using the Rainy SDK, mimicking the official OpenAI SDK. It initializes a client, creates a chat request with a specified model and user message, and sends the request asynchronously. ```rust use rainy_sdk::{models, ChatCompletionRequest, ChatMessage, RainyClient}; // Works exactly like OpenAI SDK let client = RainyClient::with_api_key("your-rainy-api-key")?; let request = ChatCompletionRequest::new( models::model_constants::OPENAI_GPT_4O, // or GOOGLE_GEMINI_2_5_PRO vec![ChatMessage::user("Hello!")] ) .with_temperature(0.7) .with_response_format(models::ResponseFormat::JsonObject); let (response, metadata) = client.chat_completion(request).await?; ``` -------------------------------- ### Add Rainy SDK Dependency to Cargo.toml Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This snippet shows how to add the Rainy SDK and the Tokio runtime as dependencies to your project's Cargo.toml file. It specifies version numbers and enables the 'full' feature for Tokio. ```toml [dependencies] rainy-sdk = "0.5.1" tokio = { version = "1.47", features = ["full"] } ``` -------------------------------- ### Preserve Reasoning Context with Thought Signatures in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Explains how to maintain reasoning context across conversation turns using encrypted thought signatures. This feature allows subsequent messages to build upon previous reasoning. Requires the rainy_sdk crate. ```rust use rainy_sdk::{models::*, ChatMessage, EnhancedChatMessage}; let mut conversation = vec![ // Previous messages with thought signatures... ]; // New message with preserved reasoning context let enhanced_message = EnhancedChatMessage::with_parts( MessageRole::User, vec![ ContentPart::text("Now apply this reasoning to the next problem..."), // Include thought signature from previous response ContentPart::with_thought_signature("encrypted_signature_here".to_string()) ] ); ``` -------------------------------- ### Enable Optional Features for Rainy SDK Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md This snippet illustrates how to enable optional features for the Rainy SDK in your Cargo.toml file. It shows enabling 'rate-limiting', 'tracing', and 'cowork' features. ```toml [dependencies] rainy-sdk = { version = "0.5.1", features = ["rate-limiting", "tracing", "cowork"] } ``` -------------------------------- ### Rainy SDK Health Check in Rust Source: https://github.com/enosislabs/rainy-sdk/blob/main/README.md Demonstrates how to perform a health check on the API using the `health_check` method. This verifies the API's status and returns a status message. Requires the rainy_sdk crate and an active API connection. ```rust # use rainy_sdk::RainyClient; # async fn example() -> Result<(), Box> { # let client = RainyClient::with_api_key("dummy")?; let health = client.health_check().await?; println!("API Status: {}", health.status); # Ok(()) # } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.